graphql 1.9.21 → 2.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/core.rb +21 -10
- data/lib/generators/graphql/enum_generator.rb +4 -10
- data/lib/generators/graphql/field_extractor.rb +31 -0
- data/lib/generators/graphql/input_generator.rb +50 -0
- data/lib/generators/graphql/install/mutation_root_generator.rb +34 -0
- data/lib/generators/graphql/{templates → install/templates}/base_mutation.erb +2 -0
- data/lib/generators/graphql/{templates → install/templates}/mutation_type.erb +2 -0
- data/lib/generators/graphql/install_generator.rb +45 -8
- data/lib/generators/graphql/interface_generator.rb +7 -7
- data/lib/generators/graphql/loader_generator.rb +1 -0
- data/lib/generators/graphql/mutation_create_generator.rb +22 -0
- data/lib/generators/graphql/mutation_delete_generator.rb +22 -0
- data/lib/generators/graphql/mutation_generator.rb +6 -30
- data/lib/generators/graphql/mutation_update_generator.rb +22 -0
- data/lib/generators/graphql/object_generator.rb +28 -12
- data/lib/generators/graphql/orm_mutations_base.rb +40 -0
- data/lib/generators/graphql/relay.rb +49 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/scalar_generator.rb +4 -2
- data/lib/generators/graphql/templates/base_argument.erb +2 -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 +2 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +2 -0
- data/lib/generators/graphql/templates/base_interface.erb +2 -0
- data/lib/generators/graphql/templates/base_object.erb +2 -0
- data/lib/generators/graphql/templates/base_scalar.erb +2 -0
- data/lib/generators/graphql/templates/base_union.erb +2 -0
- data/lib/generators/graphql/templates/enum.erb +7 -1
- data/lib/generators/graphql/templates/graphql_controller.erb +16 -12
- data/lib/generators/graphql/templates/input.erb +9 -0
- data/lib/generators/graphql/templates/interface.erb +6 -2
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +3 -1
- data/lib/generators/graphql/templates/mutation_create.erb +20 -0
- data/lib/generators/graphql/templates/mutation_delete.erb +20 -0
- data/lib/generators/graphql/templates/mutation_update.erb +21 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +7 -3
- data/lib/generators/graphql/templates/query_type.erb +3 -3
- data/lib/generators/graphql/templates/scalar.erb +5 -1
- data/lib/generators/graphql/templates/schema.erb +25 -27
- data/lib/generators/graphql/templates/union.erb +6 -2
- data/lib/generators/graphql/type_generator.rb +47 -10
- data/lib/generators/graphql/union_generator.rb +5 -5
- data/lib/graphql/analysis/ast/field_usage.rb +31 -2
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +175 -68
- data/lib/graphql/analysis/ast/query_depth.rb +0 -1
- data/lib/graphql/analysis/ast/visitor.rb +17 -8
- data/lib/graphql/analysis/ast.rb +14 -14
- data/lib/graphql/analysis.rb +0 -7
- data/lib/graphql/backtrace/inspect_result.rb +0 -1
- data/lib/graphql/backtrace/table.rb +37 -16
- data/lib/graphql/backtrace/traced_error.rb +0 -1
- data/lib/graphql/backtrace/tracer.rb +39 -9
- data/lib/graphql/backtrace.rb +20 -17
- data/lib/graphql/dataloader/null_dataloader.rb +24 -0
- data/lib/graphql/dataloader/request.rb +19 -0
- data/lib/graphql/dataloader/request_all.rb +19 -0
- data/lib/graphql/dataloader/source.rb +164 -0
- data/lib/graphql/dataloader.rb +311 -0
- data/lib/graphql/date_encoding_error.rb +16 -0
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/dig.rb +1 -1
- data/lib/graphql/execution/directive_checks.rb +2 -2
- data/lib/graphql/execution/errors.rb +77 -45
- 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 +105 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +18 -0
- data/lib/graphql/execution/interpreter/resolve.rb +44 -25
- data/lib/graphql/execution/interpreter/runtime.rb +755 -395
- data/lib/graphql/execution/interpreter.rb +201 -74
- data/lib/graphql/execution/lazy/lazy_method_map.rb +4 -0
- data/lib/graphql/execution/lazy.rb +5 -9
- data/lib/graphql/execution/lookahead.rb +65 -136
- data/lib/graphql/execution/multiplex.rb +5 -152
- data/lib/graphql/execution.rb +11 -4
- data/lib/graphql/filter.rb +1 -1
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +18 -2
- data/lib/graphql/introspection/base_object.rb +2 -5
- data/lib/graphql/introspection/directive_location_enum.rb +2 -2
- data/lib/graphql/introspection/directive_type.rb +11 -5
- data/lib/graphql/introspection/dynamic_fields.rb +3 -8
- data/lib/graphql/introspection/entry_points.rb +5 -18
- data/lib/graphql/introspection/enum_value_type.rb +2 -2
- data/lib/graphql/introspection/field_type.rb +9 -5
- data/lib/graphql/introspection/input_value_type.rb +41 -11
- data/lib/graphql/introspection/introspection_query.rb +6 -92
- data/lib/graphql/introspection/schema_type.rb +10 -10
- data/lib/graphql/introspection/type_type.rb +34 -17
- data/lib/graphql/introspection.rb +100 -0
- data/lib/graphql/invalid_null_error.rb +18 -0
- data/lib/graphql/language/block_string.rb +20 -5
- data/lib/graphql/language/cache.rb +37 -0
- data/lib/graphql/language/definition_slice.rb +21 -10
- data/lib/graphql/language/document_from_schema_definition.rb +104 -68
- data/lib/graphql/language/lexer.rb +83 -40
- data/lib/graphql/language/lexer.rl +31 -9
- data/lib/graphql/language/nodes.rb +64 -93
- data/lib/graphql/language/parser.rb +940 -896
- data/lib/graphql/language/parser.y +130 -103
- data/lib/graphql/language/printer.rb +48 -23
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/token.rb +0 -4
- data/lib/graphql/language/visitor.rb +2 -2
- data/lib/graphql/language.rb +3 -1
- data/lib/graphql/name_validator.rb +2 -7
- data/lib/graphql/pagination/active_record_relation_connection.rb +85 -0
- data/lib/graphql/pagination/array_connection.rb +79 -0
- data/lib/graphql/pagination/connection.rb +253 -0
- data/lib/graphql/pagination/connections.rb +135 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +228 -0
- data/lib/graphql/pagination/sequel_dataset_connection.rb +28 -0
- data/lib/graphql/pagination.rb +6 -0
- data/lib/graphql/parse_error.rb +0 -1
- data/lib/graphql/query/context.rb +172 -198
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +33 -7
- data/lib/graphql/query/null_context.rb +21 -8
- data/lib/graphql/query/validation_pipeline.rb +16 -38
- data/lib/graphql/query/variable_validation_error.rb +3 -3
- data/lib/graphql/query/variables.rb +39 -12
- data/lib/graphql/query.rb +74 -38
- data/lib/graphql/railtie.rb +6 -102
- data/lib/graphql/rake_task/validate.rb +4 -1
- data/lib/graphql/rake_task.rb +41 -10
- data/lib/graphql/relay/range_add.rb +17 -10
- data/lib/graphql/relay.rb +0 -15
- 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/schema/addition.rb +245 -0
- data/lib/graphql/schema/argument.rb +286 -31
- data/lib/graphql/schema/base_64_encoder.rb +2 -0
- data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +1 -1
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +13 -5
- data/lib/graphql/schema/build_from_definition.rb +334 -220
- data/lib/graphql/schema/built_in_types.rb +5 -5
- data/lib/graphql/schema/directive/deprecated.rb +18 -0
- data/lib/graphql/schema/directive/feature.rb +1 -1
- data/lib/graphql/schema/directive/flagged.rb +57 -0
- data/lib/graphql/schema/directive/include.rb +2 -2
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/skip.rb +2 -2
- data/lib/graphql/schema/directive/transform.rb +14 -2
- data/lib/graphql/schema/directive.rb +117 -14
- data/lib/graphql/schema/enum.rb +113 -22
- data/lib/graphql/schema/enum_value.rb +16 -21
- data/lib/graphql/schema/field/connection_extension.rb +50 -20
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +491 -329
- data/lib/graphql/schema/field_extension.rb +89 -2
- data/lib/graphql/schema/find_inherited_value.rb +17 -1
- data/lib/graphql/schema/finder.rb +16 -14
- data/lib/graphql/schema/input_object.rb +182 -60
- data/lib/graphql/schema/interface.rb +28 -43
- data/lib/graphql/schema/introspection_system.rb +101 -38
- data/lib/graphql/schema/late_bound_type.rb +7 -2
- data/lib/graphql/schema/list.rb +61 -3
- data/lib/graphql/schema/loader.rb +144 -102
- data/lib/graphql/schema/member/base_dsl_methods.rb +33 -32
- data/lib/graphql/schema/member/build_type.rb +24 -15
- data/lib/graphql/schema/member/has_arguments.rb +261 -24
- 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 +113 -0
- data/lib/graphql/schema/member/has_fields.rb +99 -34
- data/lib/graphql/schema/member/has_interfaces.rb +88 -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/relay_shortcuts.rb +28 -2
- data/lib/graphql/schema/member/type_system_helpers.rb +3 -3
- data/lib/graphql/schema/member/validates_input.rb +33 -0
- data/lib/graphql/schema/member.rb +11 -6
- data/lib/graphql/schema/mutation.rb +4 -9
- data/lib/graphql/schema/non_null.rb +34 -4
- data/lib/graphql/schema/object.rb +38 -60
- data/lib/graphql/schema/printer.rb +16 -35
- data/lib/graphql/schema/relay_classic_mutation.rb +90 -43
- data/lib/graphql/schema/resolver/has_payload_type.rb +46 -6
- data/lib/graphql/schema/resolver.rb +146 -93
- data/lib/graphql/schema/scalar.rb +40 -15
- data/lib/graphql/schema/subscription.rb +55 -26
- data/lib/graphql/schema/timeout.rb +29 -15
- data/lib/graphql/schema/type_expression.rb +21 -13
- data/lib/graphql/schema/type_membership.rb +22 -5
- data/lib/graphql/schema/union.rb +48 -14
- data/lib/graphql/schema/unique_within_type.rb +1 -2
- 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 +82 -0
- data/lib/graphql/schema/validator.rb +171 -0
- data/lib/graphql/schema/warden.rb +187 -33
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +773 -892
- data/lib/graphql/static_validation/all_rules.rb +3 -0
- data/lib/graphql/static_validation/base_visitor.rb +21 -31
- data/lib/graphql/static_validation/definition_dependencies.rb +7 -2
- data/lib/graphql/static_validation/error.rb +3 -1
- data/lib/graphql/static_validation/literal_validator.rb +55 -26
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +45 -83
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +22 -6
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +35 -26
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +4 -2
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +12 -6
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +14 -14
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +4 -4
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +5 -5
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +94 -51
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +25 -4
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +2 -2
- 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/one_of_input_objects_are_valid.rb +66 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/query_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +4 -2
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +9 -10
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +13 -7
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +12 -13
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +19 -14
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +5 -3
- data/lib/graphql/static_validation/type_stack.rb +2 -2
- data/lib/graphql/static_validation/validation_context.rb +13 -3
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +31 -19
- data/lib/graphql/static_validation.rb +1 -2
- data/lib/graphql/string_encoding_error.rb +13 -3
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +129 -22
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +81 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +58 -0
- data/lib/graphql/subscriptions/event.rb +85 -31
- data/lib/graphql/subscriptions/instrumentation.rb +0 -47
- data/lib/graphql/subscriptions/serialize.rb +53 -6
- data/lib/graphql/subscriptions.rb +137 -57
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +8 -17
- data/lib/graphql/tracing/appoptics_tracing.rb +173 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +23 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +34 -2
- data/lib/graphql/tracing/new_relic_tracing.rb +9 -12
- data/lib/graphql/tracing/notifications_tracing.rb +59 -0
- data/lib/graphql/tracing/platform_tracing.rb +67 -38
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +4 -1
- data/lib/graphql/tracing/prometheus_tracing.rb +8 -0
- data/lib/graphql/tracing/scout_tracing.rb +19 -0
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +15 -36
- data/lib/graphql/types/big_int.rb +5 -1
- data/lib/graphql/types/int.rb +10 -3
- data/lib/graphql/types/iso_8601_date.rb +20 -9
- data/lib/graphql/types/iso_8601_date_time.rb +36 -10
- data/lib/graphql/types/relay/base_connection.rb +18 -90
- data/lib/graphql/types/relay/base_edge.rb +2 -34
- data/lib/graphql/types/relay/connection_behaviors.rb +158 -0
- data/lib/graphql/types/relay/default_relay.rb +27 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +65 -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 +2 -4
- data/lib/graphql/types/relay/node_behaviors.rb +19 -0
- data/lib/graphql/types/relay/page_info.rb +2 -14
- data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
- data/lib/graphql/types/relay.rb +11 -5
- data/lib/graphql/types/string.rb +8 -2
- data/lib/graphql/unauthorized_error.rb +2 -2
- data/lib/graphql/unresolved_type_error.rb +2 -2
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +41 -58
- data/readme.md +3 -6
- metadata +103 -237
- data/lib/graphql/analysis/analyze_query.rb +0 -91
- data/lib/graphql/analysis/field_usage.rb +0 -45
- data/lib/graphql/analysis/max_query_complexity.rb +0 -26
- data/lib/graphql/analysis/max_query_depth.rb +0 -26
- data/lib/graphql/analysis/query_complexity.rb +0 -88
- data/lib/graphql/analysis/query_depth.rb +0 -43
- data/lib/graphql/analysis/reducer_state.rb +0 -48
- data/lib/graphql/argument.rb +0 -159
- data/lib/graphql/authorization.rb +0 -82
- data/lib/graphql/backwards_compatibility.rb +0 -60
- data/lib/graphql/base_type.rb +0 -226
- data/lib/graphql/boolean_type.rb +0 -2
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
- data/lib/graphql/compatibility/execution_specification.rb +0 -435
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
- data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -213
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -91
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
- data/lib/graphql/compatibility/query_parser_specification.rb +0 -264
- data/lib/graphql/compatibility/schema_parser_specification.rb +0 -680
- data/lib/graphql/compatibility.rb +0 -5
- data/lib/graphql/define/assign_argument.rb +0 -12
- data/lib/graphql/define/assign_connection.rb +0 -13
- data/lib/graphql/define/assign_enum_value.rb +0 -18
- data/lib/graphql/define/assign_global_id_field.rb +0 -11
- data/lib/graphql/define/assign_mutation_function.rb +0 -34
- data/lib/graphql/define/assign_object_field.rb +0 -42
- data/lib/graphql/define/defined_object_proxy.rb +0 -53
- data/lib/graphql/define/instance_definable.rb +0 -311
- data/lib/graphql/define/no_definition_error.rb +0 -7
- data/lib/graphql/define/non_null_with_bang.rb +0 -16
- data/lib/graphql/define/type_definer.rb +0 -31
- data/lib/graphql/define.rb +0 -31
- data/lib/graphql/deprecated_dsl.rb +0 -42
- data/lib/graphql/directive/deprecated_directive.rb +0 -13
- data/lib/graphql/directive/include_directive.rb +0 -2
- data/lib/graphql/directive/skip_directive.rb +0 -2
- data/lib/graphql/directive.rb +0 -104
- data/lib/graphql/enum_type.rb +0 -193
- data/lib/graphql/execution/execute.rb +0 -326
- data/lib/graphql/execution/flatten.rb +0 -40
- data/lib/graphql/execution/instrumentation.rb +0 -92
- data/lib/graphql/execution/interpreter/hash_response.rb +0 -46
- data/lib/graphql/execution/lazy/resolve.rb +0 -91
- data/lib/graphql/execution/typecast.rb +0 -50
- data/lib/graphql/field/resolve.rb +0 -59
- data/lib/graphql/field.rb +0 -330
- data/lib/graphql/float_type.rb +0 -2
- data/lib/graphql/function.rb +0 -153
- data/lib/graphql/id_type.rb +0 -2
- data/lib/graphql/input_object_type.rb +0 -154
- data/lib/graphql/int_type.rb +0 -2
- data/lib/graphql/interface_type.rb +0 -86
- data/lib/graphql/internal_representation/document.rb +0 -27
- data/lib/graphql/internal_representation/node.rb +0 -206
- data/lib/graphql/internal_representation/print.rb +0 -51
- data/lib/graphql/internal_representation/rewrite.rb +0 -184
- data/lib/graphql/internal_representation/scope.rb +0 -88
- data/lib/graphql/internal_representation/visit.rb +0 -36
- data/lib/graphql/internal_representation.rb +0 -7
- data/lib/graphql/list_type.rb +0 -80
- data/lib/graphql/literal_validation_error.rb +0 -6
- data/lib/graphql/non_null_type.rb +0 -81
- data/lib/graphql/object_type.rb +0 -141
- data/lib/graphql/query/arguments.rb +0 -187
- data/lib/graphql/query/arguments_cache.rb +0 -25
- data/lib/graphql/query/executor.rb +0 -53
- data/lib/graphql/query/literal_input.rb +0 -116
- data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
- data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
- data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
- data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
- data/lib/graphql/query/serial_execution.rb +0 -39
- data/lib/graphql/relay/array_connection.rb +0 -85
- data/lib/graphql/relay/base_connection.rb +0 -172
- data/lib/graphql/relay/connection_instrumentation.rb +0 -54
- data/lib/graphql/relay/connection_resolve.rb +0 -43
- data/lib/graphql/relay/connection_type.rb +0 -40
- data/lib/graphql/relay/edge.rb +0 -27
- data/lib/graphql/relay/edge_type.rb +0 -18
- data/lib/graphql/relay/edges_instrumentation.rb +0 -40
- data/lib/graphql/relay/global_id_resolve.rb +0 -18
- data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
- data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
- data/lib/graphql/relay/mutation/resolve.rb +0 -56
- data/lib/graphql/relay/mutation/result.rb +0 -38
- data/lib/graphql/relay/mutation.rb +0 -190
- data/lib/graphql/relay/node.rb +0 -36
- data/lib/graphql/relay/page_info.rb +0 -7
- data/lib/graphql/relay/relation_connection.rb +0 -190
- data/lib/graphql/relay/type_extensions.rb +0 -30
- data/lib/graphql/scalar_type.rb +0 -133
- data/lib/graphql/schema/catchall_middleware.rb +0 -35
- data/lib/graphql/schema/default_parse_error.rb +0 -10
- data/lib/graphql/schema/default_type_error.rb +0 -15
- data/lib/graphql/schema/member/accepts_definition.rb +0 -152
- data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -26
- data/lib/graphql/schema/member/instrumentation.rb +0 -132
- data/lib/graphql/schema/middleware_chain.rb +0 -82
- data/lib/graphql/schema/possible_types.rb +0 -39
- data/lib/graphql/schema/rescue_middleware.rb +0 -60
- data/lib/graphql/schema/timeout_middleware.rb +0 -86
- data/lib/graphql/schema/traversal.rb +0 -228
- data/lib/graphql/schema/validation.rb +0 -303
- data/lib/graphql/static_validation/default_visitor.rb +0 -15
- data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
- data/lib/graphql/string_type.rb +0 -2
- data/lib/graphql/subscriptions/subscription_root.rb +0 -74
- data/lib/graphql/tracing/skylight_tracing.rb +0 -62
- data/lib/graphql/types/relay/base_field.rb +0 -22
- data/lib/graphql/types/relay/base_interface.rb +0 -29
- data/lib/graphql/types/relay/base_object.rb +0 -26
- data/lib/graphql/types/relay/node_field.rb +0 -43
- data/lib/graphql/types/relay/nodes_field.rb +0 -45
- data/lib/graphql/union_type.rb +0 -135
- data/lib/graphql/upgrader/member.rb +0 -936
- data/lib/graphql/upgrader/schema.rb +0 -37
@@ -1,187 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module GraphQL
|
3
|
-
class Query
|
4
|
-
# Read-only access to values, normalizing all keys to strings
|
5
|
-
#
|
6
|
-
# {Arguments} recursively wraps the input in {Arguments} instances.
|
7
|
-
class Arguments
|
8
|
-
extend Forwardable
|
9
|
-
include GraphQL::Dig
|
10
|
-
|
11
|
-
def self.construct_arguments_class(argument_owner)
|
12
|
-
argument_definitions = argument_owner.arguments
|
13
|
-
argument_owner.arguments_class = Class.new(self) do
|
14
|
-
self.argument_definitions = argument_definitions
|
15
|
-
|
16
|
-
argument_definitions.each do |_arg_name, arg_definition|
|
17
|
-
if arg_definition.method_access?
|
18
|
-
expose_as = arg_definition.expose_as.to_s.freeze
|
19
|
-
expose_as_underscored = GraphQL::Schema::Member::BuildType.underscore(expose_as).freeze
|
20
|
-
method_names = [expose_as, expose_as_underscored].uniq
|
21
|
-
method_names.each do |method_name|
|
22
|
-
# Don't define a helper method if it would override something.
|
23
|
-
if method_defined?(method_name)
|
24
|
-
warn(
|
25
|
-
"Unable to define a helper for argument with name '#{method_name}' "\
|
26
|
-
"as this is a reserved name. Add `method_access: false` to stop this warning."
|
27
|
-
)
|
28
|
-
else
|
29
|
-
define_method(method_name) do
|
30
|
-
# Always use `expose_as` here, since #[] doesn't accept underscored names
|
31
|
-
self[expose_as]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
attr_reader :argument_values
|
41
|
-
|
42
|
-
def initialize(values, context:, defaults_used:)
|
43
|
-
@argument_values = values.inject({}) do |memo, (inner_key, inner_value)|
|
44
|
-
arg_name = inner_key.to_s
|
45
|
-
arg_defn = self.class.argument_definitions[arg_name] || raise("Not found #{arg_name} among #{self.class.argument_definitions.keys}")
|
46
|
-
arg_default_used = defaults_used.include?(arg_name)
|
47
|
-
arg_value = wrap_value(inner_value, arg_defn.type, context)
|
48
|
-
string_key = arg_defn.expose_as
|
49
|
-
memo[string_key] = ArgumentValue.new(string_key, arg_value, arg_defn, arg_default_used)
|
50
|
-
memo
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# @param key [String, Symbol] name or index of value to access
|
55
|
-
# @return [Object] the argument at that key
|
56
|
-
def [](key)
|
57
|
-
key_s = key.is_a?(String) ? key : key.to_s
|
58
|
-
@argument_values.fetch(key_s, NULL_ARGUMENT_VALUE).value
|
59
|
-
end
|
60
|
-
|
61
|
-
# @param key [String, Symbol] name of value to access
|
62
|
-
# @return [Boolean] true if the argument was present in this field
|
63
|
-
def key?(key)
|
64
|
-
key_s = key.is_a?(String) ? key : key.to_s
|
65
|
-
@argument_values.key?(key_s)
|
66
|
-
end
|
67
|
-
|
68
|
-
# @param key [String, Symbol] name of value to access
|
69
|
-
# @return [Boolean] true if the argument default was passed as the argument value to the resolver
|
70
|
-
def default_used?(key)
|
71
|
-
key_s = key.is_a?(String) ? key : key.to_s
|
72
|
-
@argument_values.fetch(key_s, NULL_ARGUMENT_VALUE).default_used?
|
73
|
-
end
|
74
|
-
|
75
|
-
# Get the hash of all values, with stringified keys
|
76
|
-
# @return [Hash] the stringified hash
|
77
|
-
def to_h
|
78
|
-
@to_h ||= begin
|
79
|
-
h = {}
|
80
|
-
each_value do |arg_value|
|
81
|
-
arg_key = arg_value.definition.expose_as
|
82
|
-
h[arg_key] = unwrap_value(arg_value.value)
|
83
|
-
end
|
84
|
-
h
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def_delegators :to_h, :keys, :values, :each, :any?
|
89
|
-
|
90
|
-
def prepare
|
91
|
-
self
|
92
|
-
end
|
93
|
-
|
94
|
-
# Access each key, value and type for the arguments in this set.
|
95
|
-
# @yield [argument_value] The {ArgumentValue} for each argument
|
96
|
-
# @yieldparam argument_value [ArgumentValue]
|
97
|
-
def each_value
|
98
|
-
@argument_values.each_value do |argument_value|
|
99
|
-
yield(argument_value)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
class << self
|
104
|
-
attr_accessor :argument_definitions
|
105
|
-
end
|
106
|
-
|
107
|
-
NoArguments = Class.new(self) do
|
108
|
-
self.argument_definitions = []
|
109
|
-
end
|
110
|
-
|
111
|
-
NO_ARGS = NoArguments.new({}, context: nil, defaults_used: Set.new)
|
112
|
-
|
113
|
-
# Convert this instance into valid Ruby keyword arguments
|
114
|
-
# @return [{Symbol=>Object}]
|
115
|
-
def to_kwargs
|
116
|
-
ruby_kwargs = {}
|
117
|
-
|
118
|
-
keys.each do |key|
|
119
|
-
ruby_kwargs[Schema::Member::BuildType.underscore(key).to_sym] = self[key]
|
120
|
-
end
|
121
|
-
|
122
|
-
ruby_kwargs
|
123
|
-
end
|
124
|
-
|
125
|
-
alias :to_hash :to_kwargs
|
126
|
-
|
127
|
-
private
|
128
|
-
|
129
|
-
class ArgumentValue
|
130
|
-
attr_reader :key, :value, :definition
|
131
|
-
attr_writer :default_used
|
132
|
-
|
133
|
-
def initialize(key, value, definition, default_used)
|
134
|
-
@key = key
|
135
|
-
@value = value
|
136
|
-
@definition = definition
|
137
|
-
@default_used = default_used
|
138
|
-
end
|
139
|
-
|
140
|
-
# @return [Boolean] true if the argument default was passed as the argument value to the resolver
|
141
|
-
def default_used?
|
142
|
-
@default_used
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
NULL_ARGUMENT_VALUE = ArgumentValue.new(nil, nil, nil, nil)
|
147
|
-
|
148
|
-
def wrap_value(value, arg_defn_type, context)
|
149
|
-
if value.nil?
|
150
|
-
nil
|
151
|
-
else
|
152
|
-
case arg_defn_type
|
153
|
-
when GraphQL::ListType
|
154
|
-
value.map { |item| wrap_value(item, arg_defn_type.of_type, context) }
|
155
|
-
when GraphQL::NonNullType
|
156
|
-
wrap_value(value, arg_defn_type.of_type, context)
|
157
|
-
when GraphQL::InputObjectType
|
158
|
-
if value.is_a?(Hash)
|
159
|
-
result = arg_defn_type.arguments_class.new(value, context: context, defaults_used: Set.new)
|
160
|
-
result.prepare
|
161
|
-
else
|
162
|
-
value
|
163
|
-
end
|
164
|
-
else
|
165
|
-
value
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def unwrap_value(value)
|
171
|
-
case value
|
172
|
-
when Array
|
173
|
-
value.map { |item| unwrap_value(item) }
|
174
|
-
when Hash
|
175
|
-
value.inject({}) do |memo, (key, value)|
|
176
|
-
memo[key] = unwrap_value(value)
|
177
|
-
memo
|
178
|
-
end
|
179
|
-
when GraphQL::Query::Arguments, GraphQL::Schema::InputObject
|
180
|
-
value.to_h
|
181
|
-
else
|
182
|
-
value
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# test_via: ../query.rb
|
3
|
-
module GraphQL
|
4
|
-
class Query
|
5
|
-
module ArgumentsCache
|
6
|
-
# @return [Hash<InternalRepresentation::Node, GraphQL::Language::NodesDirectiveNode => Hash<GraphQL::Field, GraphQL::Directive => GraphQL::Query::Arguments>>]
|
7
|
-
def self.build(query)
|
8
|
-
Hash.new do |h1, irep_or_ast_node|
|
9
|
-
h1[irep_or_ast_node] = Hash.new do |h2, definition|
|
10
|
-
ast_node = irep_or_ast_node.is_a?(GraphQL::InternalRepresentation::Node) ? irep_or_ast_node.ast_node : irep_or_ast_node
|
11
|
-
h2[definition] = if definition.arguments.empty?
|
12
|
-
GraphQL::Query::Arguments::NO_ARGS
|
13
|
-
else
|
14
|
-
GraphQL::Query::LiteralInput.from_arguments(
|
15
|
-
ast_node.arguments,
|
16
|
-
definition,
|
17
|
-
query.variables,
|
18
|
-
)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# test_via: ../query.rb
|
3
|
-
module GraphQL
|
4
|
-
class Query
|
5
|
-
class Executor
|
6
|
-
class PropagateNull < StandardError; end
|
7
|
-
|
8
|
-
# @return [GraphQL::Query] the query being executed
|
9
|
-
attr_reader :query
|
10
|
-
|
11
|
-
def initialize(query)
|
12
|
-
@query = query
|
13
|
-
end
|
14
|
-
|
15
|
-
# Evaluate {operation_name} on {query}.
|
16
|
-
# Handle {GraphQL::ExecutionError}s by putting them in the "errors" key.
|
17
|
-
# @return [Hash] A GraphQL response, with either a "data" key or an "errors" key
|
18
|
-
def result
|
19
|
-
execute
|
20
|
-
rescue GraphQL::ExecutionError => err
|
21
|
-
query.context.errors << err
|
22
|
-
{"errors" => [err.to_h]}
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def execute
|
28
|
-
operation = query.selected_operation
|
29
|
-
return {} if operation.nil?
|
30
|
-
|
31
|
-
op_type = operation.operation_type
|
32
|
-
root_type = query.root_type_for_operation(op_type)
|
33
|
-
execution_strategy_class = query.schema.execution_strategy_for_operation(op_type)
|
34
|
-
execution_strategy = execution_strategy_class.new
|
35
|
-
|
36
|
-
query.context.execution_strategy = execution_strategy
|
37
|
-
data_result = begin
|
38
|
-
execution_strategy.execute(operation, root_type, query)
|
39
|
-
rescue PropagateNull
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
result = { "data" => data_result }
|
43
|
-
error_result = query.context.errors.map(&:to_h)
|
44
|
-
|
45
|
-
if error_result.any?
|
46
|
-
result["errors"] = error_result
|
47
|
-
end
|
48
|
-
|
49
|
-
result
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module GraphQL
|
3
|
-
class Query
|
4
|
-
# Turn query string values into something useful for query execution
|
5
|
-
class LiteralInput
|
6
|
-
def self.coerce(type, ast_node, variables)
|
7
|
-
case ast_node
|
8
|
-
when nil
|
9
|
-
nil
|
10
|
-
when Language::Nodes::NullValue
|
11
|
-
nil
|
12
|
-
when Language::Nodes::VariableIdentifier
|
13
|
-
variables[ast_node.name]
|
14
|
-
else
|
15
|
-
case type
|
16
|
-
when GraphQL::ScalarType
|
17
|
-
# TODO smell
|
18
|
-
# This gets used for plain values during subscriber.trigger
|
19
|
-
if variables
|
20
|
-
type.coerce_input(ast_node, variables.context)
|
21
|
-
else
|
22
|
-
type.coerce_isolated_input(ast_node)
|
23
|
-
end
|
24
|
-
when GraphQL::EnumType
|
25
|
-
# TODO smell
|
26
|
-
# This gets used for plain values sometimes
|
27
|
-
v = ast_node.is_a?(GraphQL::Language::Nodes::Enum) ? ast_node.name : ast_node
|
28
|
-
if variables
|
29
|
-
type.coerce_input(v, variables.context)
|
30
|
-
else
|
31
|
-
type.coerce_isolated_input(v)
|
32
|
-
end
|
33
|
-
when GraphQL::NonNullType
|
34
|
-
LiteralInput.coerce(type.of_type, ast_node, variables)
|
35
|
-
when GraphQL::ListType
|
36
|
-
if ast_node.is_a?(Array)
|
37
|
-
ast_node.map { |element_ast| LiteralInput.coerce(type.of_type, element_ast, variables) }
|
38
|
-
else
|
39
|
-
[LiteralInput.coerce(type.of_type, ast_node, variables)]
|
40
|
-
end
|
41
|
-
when GraphQL::InputObjectType
|
42
|
-
# TODO smell: handling AST vs handling plain Ruby
|
43
|
-
next_args = ast_node.is_a?(Hash) ? ast_node : ast_node.arguments
|
44
|
-
from_arguments(next_args, type, variables)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.from_arguments(ast_arguments, argument_owner, variables)
|
50
|
-
context = variables ? variables.context : nil
|
51
|
-
values_hash = {}
|
52
|
-
defaults_used = Set.new
|
53
|
-
|
54
|
-
indexed_arguments = case ast_arguments
|
55
|
-
when Hash
|
56
|
-
ast_arguments
|
57
|
-
when Array
|
58
|
-
ast_arguments.each_with_object({}) { |a, memo| memo[a.name] = a }
|
59
|
-
else
|
60
|
-
raise ArgumentError, "Unexpected ast_arguments: #{ast_arguments}"
|
61
|
-
end
|
62
|
-
|
63
|
-
argument_defns = argument_owner.arguments
|
64
|
-
argument_defns.each do |arg_name, arg_defn|
|
65
|
-
ast_arg = indexed_arguments[arg_name]
|
66
|
-
# First, check the argument in the AST.
|
67
|
-
# If the value is a variable,
|
68
|
-
# only add a value if the variable is actually present.
|
69
|
-
# Otherwise, coerce the value in the AST, prepare the value and add it.
|
70
|
-
#
|
71
|
-
# TODO: since indexed_arguments can come from a plain Ruby hash,
|
72
|
-
# have to check for `false` or `nil` as hash values. This is getting smelly :S
|
73
|
-
if indexed_arguments.key?(arg_name)
|
74
|
-
arg_value = ast_arg.is_a?(GraphQL::Language::Nodes::Argument) ? ast_arg.value : ast_arg
|
75
|
-
|
76
|
-
value_is_a_variable = arg_value.is_a?(GraphQL::Language::Nodes::VariableIdentifier)
|
77
|
-
|
78
|
-
if (!value_is_a_variable || (value_is_a_variable && variables.key?(arg_value.name)))
|
79
|
-
|
80
|
-
value = coerce(arg_defn.type, arg_value, variables)
|
81
|
-
value = arg_defn.prepare(value, context)
|
82
|
-
|
83
|
-
if value.is_a?(GraphQL::ExecutionError)
|
84
|
-
value.ast_node = ast_arg
|
85
|
-
raise value
|
86
|
-
end
|
87
|
-
|
88
|
-
values_hash[arg_name] = value
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Then, the definition for a default value.
|
93
|
-
# If the definition has a default value and
|
94
|
-
# a value wasn't provided from the AST,
|
95
|
-
# then add the default value.
|
96
|
-
if arg_defn.default_value? && !values_hash.key?(arg_name)
|
97
|
-
value = arg_defn.default_value
|
98
|
-
defaults_used << arg_name
|
99
|
-
# `context` isn't present when pre-calculating defaults
|
100
|
-
if context
|
101
|
-
value = arg_defn.prepare(value, context)
|
102
|
-
if value.is_a?(GraphQL::ExecutionError)
|
103
|
-
value.ast_node = ast_arg
|
104
|
-
raise value
|
105
|
-
end
|
106
|
-
end
|
107
|
-
values_hash[arg_name] = value
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
result = argument_owner.arguments_class.new(values_hash, context: context, defaults_used: defaults_used)
|
112
|
-
result.prepare
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module GraphQL
|
3
|
-
class Query
|
4
|
-
class SerialExecution
|
5
|
-
class FieldResolution
|
6
|
-
attr_reader :irep_node, :parent_type, :target, :field, :arguments, :query
|
7
|
-
|
8
|
-
def initialize(selection, parent_type, target, query_ctx)
|
9
|
-
@irep_node = selection
|
10
|
-
@selection = selection
|
11
|
-
@parent_type = parent_type
|
12
|
-
@target = target
|
13
|
-
@query = query_ctx.query
|
14
|
-
@field = irep_node.definition
|
15
|
-
@field_ctx = query_ctx.spawn_child(
|
16
|
-
key: irep_node.name,
|
17
|
-
object: target,
|
18
|
-
irep_node: irep_node,
|
19
|
-
)
|
20
|
-
@arguments = @query.arguments_for(irep_node, @field)
|
21
|
-
end
|
22
|
-
|
23
|
-
def result
|
24
|
-
result_name = irep_node.name
|
25
|
-
raw_value = get_raw_value
|
26
|
-
if raw_value.is_a?(GraphQL::Execution::Execute::Skip)
|
27
|
-
{}
|
28
|
-
else
|
29
|
-
{ result_name => get_finished_value(raw_value) }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# GraphQL::Batch depends on this
|
34
|
-
def execution_context
|
35
|
-
@field_ctx
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
# After getting the value from the field's resolve method,
|
41
|
-
# continue by "finishing" the value, eg. executing sub-fields or coercing values
|
42
|
-
def get_finished_value(raw_value)
|
43
|
-
case raw_value
|
44
|
-
when GraphQL::ExecutionError
|
45
|
-
raw_value.ast_node = @field_ctx.ast_node
|
46
|
-
raw_value.path = @field_ctx.path
|
47
|
-
@query.context.errors.push(raw_value)
|
48
|
-
when Array
|
49
|
-
list_errors = raw_value.each_with_index.select { |value, _| value.is_a?(GraphQL::ExecutionError) }
|
50
|
-
if list_errors.any?
|
51
|
-
list_errors.each do |error, index|
|
52
|
-
error.ast_node = @field_ctx.ast_node
|
53
|
-
error.path = @field_ctx.path + [index]
|
54
|
-
@query.context.errors.push(error)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
begin
|
60
|
-
GraphQL::Query::SerialExecution::ValueResolution.resolve(
|
61
|
-
parent_type,
|
62
|
-
field,
|
63
|
-
field.type,
|
64
|
-
raw_value,
|
65
|
-
@selection,
|
66
|
-
@field_ctx,
|
67
|
-
)
|
68
|
-
rescue GraphQL::Query::Executor::PropagateNull
|
69
|
-
if field.type.kind.non_null?
|
70
|
-
raise
|
71
|
-
else
|
72
|
-
nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Get the result of:
|
78
|
-
# - Any middleware on this schema
|
79
|
-
# - The field's resolve method
|
80
|
-
# If the middleware chain returns a GraphQL::ExecutionError, its message
|
81
|
-
# is added to the "errors" key.
|
82
|
-
def get_raw_value
|
83
|
-
begin
|
84
|
-
@field_ctx.schema.middleware.invoke([parent_type, target, field, arguments, @field_ctx])
|
85
|
-
rescue GraphQL::ExecutionError => err
|
86
|
-
err
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module GraphQL
|
3
|
-
class Query
|
4
|
-
class SerialExecution
|
5
|
-
module OperationResolution
|
6
|
-
def self.resolve(selection, target, query)
|
7
|
-
result = query.context.execution_strategy.selection_resolution.resolve(
|
8
|
-
query.root_value,
|
9
|
-
target,
|
10
|
-
selection,
|
11
|
-
query.context,
|
12
|
-
)
|
13
|
-
|
14
|
-
result
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module GraphQL
|
3
|
-
class Query
|
4
|
-
class SerialExecution
|
5
|
-
module SelectionResolution
|
6
|
-
def self.resolve(target, current_type, selection, query_ctx)
|
7
|
-
selection_result = {}
|
8
|
-
|
9
|
-
selection.typed_children[current_type].each do |name, subselection|
|
10
|
-
selection_result.merge!(query_ctx.execution_strategy.field_resolution.new(
|
11
|
-
subselection,
|
12
|
-
current_type,
|
13
|
-
target,
|
14
|
-
query_ctx
|
15
|
-
).result)
|
16
|
-
end
|
17
|
-
|
18
|
-
selection_result
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module GraphQL
|
3
|
-
class Query
|
4
|
-
class SerialExecution
|
5
|
-
module ValueResolution
|
6
|
-
def self.resolve(parent_type, field_defn, field_type, value, selection, query_ctx)
|
7
|
-
if value.nil? || value.is_a?(GraphQL::ExecutionError)
|
8
|
-
if field_type.kind.non_null?
|
9
|
-
if value.nil?
|
10
|
-
type_error = GraphQL::InvalidNullError.new(parent_type, field_defn, value)
|
11
|
-
query_ctx.schema.type_error(type_error, query_ctx)
|
12
|
-
end
|
13
|
-
raise GraphQL::Query::Executor::PropagateNull
|
14
|
-
else
|
15
|
-
nil
|
16
|
-
end
|
17
|
-
else
|
18
|
-
case field_type.kind
|
19
|
-
when GraphQL::TypeKinds::SCALAR, GraphQL::TypeKinds::ENUM
|
20
|
-
field_type.coerce_result(value, query_ctx)
|
21
|
-
when GraphQL::TypeKinds::LIST
|
22
|
-
wrapped_type = field_type.of_type
|
23
|
-
result = []
|
24
|
-
i = 0
|
25
|
-
value.each do |inner_value|
|
26
|
-
inner_ctx = query_ctx.spawn_child(
|
27
|
-
key: i,
|
28
|
-
object: inner_value,
|
29
|
-
irep_node: selection,
|
30
|
-
)
|
31
|
-
|
32
|
-
result << resolve(
|
33
|
-
parent_type,
|
34
|
-
field_defn,
|
35
|
-
wrapped_type,
|
36
|
-
inner_value,
|
37
|
-
selection,
|
38
|
-
inner_ctx,
|
39
|
-
)
|
40
|
-
i += 1
|
41
|
-
end
|
42
|
-
result
|
43
|
-
when GraphQL::TypeKinds::NON_NULL
|
44
|
-
wrapped_type = field_type.of_type
|
45
|
-
resolve(
|
46
|
-
parent_type,
|
47
|
-
field_defn,
|
48
|
-
wrapped_type,
|
49
|
-
value,
|
50
|
-
selection,
|
51
|
-
query_ctx,
|
52
|
-
)
|
53
|
-
when GraphQL::TypeKinds::OBJECT
|
54
|
-
query_ctx.execution_strategy.selection_resolution.resolve(
|
55
|
-
value,
|
56
|
-
field_type,
|
57
|
-
selection,
|
58
|
-
query_ctx
|
59
|
-
)
|
60
|
-
when GraphQL::TypeKinds::UNION, GraphQL::TypeKinds::INTERFACE
|
61
|
-
query = query_ctx.query
|
62
|
-
resolved_type = query.resolve_type(value)
|
63
|
-
possible_types = query.possible_types(field_type)
|
64
|
-
|
65
|
-
if !possible_types.include?(resolved_type)
|
66
|
-
type_error = GraphQL::UnresolvedTypeError.new(value, field_defn, parent_type, resolved_type, possible_types)
|
67
|
-
query.schema.type_error(type_error, query_ctx)
|
68
|
-
raise GraphQL::Query::Executor::PropagateNull
|
69
|
-
else
|
70
|
-
resolve(
|
71
|
-
parent_type,
|
72
|
-
field_defn,
|
73
|
-
resolved_type,
|
74
|
-
value,
|
75
|
-
selection,
|
76
|
-
query_ctx,
|
77
|
-
)
|
78
|
-
end
|
79
|
-
else
|
80
|
-
raise("Unknown type kind: #{field_type.kind}")
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "graphql/query/serial_execution/value_resolution"
|
3
|
-
require "graphql/query/serial_execution/field_resolution"
|
4
|
-
require "graphql/query/serial_execution/operation_resolution"
|
5
|
-
require "graphql/query/serial_execution/selection_resolution"
|
6
|
-
|
7
|
-
module GraphQL
|
8
|
-
class Query
|
9
|
-
class SerialExecution
|
10
|
-
# This is the only required method for an Execution strategy.
|
11
|
-
# You could create a custom execution strategy and configure your schema to
|
12
|
-
# use that custom strategy instead.
|
13
|
-
#
|
14
|
-
# @param ast_operation [GraphQL::Language::Nodes::OperationDefinition] The operation definition to run
|
15
|
-
# @param root_type [GraphQL::ObjectType] either the query type or the mutation type
|
16
|
-
# @param query_object [GraphQL::Query] the query object for this execution
|
17
|
-
# @return [Hash] a spec-compliant GraphQL result, as a hash
|
18
|
-
def execute(ast_operation, root_type, query_object)
|
19
|
-
operation_resolution.resolve(
|
20
|
-
query_object.irep_selection,
|
21
|
-
root_type,
|
22
|
-
query_object
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
def field_resolution
|
27
|
-
self.class::FieldResolution
|
28
|
-
end
|
29
|
-
|
30
|
-
def operation_resolution
|
31
|
-
self.class::OperationResolution
|
32
|
-
end
|
33
|
-
|
34
|
-
def selection_resolution
|
35
|
-
self.class::SelectionResolution
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|