graphql_cody 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/MIT-LICENSE +20 -0
- data/lib/generators/graphql/core.rb +74 -0
- data/lib/generators/graphql/enum_generator.rb +33 -0
- data/lib/generators/graphql/install_generator.rb +190 -0
- data/lib/generators/graphql/interface_generator.rb +27 -0
- data/lib/generators/graphql/loader_generator.rb +21 -0
- data/lib/generators/graphql/mutation_generator.rb +55 -0
- data/lib/generators/graphql/object_generator.rb +79 -0
- data/lib/generators/graphql/relay.rb +63 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/scalar_generator.rb +20 -0
- data/lib/generators/graphql/templates/base_argument.erb +6 -0
- data/lib/generators/graphql/templates/base_connection.erb +8 -0
- data/lib/generators/graphql/templates/base_edge.erb +8 -0
- data/lib/generators/graphql/templates/base_enum.erb +6 -0
- data/lib/generators/graphql/templates/base_field.erb +7 -0
- data/lib/generators/graphql/templates/base_input_object.erb +7 -0
- data/lib/generators/graphql/templates/base_interface.erb +9 -0
- data/lib/generators/graphql/templates/base_mutation.erb +10 -0
- data/lib/generators/graphql/templates/base_object.erb +7 -0
- data/lib/generators/graphql/templates/base_scalar.erb +6 -0
- data/lib/generators/graphql/templates/base_union.erb +6 -0
- data/lib/generators/graphql/templates/enum.erb +7 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +52 -0
- data/lib/generators/graphql/templates/interface.erb +8 -0
- data/lib/generators/graphql/templates/loader.erb +19 -0
- data/lib/generators/graphql/templates/mutation.erb +16 -0
- data/lib/generators/graphql/templates/mutation_type.erb +12 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +8 -0
- data/lib/generators/graphql/templates/query_type.erb +15 -0
- data/lib/generators/graphql/templates/scalar.erb +15 -0
- data/lib/generators/graphql/templates/schema.erb +27 -0
- data/lib/generators/graphql/templates/union.erb +7 -0
- data/lib/generators/graphql/type_generator.rb +98 -0
- data/lib/generators/graphql/union_generator.rb +33 -0
- data/lib/graphql/analysis/analyze_query.rb +98 -0
- data/lib/graphql/analysis/ast/analyzer.rb +84 -0
- data/lib/graphql/analysis/ast/field_usage.rb +51 -0
- data/lib/graphql/analysis/ast/max_query_complexity.rb +23 -0
- data/lib/graphql/analysis/ast/max_query_depth.rb +22 -0
- data/lib/graphql/analysis/ast/query_complexity.rb +230 -0
- data/lib/graphql/analysis/ast/query_depth.rb +56 -0
- data/lib/graphql/analysis/ast/visitor.rb +268 -0
- data/lib/graphql/analysis/ast.rb +91 -0
- data/lib/graphql/analysis/field_usage.rb +45 -0
- data/lib/graphql/analysis/max_query_complexity.rb +26 -0
- data/lib/graphql/analysis/max_query_depth.rb +26 -0
- data/lib/graphql/analysis/query_complexity.rb +88 -0
- data/lib/graphql/analysis/query_depth.rb +43 -0
- data/lib/graphql/analysis/reducer_state.rb +48 -0
- data/lib/graphql/analysis.rb +9 -0
- data/lib/graphql/analysis_error.rb +5 -0
- data/lib/graphql/argument.rb +131 -0
- data/lib/graphql/authorization.rb +82 -0
- data/lib/graphql/backtrace/inspect_result.rb +50 -0
- data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
- data/lib/graphql/backtrace/table.rb +159 -0
- data/lib/graphql/backtrace/traced_error.rb +54 -0
- data/lib/graphql/backtrace/tracer.rb +81 -0
- data/lib/graphql/backtrace.rb +64 -0
- data/lib/graphql/backwards_compatibility.rb +61 -0
- data/lib/graphql/base_type.rb +230 -0
- data/lib/graphql/boolean_type.rb +2 -0
- data/lib/graphql/coercion_error.rb +13 -0
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +53 -0
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +200 -0
- data/lib/graphql/compatibility/execution_specification.rb +436 -0
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +111 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +215 -0
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +87 -0
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +79 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +266 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +682 -0
- data/lib/graphql/compatibility.rb +5 -0
- data/lib/graphql/dataloader/null_dataloader.rb +22 -0
- data/lib/graphql/dataloader/request.rb +19 -0
- data/lib/graphql/dataloader/request_all.rb +19 -0
- data/lib/graphql/dataloader/source.rb +155 -0
- data/lib/graphql/dataloader.rb +308 -0
- data/lib/graphql/define/assign_argument.rb +12 -0
- data/lib/graphql/define/assign_connection.rb +13 -0
- data/lib/graphql/define/assign_enum_value.rb +18 -0
- data/lib/graphql/define/assign_global_id_field.rb +11 -0
- data/lib/graphql/define/assign_mutation_function.rb +34 -0
- data/lib/graphql/define/assign_object_field.rb +42 -0
- data/lib/graphql/define/defined_object_proxy.rb +53 -0
- data/lib/graphql/define/instance_definable.rb +240 -0
- data/lib/graphql/define/no_definition_error.rb +7 -0
- data/lib/graphql/define/non_null_with_bang.rb +16 -0
- data/lib/graphql/define/type_definer.rb +31 -0
- data/lib/graphql/define.rb +31 -0
- data/lib/graphql/deprecated_dsl.rb +55 -0
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/dig.rb +19 -0
- data/lib/graphql/directive/deprecated_directive.rb +2 -0
- data/lib/graphql/directive/include_directive.rb +2 -0
- data/lib/graphql/directive/skip_directive.rb +2 -0
- data/lib/graphql/directive.rb +107 -0
- data/lib/graphql/enum_type.rb +133 -0
- data/lib/graphql/execution/directive_checks.rb +37 -0
- data/lib/graphql/execution/errors.rb +163 -0
- data/lib/graphql/execution/execute.rb +333 -0
- data/lib/graphql/execution/flatten.rb +40 -0
- data/lib/graphql/execution/instrumentation.rb +92 -0
- data/lib/graphql/execution/interpreter/argument_value.rb +28 -0
- data/lib/graphql/execution/interpreter/arguments.rb +88 -0
- data/lib/graphql/execution/interpreter/arguments_cache.rb +103 -0
- data/lib/graphql/execution/interpreter/execution_errors.rb +29 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +18 -0
- data/lib/graphql/execution/interpreter/resolve.rb +70 -0
- data/lib/graphql/execution/interpreter/runtime.rb +949 -0
- data/lib/graphql/execution/interpreter.rb +122 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +98 -0
- data/lib/graphql/execution/lazy/resolve.rb +91 -0
- data/lib/graphql/execution/lazy.rb +83 -0
- data/lib/graphql/execution/lookahead.rb +307 -0
- data/lib/graphql/execution/multiplex.rb +214 -0
- data/lib/graphql/execution/typecast.rb +50 -0
- data/lib/graphql/execution.rb +11 -0
- data/lib/graphql/execution_error.rb +58 -0
- data/lib/graphql/field/resolve.rb +59 -0
- data/lib/graphql/field.rb +226 -0
- data/lib/graphql/filter.rb +53 -0
- data/lib/graphql/float_type.rb +2 -0
- data/lib/graphql/function.rb +128 -0
- data/lib/graphql/id_type.rb +2 -0
- data/lib/graphql/input_object_type.rb +138 -0
- data/lib/graphql/int_type.rb +2 -0
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +36 -0
- data/lib/graphql/interface_type.rb +72 -0
- data/lib/graphql/internal_representation/document.rb +27 -0
- data/lib/graphql/internal_representation/node.rb +206 -0
- data/lib/graphql/internal_representation/print.rb +51 -0
- data/lib/graphql/internal_representation/rewrite.rb +184 -0
- data/lib/graphql/internal_representation/scope.rb +88 -0
- data/lib/graphql/internal_representation/visit.rb +36 -0
- data/lib/graphql/internal_representation.rb +7 -0
- data/lib/graphql/introspection/base_object.rb +13 -0
- data/lib/graphql/introspection/directive_location_enum.rb +15 -0
- data/lib/graphql/introspection/directive_type.rb +29 -0
- data/lib/graphql/introspection/dynamic_fields.rb +17 -0
- data/lib/graphql/introspection/entry_points.rb +35 -0
- data/lib/graphql/introspection/enum_value_type.rb +23 -0
- data/lib/graphql/introspection/field_type.rb +28 -0
- data/lib/graphql/introspection/input_value_type.rb +67 -0
- data/lib/graphql/introspection/introspection_query.rb +7 -0
- data/lib/graphql/introspection/schema_type.rb +44 -0
- data/lib/graphql/introspection/type_kind_enum.rb +13 -0
- data/lib/graphql/introspection/type_type.rb +95 -0
- data/lib/graphql/introspection.rb +114 -0
- data/lib/graphql/invalid_name_error.rb +11 -0
- data/lib/graphql/invalid_null_error.rb +50 -0
- data/lib/graphql/language/block_string.rb +99 -0
- data/lib/graphql/language/cache.rb +37 -0
- data/lib/graphql/language/definition_slice.rb +41 -0
- data/lib/graphql/language/document_from_schema_definition.rb +347 -0
- data/lib/graphql/language/generation.rb +24 -0
- data/lib/graphql/language/lexer.rb +1467 -0
- data/lib/graphql/language/lexer.rl +258 -0
- data/lib/graphql/language/nodes.rb +707 -0
- data/lib/graphql/language/parser.rb +1974 -0
- data/lib/graphql/language/parser.y +544 -0
- data/lib/graphql/language/printer.rb +366 -0
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/token.rb +34 -0
- data/lib/graphql/language/visitor.rb +242 -0
- data/lib/graphql/language.rb +36 -0
- data/lib/graphql/list_type.rb +80 -0
- data/lib/graphql/load_application_object_failed_error.rb +22 -0
- data/lib/graphql/name_validator.rb +11 -0
- data/lib/graphql/non_null_type.rb +71 -0
- data/lib/graphql/object_type.rb +130 -0
- data/lib/graphql/pagination/active_record_relation_connection.rb +48 -0
- data/lib/graphql/pagination/array_connection.rb +77 -0
- data/lib/graphql/pagination/connection.rb +226 -0
- data/lib/graphql/pagination/connections.rb +160 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +196 -0
- data/lib/graphql/pagination/sequel_dataset_connection.rb +28 -0
- data/lib/graphql/pagination.rb +6 -0
- data/lib/graphql/parse_error.rb +24 -0
- data/lib/graphql/query/arguments.rb +189 -0
- data/lib/graphql/query/arguments_cache.rb +24 -0
- data/lib/graphql/query/context.rb +371 -0
- data/lib/graphql/query/executor.rb +52 -0
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +43 -0
- data/lib/graphql/query/literal_input.rb +136 -0
- data/lib/graphql/query/null_context.rb +55 -0
- data/lib/graphql/query/result.rb +63 -0
- data/lib/graphql/query/serial_execution/field_resolution.rb +92 -0
- data/lib/graphql/query/serial_execution/operation_resolution.rb +19 -0
- data/lib/graphql/query/serial_execution/selection_resolution.rb +23 -0
- data/lib/graphql/query/serial_execution/value_resolution.rb +87 -0
- data/lib/graphql/query/serial_execution.rb +40 -0
- data/lib/graphql/query/validation_pipeline.rb +139 -0
- data/lib/graphql/query/variable_validation_error.rb +44 -0
- data/lib/graphql/query/variables.rb +78 -0
- data/lib/graphql/query.rb +454 -0
- data/lib/graphql/railtie.rb +117 -0
- data/lib/graphql/rake_task/validate.rb +63 -0
- data/lib/graphql/rake_task.rb +145 -0
- data/lib/graphql/relay/array_connection.rb +83 -0
- data/lib/graphql/relay/base_connection.rb +189 -0
- data/lib/graphql/relay/connection_instrumentation.rb +54 -0
- data/lib/graphql/relay/connection_resolve.rb +43 -0
- data/lib/graphql/relay/connection_type.rb +41 -0
- data/lib/graphql/relay/edge.rb +27 -0
- data/lib/graphql/relay/edge_type.rb +19 -0
- data/lib/graphql/relay/edges_instrumentation.rb +39 -0
- data/lib/graphql/relay/global_id_resolve.rb +18 -0
- data/lib/graphql/relay/mongo_relation_connection.rb +50 -0
- data/lib/graphql/relay/mutation/instrumentation.rb +23 -0
- data/lib/graphql/relay/mutation/resolve.rb +56 -0
- data/lib/graphql/relay/mutation/result.rb +38 -0
- data/lib/graphql/relay/mutation.rb +106 -0
- data/lib/graphql/relay/node.rb +39 -0
- data/lib/graphql/relay/page_info.rb +7 -0
- data/lib/graphql/relay/range_add.rb +59 -0
- data/lib/graphql/relay/relation_connection.rb +188 -0
- data/lib/graphql/relay/type_extensions.rb +32 -0
- data/lib/graphql/relay.rb +18 -0
- data/lib/graphql/rubocop/graphql/base_cop.rb +36 -0
- data/lib/graphql/rubocop/graphql/default_null_true.rb +43 -0
- data/lib/graphql/rubocop/graphql/default_required_true.rb +43 -0
- data/lib/graphql/rubocop.rb +4 -0
- data/lib/graphql/runtime_type_error.rb +5 -0
- data/lib/graphql/scalar_type.rb +91 -0
- data/lib/graphql/schema/addition.rb +247 -0
- data/lib/graphql/schema/argument.rb +383 -0
- data/lib/graphql/schema/base_64_bp.rb +26 -0
- data/lib/graphql/schema/base_64_encoder.rb +21 -0
- data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +47 -0
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +78 -0
- data/lib/graphql/schema/build_from_definition.rb +477 -0
- data/lib/graphql/schema/built_in_types.rb +12 -0
- data/lib/graphql/schema/catchall_middleware.rb +35 -0
- data/lib/graphql/schema/default_parse_error.rb +10 -0
- data/lib/graphql/schema/default_type_error.rb +17 -0
- data/lib/graphql/schema/directive/deprecated.rb +18 -0
- data/lib/graphql/schema/directive/feature.rb +66 -0
- data/lib/graphql/schema/directive/flagged.rb +57 -0
- data/lib/graphql/schema/directive/include.rb +25 -0
- data/lib/graphql/schema/directive/skip.rb +25 -0
- data/lib/graphql/schema/directive/transform.rb +60 -0
- data/lib/graphql/schema/directive.rb +210 -0
- data/lib/graphql/schema/enum.rb +193 -0
- data/lib/graphql/schema/enum_value.rb +97 -0
- data/lib/graphql/schema/field/connection_extension.rb +76 -0
- data/lib/graphql/schema/field/scope_extension.rb +22 -0
- data/lib/graphql/schema/field.rb +880 -0
- data/lib/graphql/schema/field_extension.rb +69 -0
- data/lib/graphql/schema/find_inherited_value.rb +36 -0
- data/lib/graphql/schema/finder.rb +155 -0
- data/lib/graphql/schema/input_object.rb +253 -0
- data/lib/graphql/schema/interface.rb +136 -0
- data/lib/graphql/schema/introspection_system.rb +169 -0
- data/lib/graphql/schema/invalid_type_error.rb +7 -0
- data/lib/graphql/schema/late_bound_type.rb +33 -0
- data/lib/graphql/schema/list.rb +75 -0
- data/lib/graphql/schema/loader.rb +226 -0
- data/lib/graphql/schema/member/accepts_definition.rb +159 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +129 -0
- data/lib/graphql/schema/member/build_type.rb +180 -0
- data/lib/graphql/schema/member/cached_graphql_definition.rb +31 -0
- data/lib/graphql/schema/member/graphql_type_names.rb +21 -0
- data/lib/graphql/schema/member/has_arguments.rb +332 -0
- data/lib/graphql/schema/member/has_ast_node.rb +20 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +25 -0
- data/lib/graphql/schema/member/has_directives.rb +98 -0
- data/lib/graphql/schema/member/has_fields.rb +163 -0
- data/lib/graphql/schema/member/has_interfaces.rb +90 -0
- data/lib/graphql/schema/member/has_path.rb +25 -0
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +15 -0
- data/lib/graphql/schema/member/has_validators.rb +31 -0
- data/lib/graphql/schema/member/instrumentation.rb +131 -0
- data/lib/graphql/schema/member/relay_shortcuts.rb +47 -0
- data/lib/graphql/schema/member/scoped.rb +21 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +38 -0
- data/lib/graphql/schema/member/validates_input.rb +33 -0
- data/lib/graphql/schema/member.rb +161 -0
- data/lib/graphql/schema/middleware_chain.rb +82 -0
- data/lib/graphql/schema/mutation.rb +94 -0
- data/lib/graphql/schema/non_null.rb +67 -0
- data/lib/graphql/schema/null_mask.rb +11 -0
- data/lib/graphql/schema/object.rb +150 -0
- data/lib/graphql/schema/possible_types.rb +44 -0
- data/lib/graphql/schema/printer.rb +100 -0
- data/lib/graphql/schema/relay_classic_mutation.rb +160 -0
- data/lib/graphql/schema/rescue_middleware.rb +60 -0
- data/lib/graphql/schema/resolver/has_payload_type.rb +96 -0
- data/lib/graphql/schema/resolver.rb +397 -0
- data/lib/graphql/schema/scalar.rb +69 -0
- data/lib/graphql/schema/subscription.rb +155 -0
- data/lib/graphql/schema/timeout.rb +123 -0
- data/lib/graphql/schema/timeout_middleware.rb +88 -0
- data/lib/graphql/schema/traversal.rb +228 -0
- data/lib/graphql/schema/type_expression.rb +43 -0
- data/lib/graphql/schema/type_membership.rb +48 -0
- data/lib/graphql/schema/union.rb +95 -0
- data/lib/graphql/schema/unique_within_type.rb +34 -0
- data/lib/graphql/schema/validation.rb +313 -0
- data/lib/graphql/schema/validator/allow_blank_validator.rb +29 -0
- data/lib/graphql/schema/validator/allow_null_validator.rb +26 -0
- data/lib/graphql/schema/validator/exclusion_validator.rb +33 -0
- data/lib/graphql/schema/validator/format_validator.rb +48 -0
- data/lib/graphql/schema/validator/inclusion_validator.rb +35 -0
- data/lib/graphql/schema/validator/length_validator.rb +59 -0
- data/lib/graphql/schema/validator/numericality_validator.rb +82 -0
- data/lib/graphql/schema/validator/required_validator.rb +68 -0
- data/lib/graphql/schema/validator.rb +174 -0
- data/lib/graphql/schema/warden.rb +409 -0
- data/lib/graphql/schema/wrapper.rb +29 -0
- data/lib/graphql/schema.rb +1945 -0
- data/lib/graphql/static_validation/all_rules.rb +40 -0
- data/lib/graphql/static_validation/base_visitor.rb +217 -0
- data/lib/graphql/static_validation/default_visitor.rb +15 -0
- data/lib/graphql/static_validation/definition_dependencies.rb +198 -0
- data/lib/graphql/static_validation/error.rb +46 -0
- data/lib/graphql/static_validation/interpreter_visitor.rb +14 -0
- data/lib/graphql/static_validation/literal_validator.rb +139 -0
- data/lib/graphql/static_validation/no_validate_visitor.rb +10 -0
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +66 -0
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +48 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +31 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +71 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +37 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +23 -0
- data/lib/graphql/static_validation/rules/directives_are_defined_error.rb +29 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +65 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +30 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type_error.rb +32 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +73 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +418 -0
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +53 -0
- data/lib/graphql/static_validation/rules/fragment_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/fragment_names_are_unique_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +73 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +35 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +39 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +21 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_named.rb +16 -0
- data/lib/graphql/static_validation/rules/fragments_are_named_error.rb +26 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +37 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types_error.rb +30 -0
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +32 -0
- data/lib/graphql/static_validation/rules/fragments_are_used_error.rb +29 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +41 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present_error.rb +25 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid.rb +36 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid_error.rb +28 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +37 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present_error.rb +35 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +59 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present_error.rb +35 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +50 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location_error.rb +29 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +46 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb +39 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +24 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique_error.rb +29 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +153 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed_error.rb +38 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +39 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types_error.rb +32 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +155 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +37 -0
- data/lib/graphql/static_validation/type_stack.rb +216 -0
- data/lib/graphql/static_validation/validation_context.rb +49 -0
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +96 -0
- data/lib/graphql/static_validation.rb +19 -0
- data/lib/graphql/string_encoding_error.rb +20 -0
- data/lib/graphql/string_type.rb +2 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +245 -0
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +81 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +21 -0
- data/lib/graphql/subscriptions/event.rb +144 -0
- data/lib/graphql/subscriptions/instrumentation.rb +79 -0
- data/lib/graphql/subscriptions/serialize.rb +138 -0
- data/lib/graphql/subscriptions/subscription_root.rb +76 -0
- data/lib/graphql/subscriptions.rb +299 -0
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +35 -0
- data/lib/graphql/tracing/appoptics_tracing.rb +173 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +51 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +76 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +51 -0
- data/lib/graphql/tracing/platform_tracing.rb +139 -0
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +32 -0
- data/lib/graphql/tracing/prometheus_tracing.rb +67 -0
- data/lib/graphql/tracing/scout_tracing.rb +54 -0
- data/lib/graphql/tracing/skylight_tracing.rb +70 -0
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +95 -0
- data/lib/graphql/type_kinds.rb +77 -0
- data/lib/graphql/types/big_int.rb +23 -0
- data/lib/graphql/types/boolean.rb +18 -0
- data/lib/graphql/types/float.rb +19 -0
- data/lib/graphql/types/id.rb +24 -0
- data/lib/graphql/types/int.rb +36 -0
- data/lib/graphql/types/iso_8601_date.rb +34 -0
- data/lib/graphql/types/iso_8601_date_time.rb +65 -0
- data/lib/graphql/types/json.rb +25 -0
- data/lib/graphql/types/relay/base_connection.rb +39 -0
- data/lib/graphql/types/relay/base_edge.rb +29 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +156 -0
- data/lib/graphql/types/relay/default_relay.rb +27 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +53 -0
- data/lib/graphql/types/relay/has_node_field.rb +41 -0
- data/lib/graphql/types/relay/has_nodes_field.rb +41 -0
- data/lib/graphql/types/relay/node.rb +15 -0
- data/lib/graphql/types/relay/node_behaviors.rb +15 -0
- data/lib/graphql/types/relay/node_field.rb +25 -0
- data/lib/graphql/types/relay/nodes_field.rb +27 -0
- data/lib/graphql/types/relay/page_info.rb +11 -0
- data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
- data/lib/graphql/types/relay.rb +41 -0
- data/lib/graphql/types/string.rb +29 -0
- data/lib/graphql/types.rb +11 -0
- data/lib/graphql/unauthorized_error.rb +29 -0
- data/lib/graphql/unauthorized_field_error.rb +23 -0
- data/lib/graphql/union_type.rb +115 -0
- data/lib/graphql/unresolved_type_error.rb +35 -0
- data/lib/graphql/upgrader/member.rb +937 -0
- data/lib/graphql/upgrader/schema.rb +38 -0
- data/lib/graphql/version.rb +4 -0
- data/lib/graphql.rb +168 -0
- data/readme.md +49 -0
- metadata +714 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
class Member
|
6
|
+
module TypeSystemHelpers
|
7
|
+
# @return [Schema::NonNull] Make a non-null-type representation of this type
|
8
|
+
def to_non_null_type
|
9
|
+
@to_non_null_type ||= GraphQL::Schema::NonNull.new(self)
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Schema::List] Make a list-type representation of this type
|
13
|
+
def to_list_type
|
14
|
+
@to_list_type ||= GraphQL::Schema::List.new(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Boolean] true if this is a non-nullable type. A nullable list of non-nullables is considered nullable.
|
18
|
+
def non_null?
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Boolean] true if this is a list type. A non-nullable list is considered a list.
|
23
|
+
def list?
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_type_signature
|
28
|
+
graphql_name
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [GraphQL::TypeKinds::TypeKind]
|
32
|
+
def kind
|
33
|
+
raise GraphQL::RequiredImplementationMissingError, "No `.kind` defined for #{self}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
class Member
|
6
|
+
module ValidatesInput
|
7
|
+
def valid_input?(val, ctx)
|
8
|
+
validate_input(val, ctx).valid?
|
9
|
+
end
|
10
|
+
|
11
|
+
def validate_input(val, ctx)
|
12
|
+
if val.nil?
|
13
|
+
GraphQL::Query::InputValidationResult.new
|
14
|
+
else
|
15
|
+
validate_non_null_input(val, ctx)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid_isolated_input?(v)
|
20
|
+
valid_input?(v, GraphQL::Query::NullContext)
|
21
|
+
end
|
22
|
+
|
23
|
+
def coerce_isolated_input(v)
|
24
|
+
coerce_input(v, GraphQL::Query::NullContext)
|
25
|
+
end
|
26
|
+
|
27
|
+
def coerce_isolated_result(v)
|
28
|
+
coerce_result(v, GraphQL::Query::NullContext)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'graphql/schema/member/accepts_definition'
|
3
|
+
require 'graphql/schema/member/base_dsl_methods'
|
4
|
+
require 'graphql/schema/member/cached_graphql_definition'
|
5
|
+
require 'graphql/schema/member/graphql_type_names'
|
6
|
+
require 'graphql/schema/member/has_ast_node'
|
7
|
+
require 'graphql/schema/member/has_directives'
|
8
|
+
require 'graphql/schema/member/has_deprecation_reason'
|
9
|
+
require 'graphql/schema/member/has_interfaces'
|
10
|
+
require 'graphql/schema/member/has_path'
|
11
|
+
require 'graphql/schema/member/has_unresolved_type_error'
|
12
|
+
require 'graphql/schema/member/has_validators'
|
13
|
+
require 'graphql/schema/member/relay_shortcuts'
|
14
|
+
require 'graphql/schema/member/scoped'
|
15
|
+
require 'graphql/schema/member/type_system_helpers'
|
16
|
+
require 'graphql/schema/member/validates_input'
|
17
|
+
require "graphql/relay/type_extensions"
|
18
|
+
|
19
|
+
module GraphQL
|
20
|
+
class Schema
|
21
|
+
# The base class for things that make up the schema,
|
22
|
+
# eg objects, enums, scalars.
|
23
|
+
#
|
24
|
+
# @api private
|
25
|
+
class Member
|
26
|
+
include GraphQLTypeNames
|
27
|
+
extend CachedGraphQLDefinition
|
28
|
+
extend GraphQL::Relay::TypeExtensions
|
29
|
+
extend BaseDSLMethods
|
30
|
+
extend BaseDSLMethods::ConfigurationExtension
|
31
|
+
introspection(false)
|
32
|
+
extend TypeSystemHelpers
|
33
|
+
extend Scoped
|
34
|
+
extend RelayShortcuts
|
35
|
+
extend HasPath
|
36
|
+
extend HasAstNode
|
37
|
+
extend HasDirectives
|
38
|
+
end
|
39
|
+
|
40
|
+
# # The legacy handler is called, as before:
|
41
|
+
# Account.graphql_definition.metadata[:permission_level] # => 1
|
42
|
+
module AcceptsDefinition
|
43
|
+
|
44
|
+
def self.included(child)
|
45
|
+
child.extend(AcceptsDefinitionDefinitionMethods)
|
46
|
+
child.prepend(ToGraphQLExtension)
|
47
|
+
child.prepend(InitializeExtension)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.extended(child)
|
51
|
+
if defined?(child::DefinitionMethods)
|
52
|
+
child::DefinitionMethods.include(AcceptsDefinitionDefinitionMethods)
|
53
|
+
child::DefinitionMethods.prepend(ToGraphQLExtension)
|
54
|
+
else
|
55
|
+
child.extend(AcceptsDefinitionDefinitionMethods)
|
56
|
+
# I tried to use `super`, but super isn't quite right
|
57
|
+
# since the method is defined in the same class itself,
|
58
|
+
# not the superclass
|
59
|
+
child.class_eval do
|
60
|
+
class << self
|
61
|
+
prepend(ToGraphQLExtension)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
module AcceptsDefinitionDefinitionMethods
|
68
|
+
def accepts_definition(name)
|
69
|
+
own_accepts_definition_methods << name
|
70
|
+
|
71
|
+
ivar_name = "@#{name}_args"
|
72
|
+
if self.is_a?(Class)
|
73
|
+
define_singleton_method(name) do |*args|
|
74
|
+
if args.any?
|
75
|
+
instance_variable_set(ivar_name, args)
|
76
|
+
end
|
77
|
+
instance_variable_get(ivar_name) || (superclass.respond_to?(name) ? superclass.public_send(name) : nil)
|
78
|
+
end
|
79
|
+
|
80
|
+
define_method(name) do |*args|
|
81
|
+
if args.any?
|
82
|
+
instance_variable_set(ivar_name, args)
|
83
|
+
end
|
84
|
+
instance_variable_get(ivar_name)
|
85
|
+
end
|
86
|
+
else
|
87
|
+
# Special handling for interfaces, define it here
|
88
|
+
# so it's appropriately passed down
|
89
|
+
self::DefinitionMethods.module_eval do
|
90
|
+
define_method(name) do |*args|
|
91
|
+
if args.any?
|
92
|
+
instance_variable_set(ivar_name, args)
|
93
|
+
end
|
94
|
+
instance_variable_get(ivar_name) || ((int = interfaces.first { |i| i.respond_to?()}) && int.public_send(name))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def accepts_definition_methods
|
101
|
+
inherited_methods = if self.is_a?(Class)
|
102
|
+
superclass.respond_to?(:accepts_definition_methods) ? superclass.accepts_definition_methods : []
|
103
|
+
elsif self.is_a?(Module)
|
104
|
+
m = []
|
105
|
+
ancestors.each do |a|
|
106
|
+
if a.respond_to?(:own_accepts_definition_methods)
|
107
|
+
m.concat(a.own_accepts_definition_methods)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
m
|
111
|
+
else
|
112
|
+
self.class.accepts_definition_methods
|
113
|
+
end
|
114
|
+
|
115
|
+
own_accepts_definition_methods + inherited_methods
|
116
|
+
end
|
117
|
+
|
118
|
+
def own_accepts_definition_methods
|
119
|
+
@own_accepts_definition_methods ||= []
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
module ToGraphQLExtension
|
124
|
+
def to_graphql
|
125
|
+
defn = super
|
126
|
+
accepts_definition_methods.each do |method_name|
|
127
|
+
value = public_send(method_name)
|
128
|
+
if !value.nil?
|
129
|
+
defn = defn.redefine { public_send(method_name, *value) }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
defn
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
module InitializeExtension
|
137
|
+
def initialize(*args, **kwargs, &block)
|
138
|
+
self.class.accepts_definition_methods.each do |method_name|
|
139
|
+
if kwargs.key?(method_name)
|
140
|
+
value = kwargs.delete(method_name)
|
141
|
+
if !value.is_a?(Array)
|
142
|
+
value = [value]
|
143
|
+
end
|
144
|
+
instance_variable_set("@#{method_name}_args", value)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
super(*args, **kwargs, &block)
|
148
|
+
end
|
149
|
+
|
150
|
+
def accepts_definition_methods
|
151
|
+
self.class.accepts_definition_methods
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
require 'graphql/schema/member/has_arguments'
|
159
|
+
require 'graphql/schema/member/has_fields'
|
160
|
+
require 'graphql/schema/member/instrumentation'
|
161
|
+
require 'graphql/schema/member/build_type'
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
# Given {steps} and {arguments}, call steps in order, passing `(*arguments, next_step)`.
|
5
|
+
#
|
6
|
+
# Steps should call `next_step.call` to continue the chain, or _not_ call it to stop the chain.
|
7
|
+
class MiddlewareChain
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
# @return [Array<#call(*args)>] Steps in this chain, will be called with arguments and `next_middleware`
|
11
|
+
attr_reader :steps, :final_step
|
12
|
+
|
13
|
+
def initialize(steps: [], final_step: nil)
|
14
|
+
@steps = steps
|
15
|
+
@final_step = final_step
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize_copy(other)
|
19
|
+
super
|
20
|
+
@steps = other.steps.dup
|
21
|
+
end
|
22
|
+
|
23
|
+
def_delegators :@steps, :[], :first, :insert, :delete
|
24
|
+
|
25
|
+
def <<(callable)
|
26
|
+
add_middleware(callable)
|
27
|
+
end
|
28
|
+
|
29
|
+
def push(callable)
|
30
|
+
add_middleware(callable)
|
31
|
+
end
|
32
|
+
|
33
|
+
def ==(other)
|
34
|
+
steps == other.steps && final_step == other.final_step
|
35
|
+
end
|
36
|
+
|
37
|
+
def invoke(arguments)
|
38
|
+
invoke_core(0, arguments)
|
39
|
+
end
|
40
|
+
|
41
|
+
def concat(callables)
|
42
|
+
callables.each { |c| add_middleware(c) }
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def invoke_core(index, arguments)
|
48
|
+
if index >= steps.length
|
49
|
+
final_step.call(*arguments)
|
50
|
+
else
|
51
|
+
steps[index].call(*arguments) { |next_args = arguments| invoke_core(index + 1, next_args) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_middleware(callable)
|
56
|
+
# TODO: Stop wrapping callables once deprecated middleware becomes unsupported
|
57
|
+
steps << wrap(callable)
|
58
|
+
end
|
59
|
+
|
60
|
+
# TODO: Remove this code once deprecated middleware becomes unsupported
|
61
|
+
class MiddlewareWrapper
|
62
|
+
attr_reader :callable
|
63
|
+
def initialize(callable)
|
64
|
+
@callable = callable
|
65
|
+
end
|
66
|
+
|
67
|
+
def call(*args, &next_middleware)
|
68
|
+
callable.call(*args, next_middleware)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def wrap(callable)
|
73
|
+
if BackwardsCompatibility.get_arity(callable) == 6
|
74
|
+
GraphQL::Deprecation.warn("Middleware that takes a next_middleware parameter is deprecated (#{callable.inspect}); instead, accept a block and use yield.")
|
75
|
+
MiddlewareWrapper.new(callable)
|
76
|
+
else
|
77
|
+
callable
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
# This base class accepts configuration for a mutation root field,
|
6
|
+
# then it can be hooked up to your mutation root object type.
|
7
|
+
#
|
8
|
+
# If you want to customize how this class generates types, in your base class,
|
9
|
+
# override the various `generate_*` methods.
|
10
|
+
#
|
11
|
+
# @see {GraphQL::Schema::RelayClassicMutation} for an extension of this class with some conventions built-in.
|
12
|
+
#
|
13
|
+
# @example Creating a comment
|
14
|
+
# # Define the mutation:
|
15
|
+
# class Mutations::CreateComment < GraphQL::Schema::Mutation
|
16
|
+
# argument :body, String, required: true
|
17
|
+
# argument :post_id, ID, required: true
|
18
|
+
#
|
19
|
+
# field :comment, Types::Comment, null: true
|
20
|
+
# field :errors, [String], null: false
|
21
|
+
#
|
22
|
+
# def resolve(body:, post_id:)
|
23
|
+
# post = Post.find(post_id)
|
24
|
+
# comment = post.comments.build(body: body, author: context[:current_user])
|
25
|
+
# if comment.save
|
26
|
+
# # Successful creation, return the created object with no errors
|
27
|
+
# {
|
28
|
+
# comment: comment,
|
29
|
+
# errors: [],
|
30
|
+
# }
|
31
|
+
# else
|
32
|
+
# # Failed save, return the errors to the client
|
33
|
+
# {
|
34
|
+
# comment: nil,
|
35
|
+
# errors: comment.errors.full_messages
|
36
|
+
# }
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# # Hook it up to your mutation:
|
42
|
+
# class Types::Mutation < GraphQL::Schema::Object
|
43
|
+
# field :create_comment, mutation: Mutations::CreateComment
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# # Call it from GraphQL:
|
47
|
+
# result = MySchema.execute <<-GRAPHQL
|
48
|
+
# mutation {
|
49
|
+
# createComment(postId: "1", body: "Nice Post!") {
|
50
|
+
# errors
|
51
|
+
# comment {
|
52
|
+
# body
|
53
|
+
# author {
|
54
|
+
# login
|
55
|
+
# }
|
56
|
+
# }
|
57
|
+
# }
|
58
|
+
# }
|
59
|
+
# GRAPHQL
|
60
|
+
#
|
61
|
+
class Mutation < GraphQL::Schema::Resolver
|
62
|
+
extend GraphQL::Schema::Member::HasFields
|
63
|
+
extend GraphQL::Schema::Resolver::HasPayloadType
|
64
|
+
|
65
|
+
class << self
|
66
|
+
# Override this method to handle legacy-style usages of `MyMutation.field`
|
67
|
+
def field(*args, **kwargs, &block)
|
68
|
+
if args.empty?
|
69
|
+
raise ArgumentError, "#{name}.field is used for adding fields to this mutation. Use `mutation: #{name}` to attach this mutation instead."
|
70
|
+
else
|
71
|
+
super
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def visible?(context)
|
76
|
+
true
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def conflict_field_name_warning(field_defn)
|
82
|
+
"#{self.graphql_name}'s `field :#{field_defn.name}` conflicts with a built-in method, use `hash_key:` or `method:` to pick a different resolve behavior for this field (for example, `hash_key: :#{field_defn.resolver_method}_value`, and modify the return hash). Or use `method_conflict_warning: false` to suppress this warning."
|
83
|
+
end
|
84
|
+
|
85
|
+
# Override this to attach self as `mutation`
|
86
|
+
def generate_payload_type
|
87
|
+
payload_class = super
|
88
|
+
payload_class.mutation(self)
|
89
|
+
payload_class
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
# Represents a non null type in the schema.
|
6
|
+
# Wraps a {Schema::Member} when it is required.
|
7
|
+
# @see {Schema::Member::TypeSystemHelpers#to_non_null_type}
|
8
|
+
class NonNull < GraphQL::Schema::Wrapper
|
9
|
+
include Schema::Member::ValidatesInput
|
10
|
+
|
11
|
+
def to_graphql
|
12
|
+
@of_type.graphql_definition.to_non_null_type
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [GraphQL::TypeKinds::NON_NULL]
|
16
|
+
def kind
|
17
|
+
GraphQL::TypeKinds::NON_NULL
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [true]
|
21
|
+
def non_null?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Boolean] True if this type wraps a list type
|
26
|
+
def list?
|
27
|
+
@of_type.list?
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_type_signature
|
31
|
+
"#{@of_type.to_type_signature}!"
|
32
|
+
end
|
33
|
+
|
34
|
+
def inspect
|
35
|
+
"#<#{self.class.name} @of_type=#{@of_type.inspect}>"
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_input(value, ctx)
|
39
|
+
if value.nil?
|
40
|
+
result = GraphQL::Query::InputValidationResult.new
|
41
|
+
result.add_problem("Expected value to not be null")
|
42
|
+
result
|
43
|
+
else
|
44
|
+
of_type.validate_input(value, ctx)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# This is for introspection, where it's expected the name will be `null`
|
49
|
+
def graphql_name
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def coerce_input(value, ctx)
|
54
|
+
of_type.coerce_input(value, ctx)
|
55
|
+
end
|
56
|
+
|
57
|
+
def coerce_result(value, ctx)
|
58
|
+
of_type.coerce_result(value, ctx)
|
59
|
+
end
|
60
|
+
|
61
|
+
# This is for implementing introspection
|
62
|
+
def description
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "graphql/query/null_context"
|
4
|
+
|
5
|
+
module GraphQL
|
6
|
+
class Schema
|
7
|
+
class Object < GraphQL::Schema::Member
|
8
|
+
extend GraphQL::Schema::Member::AcceptsDefinition
|
9
|
+
extend GraphQL::Schema::Member::HasFields
|
10
|
+
extend GraphQL::Schema::Member::HasInterfaces
|
11
|
+
|
12
|
+
# @return [Object] the application object this type is wrapping
|
13
|
+
attr_reader :object
|
14
|
+
|
15
|
+
# @return [GraphQL::Query::Context] the context instance for this query
|
16
|
+
attr_reader :context
|
17
|
+
|
18
|
+
# @return [GraphQL::Dataloader]
|
19
|
+
def dataloader
|
20
|
+
context.dataloader
|
21
|
+
end
|
22
|
+
|
23
|
+
# Call this in a field method to return a value that should be returned to the client
|
24
|
+
# without any further handling by GraphQL.
|
25
|
+
def raw_value(obj)
|
26
|
+
GraphQL::Execution::Interpreter::RawValue.new(obj)
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
# This is protected so that we can be sure callers use the public method, {.authorized_new}
|
31
|
+
# @see authorized_new to make instances
|
32
|
+
protected :new
|
33
|
+
|
34
|
+
# Make a new instance of this type _if_ the auth check passes,
|
35
|
+
# otherwise, raise an error.
|
36
|
+
#
|
37
|
+
# Probably only the framework should call this method.
|
38
|
+
#
|
39
|
+
# This might return a {GraphQL::Execution::Lazy} if the user-provided `.authorized?`
|
40
|
+
# hook returns some lazy value (like a Promise).
|
41
|
+
#
|
42
|
+
# The reason that the auth check is in this wrapper method instead of {.new} is because
|
43
|
+
# of how it might return a Promise. It would be weird if `.new` returned a promise;
|
44
|
+
# It would be a headache to try to maintain Promise-y state inside a {Schema::Object}
|
45
|
+
# instance. So, hopefully this wrapper method will do the job.
|
46
|
+
#
|
47
|
+
# @param object [Object] The thing wrapped by this object
|
48
|
+
# @param context [GraphQL::Query::Context]
|
49
|
+
# @return [GraphQL::Schema::Object, GraphQL::Execution::Lazy]
|
50
|
+
# @raise [GraphQL::UnauthorizedError] if the user-provided hook returns `false`
|
51
|
+
def authorized_new(object, context)
|
52
|
+
trace_payload = { context: context, type: self, object: object, path: context[:current_path] }
|
53
|
+
|
54
|
+
maybe_lazy_auth_val = context.query.trace("authorized", trace_payload) do
|
55
|
+
context.query.with_error_handling do
|
56
|
+
begin
|
57
|
+
authorized?(object, context)
|
58
|
+
rescue GraphQL::UnauthorizedError => err
|
59
|
+
context.schema.unauthorized_object(err)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
auth_val = if context.schema.lazy?(maybe_lazy_auth_val)
|
65
|
+
GraphQL::Execution::Lazy.new do
|
66
|
+
context.query.trace("authorized_lazy", trace_payload) do
|
67
|
+
context.schema.sync_lazy(maybe_lazy_auth_val)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
else
|
71
|
+
maybe_lazy_auth_val
|
72
|
+
end
|
73
|
+
|
74
|
+
context.schema.after_lazy(auth_val) do |is_authorized|
|
75
|
+
if is_authorized
|
76
|
+
self.new(object, context)
|
77
|
+
else
|
78
|
+
# It failed the authorization check, so go to the schema's authorized object hook
|
79
|
+
err = GraphQL::UnauthorizedError.new(object: object, type: self, context: context)
|
80
|
+
# If a new value was returned, wrap that instead of the original value
|
81
|
+
begin
|
82
|
+
new_obj = context.schema.unauthorized_object(err)
|
83
|
+
if new_obj
|
84
|
+
self.new(new_obj, context)
|
85
|
+
else
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def initialize(object, context)
|
95
|
+
@object = object
|
96
|
+
@context = context
|
97
|
+
end
|
98
|
+
|
99
|
+
class << self
|
100
|
+
# Set up a type-specific invalid null error to use when this object's non-null fields wrongly return `nil`.
|
101
|
+
# It should help with debugging and bug tracker integrations.
|
102
|
+
def inherited(child_class)
|
103
|
+
child_class.const_set(:InvalidNullError, GraphQL::InvalidNullError.subclass_for(child_class))
|
104
|
+
super
|
105
|
+
end
|
106
|
+
|
107
|
+
# @return [Hash<String => GraphQL::Schema::Field>] All of this object's fields, indexed by name
|
108
|
+
# @see get_field A faster way to find one field by name ({#fields} merges hashes of inherited fields; {#get_field} just looks up one field.)
|
109
|
+
def fields(context = GraphQL::Query::NullContext)
|
110
|
+
all_fields = super
|
111
|
+
# This adds fields from legacy-style interfaces only.
|
112
|
+
# Multi-fields are not supported here.
|
113
|
+
interfaces.each do |int|
|
114
|
+
if int.is_a?(GraphQL::InterfaceType)
|
115
|
+
int_f = {}
|
116
|
+
int.fields.each do |name, legacy_field| # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
117
|
+
int_f[name] = field_class.from_options(name, field: legacy_field)
|
118
|
+
end
|
119
|
+
all_fields = int_f.merge(all_fields)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
all_fields
|
123
|
+
end
|
124
|
+
|
125
|
+
# @return [GraphQL::ObjectType]
|
126
|
+
def to_graphql
|
127
|
+
obj_type = GraphQL::ObjectType.new
|
128
|
+
obj_type.name = graphql_name
|
129
|
+
obj_type.description = description
|
130
|
+
obj_type.structural_interface_type_memberships = interface_type_memberships
|
131
|
+
obj_type.introspection = introspection
|
132
|
+
obj_type.mutation = mutation
|
133
|
+
obj_type.ast_node = ast_node
|
134
|
+
fields.each do |field_name, field_inst| # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
135
|
+
field_defn = field_inst.to_graphql
|
136
|
+
obj_type.fields[field_defn.name] = field_defn # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
137
|
+
end
|
138
|
+
|
139
|
+
obj_type.metadata[:type_class] = self
|
140
|
+
|
141
|
+
obj_type
|
142
|
+
end
|
143
|
+
|
144
|
+
def kind
|
145
|
+
GraphQL::TypeKinds::OBJECT
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
# Find the members of a union or interface within a given schema.
|
5
|
+
#
|
6
|
+
# (Although its members never change, unions are handled this way to simplify execution code.)
|
7
|
+
#
|
8
|
+
# Internally, the calculation is cached. It's assumed that schema members _don't_ change after creating the schema!
|
9
|
+
#
|
10
|
+
# @example Get an interface's possible types
|
11
|
+
# possible_types = GraphQL::Schema::PossibleTypes(MySchema)
|
12
|
+
# possible_types.possible_types(MyInterface)
|
13
|
+
# # => [MyObjectType, MyOtherObjectType]
|
14
|
+
class PossibleTypes
|
15
|
+
def initialize(schema)
|
16
|
+
@object_types = schema.types.values.select { |type| type.kind.object? }
|
17
|
+
@interface_implementers = Hash.new do |h1, ctx|
|
18
|
+
h1[ctx] = Hash.new do |h2, int_type|
|
19
|
+
h2[int_type] = @object_types.select { |type| type.interfaces(ctx).include?(int_type) }.sort_by(&:name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def possible_types(type_defn, ctx)
|
25
|
+
case type_defn
|
26
|
+
when Module
|
27
|
+
possible_types(type_defn.graphql_definition, ctx)
|
28
|
+
when GraphQL::UnionType
|
29
|
+
type_defn.possible_types(ctx)
|
30
|
+
when GraphQL::InterfaceType
|
31
|
+
interface_implementers(ctx, type_defn)
|
32
|
+
when GraphQL::BaseType
|
33
|
+
[type_defn]
|
34
|
+
else
|
35
|
+
raise "Unexpected possible_types object: #{type_defn.inspect}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def interface_implementers(ctx, type_defn)
|
40
|
+
@interface_implementers[ctx][type_defn]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|