graphql 1.9.21 → 2.0.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.
Potentially problematic release.
This version of graphql might be problematic. Click here for more details.
- 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 +44 -7
- 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 +63 -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 +22 -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 +29 -2
- 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 +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/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 +108 -14
- data/lib/graphql/execution/instrumentation.rb +1 -1
- 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 +37 -25
- data/lib/graphql/execution/interpreter/runtime.rb +715 -387
- data/lib/graphql/execution/interpreter.rb +32 -31
- data/lib/graphql/execution/lazy/lazy_method_map.rb +4 -0
- data/lib/graphql/execution/lazy.rb +5 -1
- data/lib/graphql/execution/lookahead.rb +32 -114
- data/lib/graphql/execution/multiplex.rb +60 -92
- data/lib/graphql/execution.rb +11 -3
- 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 +27 -17
- data/lib/graphql/introspection.rb +99 -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 +99 -63
- data/lib/graphql/language/lexer.rb +53 -27
- data/lib/graphql/language/lexer.rl +5 -3
- data/lib/graphql/language/nodes.rb +64 -93
- data/lib/graphql/language/parser.rb +929 -896
- data/lib/graphql/language/parser.y +125 -102
- data/lib/graphql/language/printer.rb +11 -2
- 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 +77 -0
- data/lib/graphql/pagination/connection.rb +226 -0
- data/lib/graphql/pagination/connections.rb +134 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +226 -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 +51 -190
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +23 -6
- data/lib/graphql/query/literal_input.rb +26 -11
- data/lib/graphql/query/null_context.rb +24 -8
- data/lib/graphql/query/validation_pipeline.rb +12 -38
- data/lib/graphql/query/variable_validation_error.rb +2 -2
- data/lib/graphql/query/variables.rb +26 -9
- data/lib/graphql/query.rb +62 -32
- data/lib/graphql/railtie.rb +6 -102
- data/lib/graphql/rake_task/validate.rb +3 -0
- data/lib/graphql/rake_task.rb +12 -9
- data/lib/graphql/relay/range_add.rb +23 -9
- 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 +240 -0
- data/lib/graphql/schema/argument.rb +262 -28
- 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 +319 -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/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 +115 -22
- data/lib/graphql/schema/enum_value.rb +16 -21
- data/lib/graphql/schema/field/connection_extension.rb +46 -20
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +376 -291
- 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 +147 -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 +3 -2
- data/lib/graphql/schema/list.rb +46 -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 +23 -14
- data/lib/graphql/schema/member/has_arguments.rb +212 -23
- 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 +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/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 -65
- data/lib/graphql/schema/printer.rb +16 -35
- data/lib/graphql/schema/relay_classic_mutation.rb +57 -32
- data/lib/graphql/schema/resolver/has_payload_type.rb +34 -4
- data/lib/graphql/schema/resolver.rb +133 -79
- data/lib/graphql/schema/scalar.rb +40 -15
- data/lib/graphql/schema/subscription.rb +57 -21
- data/lib/graphql/schema/timeout.rb +29 -15
- data/lib/graphql/schema/type_expression.rb +21 -13
- data/lib/graphql/schema/type_membership.rb +19 -5
- data/lib/graphql/schema/union.rb +39 -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 +182 -32
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +687 -891
- data/lib/graphql/static_validation/all_rules.rb +2 -0
- data/lib/graphql/static_validation/base_visitor.rb +21 -31
- data/lib/graphql/static_validation/definition_dependencies.rb +0 -1
- data/lib/graphql/static_validation/error.rb +3 -1
- data/lib/graphql/static_validation/literal_validator.rb +51 -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 +1 -1
- 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/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 +1 -1
- 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 +123 -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 +111 -52
- 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 +14 -1
- 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 +57 -29
- 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 +16 -8
- data/lib/graphql/types/iso_8601_date_time.rb +32 -10
- data/lib/graphql/types/relay/base_connection.rb +6 -88
- data/lib/graphql/types/relay/base_edge.rb +2 -34
- data/lib/graphql/types/relay/connection_behaviors.rb +170 -0
- data/lib/graphql/types/relay/default_relay.rb +21 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +64 -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 +97 -231
- 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/interpreter/hash_response.rb +0 -46
- 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/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
@@ -15,23 +15,110 @@ module GraphQL
|
|
15
15
|
# @return [Object]
|
16
16
|
attr_reader :options
|
17
17
|
|
18
|
+
# @return [Array<Symbol>, nil] `default_argument`s added, if any were added (otherwise, `nil`)
|
19
|
+
attr_reader :added_default_arguments
|
20
|
+
|
18
21
|
# Called when the extension is mounted with `extension(name, options)`.
|
19
|
-
# The instance
|
22
|
+
# The instance will be frozen to avoid improper use of state during execution.
|
20
23
|
# @param field [GraphQL::Schema::Field] The field where this extension was mounted
|
21
24
|
# @param options [Object] The second argument to `extension`, or `{}` if nothing was passed.
|
22
25
|
def initialize(field:, options:)
|
23
26
|
@field = field
|
24
27
|
@options = options || {}
|
28
|
+
@added_default_arguments = nil
|
25
29
|
apply
|
26
|
-
freeze
|
27
30
|
end
|
28
31
|
|
32
|
+
class << self
|
33
|
+
# @return [Array(Array, Hash), nil] A list of default argument configs, or `nil` if there aren't any
|
34
|
+
def default_argument_configurations
|
35
|
+
args = superclass.respond_to?(:default_argument_configurations) ? superclass.default_argument_configurations : nil
|
36
|
+
if @own_default_argument_configurations
|
37
|
+
if args
|
38
|
+
args.concat(@own_default_argument_configurations)
|
39
|
+
else
|
40
|
+
args = @own_default_argument_configurations.dup
|
41
|
+
end
|
42
|
+
end
|
43
|
+
args
|
44
|
+
end
|
45
|
+
|
46
|
+
# @see Argument#initialize
|
47
|
+
# @see HasArguments#argument
|
48
|
+
def default_argument(*argument_args, **argument_kwargs)
|
49
|
+
configs = @own_default_argument_configurations ||= []
|
50
|
+
configs << [argument_args, argument_kwargs]
|
51
|
+
end
|
52
|
+
|
53
|
+
# If configured, these `extras` will be added to the field if they aren't already present,
|
54
|
+
# but removed by from `arguments` before the field's `resolve` is called.
|
55
|
+
# (The extras _will_ be present for other extensions, though.)
|
56
|
+
#
|
57
|
+
# @param new_extras [Array<Symbol>] If provided, assign extras used by this extension
|
58
|
+
# @return [Array<Symbol>] any extras assigned to this extension
|
59
|
+
def extras(new_extras = nil)
|
60
|
+
if new_extras
|
61
|
+
@own_extras = new_extras
|
62
|
+
end
|
63
|
+
|
64
|
+
inherited_extras = self.superclass.respond_to?(:extras) ? superclass.extras : nil
|
65
|
+
if @own_extras
|
66
|
+
if inherited_extras
|
67
|
+
inherited_extras + @own_extras
|
68
|
+
else
|
69
|
+
@own_extras
|
70
|
+
end
|
71
|
+
elsif inherited_extras
|
72
|
+
inherited_extras
|
73
|
+
else
|
74
|
+
NO_EXTRAS
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
NO_EXTRAS = [].freeze
|
80
|
+
private_constant :NO_EXTRAS
|
81
|
+
|
29
82
|
# Called when this extension is attached to a field.
|
30
83
|
# The field definition may be extended during this method.
|
31
84
|
# @return [void]
|
32
85
|
def apply
|
33
86
|
end
|
34
87
|
|
88
|
+
# Called after the field's definition block has been executed.
|
89
|
+
# (Any arguments from the block are present on `field`)
|
90
|
+
# @return [void]
|
91
|
+
def after_define
|
92
|
+
end
|
93
|
+
|
94
|
+
# @api private
|
95
|
+
def after_define_apply
|
96
|
+
after_define
|
97
|
+
if (configs = self.class.default_argument_configurations)
|
98
|
+
existing_keywords = field.all_argument_definitions.map(&:keyword)
|
99
|
+
existing_keywords.uniq!
|
100
|
+
@added_default_arguments = []
|
101
|
+
configs.each do |config|
|
102
|
+
argument_args, argument_kwargs = config
|
103
|
+
arg_name = argument_args[0]
|
104
|
+
if !existing_keywords.include?(arg_name)
|
105
|
+
@added_default_arguments << arg_name
|
106
|
+
field.argument(*argument_args, **argument_kwargs)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
if (extras = self.class.extras).any?
|
111
|
+
@added_extras = extras - field.extras
|
112
|
+
field.extras(@added_extras)
|
113
|
+
else
|
114
|
+
@added_extras = nil
|
115
|
+
end
|
116
|
+
freeze
|
117
|
+
end
|
118
|
+
|
119
|
+
# @api private
|
120
|
+
attr_reader :added_extras
|
121
|
+
|
35
122
|
# Called before resolving {#field}. It should either:
|
36
123
|
#
|
37
124
|
# - `yield` values to continue execution; OR
|
@@ -1,13 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
class Schema
|
3
4
|
module FindInheritedValue
|
5
|
+
module EmptyObjects
|
6
|
+
EMPTY_HASH = {}.freeze
|
7
|
+
EMPTY_ARRAY = [].freeze
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.extended(child_cls)
|
11
|
+
child_cls.singleton_class.include(EmptyObjects)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.included(child_cls)
|
15
|
+
child_cls.include(EmptyObjects)
|
16
|
+
end
|
17
|
+
|
4
18
|
private
|
5
19
|
|
6
20
|
def find_inherited_value(method_name, default_value = nil)
|
7
21
|
if self.is_a?(Class)
|
8
22
|
superclass.respond_to?(method_name, true) ? superclass.send(method_name) : default_value
|
9
23
|
else
|
10
|
-
|
24
|
+
ancestors_except_self = ancestors
|
25
|
+
ancestors_except_self.delete(self)
|
26
|
+
ancestors_except_self.each do |ancestor|
|
11
27
|
if ancestor.respond_to?(method_name, true)
|
12
28
|
return ancestor.send(method_name)
|
13
29
|
end
|
@@ -38,7 +38,7 @@ module GraphQL
|
|
38
38
|
|
39
39
|
find_in_directive(directive, path: path)
|
40
40
|
else
|
41
|
-
type = schema.
|
41
|
+
type = schema.get_type(type_or_directive) # rubocop:disable Development/ContextIsPassedCop -- build-time
|
42
42
|
|
43
43
|
if type.nil?
|
44
44
|
raise MemberNotFoundError, "Could not find type `#{type_or_directive}` in schema."
|
@@ -56,7 +56,7 @@ module GraphQL
|
|
56
56
|
|
57
57
|
def find_in_directive(directive, path:)
|
58
58
|
argument_name = path.shift
|
59
|
-
argument = directive.
|
59
|
+
argument = directive.get_argument(argument_name) # rubocop:disable Development/ContextIsPassedCop -- build-time
|
60
60
|
|
61
61
|
if argument.nil?
|
62
62
|
raise MemberNotFoundError, "Could not find argument `#{argument_name}` on directive #{directive}."
|
@@ -66,22 +66,24 @@ module GraphQL
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def find_in_type(type, path:)
|
69
|
-
case type
|
70
|
-
when
|
69
|
+
case type.kind.name
|
70
|
+
when "OBJECT"
|
71
71
|
find_in_fields_type(type, kind: "object", path: path)
|
72
|
-
when
|
72
|
+
when "INTERFACE"
|
73
73
|
find_in_fields_type(type, kind: "interface", path: path)
|
74
|
-
when
|
74
|
+
when "INPUT_OBJECT"
|
75
75
|
find_in_input_object(type, path: path)
|
76
|
-
when
|
76
|
+
when "UNION"
|
77
77
|
# Error out if path that was provided is too long
|
78
78
|
# i.e UnionType.PossibleType.aField
|
79
79
|
# Use PossibleType.aField instead.
|
80
80
|
if invalid = path.first
|
81
81
|
raise MemberNotFoundError, "Cannot select union possible type `#{invalid}`. Select the type directly instead."
|
82
82
|
end
|
83
|
-
when
|
83
|
+
when "ENUM"
|
84
84
|
find_in_enum_type(type, path: path)
|
85
|
+
else
|
86
|
+
raise "Unexpected find_in_type: #{type.inspect} (#{path})"
|
85
87
|
end
|
86
88
|
end
|
87
89
|
|
@@ -90,7 +92,7 @@ module GraphQL
|
|
90
92
|
field = schema.get_field(type, field_name)
|
91
93
|
|
92
94
|
if field.nil?
|
93
|
-
raise MemberNotFoundError, "Could not find field `#{field_name}` on #{kind} type `#{type}`."
|
95
|
+
raise MemberNotFoundError, "Could not find field `#{field_name}` on #{kind} type `#{type.graphql_name}`."
|
94
96
|
end
|
95
97
|
|
96
98
|
return field if path.empty?
|
@@ -100,7 +102,7 @@ module GraphQL
|
|
100
102
|
|
101
103
|
def find_in_field(field, path:)
|
102
104
|
argument_name = path.shift
|
103
|
-
argument = field.
|
105
|
+
argument = field.get_argument(argument_name) # rubocop:disable Development/ContextIsPassedCop -- build-time
|
104
106
|
|
105
107
|
if argument.nil?
|
106
108
|
raise MemberNotFoundError, "Could not find argument `#{argument_name}` on field `#{field.name}`."
|
@@ -117,10 +119,10 @@ module GraphQL
|
|
117
119
|
|
118
120
|
def find_in_input_object(input_object, path:)
|
119
121
|
field_name = path.shift
|
120
|
-
input_field = input_object.
|
122
|
+
input_field = input_object.get_argument(field_name) # rubocop:disable Development/ContextIsPassedCop -- build-time
|
121
123
|
|
122
124
|
if input_field.nil?
|
123
|
-
raise MemberNotFoundError, "Could not find input field `#{field_name}` on input object type `#{input_object}`."
|
125
|
+
raise MemberNotFoundError, "Could not find input field `#{field_name}` on input object type `#{input_object.graphql_name}`."
|
124
126
|
end
|
125
127
|
|
126
128
|
# Error out if path that was provided is too long
|
@@ -134,10 +136,10 @@ module GraphQL
|
|
134
136
|
|
135
137
|
def find_in_enum_type(enum_type, path:)
|
136
138
|
value_name = path.shift
|
137
|
-
enum_value = enum_type.
|
139
|
+
enum_value = enum_type.enum_values.find { |v| v.graphql_name == value_name } # rubocop:disable Development/ContextIsPassedCop -- build-time, not runtime
|
138
140
|
|
139
141
|
if enum_value.nil?
|
140
|
-
raise MemberNotFoundError, "Could not find enum value `#{value_name}` on enum type `#{enum_type}`."
|
142
|
+
raise MemberNotFoundError, "Could not find enum value `#{value_name}` on enum type `#{enum_type.graphql_name}`."
|
141
143
|
end
|
142
144
|
|
143
145
|
# Error out if path that was provided is too long
|
@@ -2,55 +2,42 @@
|
|
2
2
|
module GraphQL
|
3
3
|
class Schema
|
4
4
|
class InputObject < GraphQL::Schema::Member
|
5
|
-
extend GraphQL::Schema::Member::AcceptsDefinition
|
6
5
|
extend Forwardable
|
7
6
|
extend GraphQL::Schema::Member::HasArguments
|
7
|
+
extend GraphQL::Schema::Member::HasArguments::ArgumentObjectLoader
|
8
|
+
extend GraphQL::Schema::Member::ValidatesInput
|
9
|
+
extend GraphQL::Schema::Member::HasValidators
|
10
|
+
|
8
11
|
include GraphQL::Dig
|
9
12
|
|
10
|
-
|
13
|
+
# @return [GraphQL::Query::Context] The context for this query
|
14
|
+
attr_reader :context
|
15
|
+
# @return [GraphQL::Execution::Interpereter::Arguments] The underlying arguments instance
|
16
|
+
attr_reader :arguments
|
17
|
+
|
18
|
+
# Ruby-like hash behaviors, read-only
|
19
|
+
def_delegators :@ruby_style_hash, :keys, :values, :each, :map, :any?, :empty?
|
20
|
+
|
21
|
+
def initialize(arguments, ruby_kwargs:, context:, defaults_used:)
|
11
22
|
@context = context
|
12
|
-
|
13
|
-
|
14
|
-
else
|
15
|
-
@arguments = self.class.arguments_class.new(values, context: context, defaults_used: defaults_used)
|
16
|
-
# Symbolized, underscored hash:
|
17
|
-
@ruby_style_hash = @arguments.to_kwargs
|
18
|
-
end
|
23
|
+
@ruby_style_hash = ruby_kwargs
|
24
|
+
@arguments = arguments
|
19
25
|
# Apply prepares, not great to have it duplicated here.
|
20
|
-
|
21
|
-
self.class.arguments.each do |name, arg_defn|
|
22
|
-
@arguments_by_keyword[arg_defn.keyword] = arg_defn
|
26
|
+
self.class.arguments(context).each_value do |arg_defn|
|
23
27
|
ruby_kwargs_key = arg_defn.keyword
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
else
|
31
|
-
load_application_object(arg_defn, loads, value)
|
28
|
+
if @ruby_style_hash.key?(ruby_kwargs_key)
|
29
|
+
# Weirdly, procs are applied during coercion, but not methods.
|
30
|
+
# Probably because these methods require a `self`.
|
31
|
+
if arg_defn.prepare.is_a?(Symbol) || context.nil?
|
32
|
+
prepared_value = arg_defn.prepare_value(self, @ruby_style_hash[ruby_kwargs_key])
|
33
|
+
overwrite_argument(ruby_kwargs_key, prepared_value)
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
35
|
-
if @ruby_style_hash.key?(ruby_kwargs_key) && arg_defn.prepare
|
36
|
-
@ruby_style_hash[ruby_kwargs_key] = arg_defn.prepare_value(self, @ruby_style_hash[ruby_kwargs_key])
|
37
|
-
end
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
41
|
-
# @return [GraphQL::Query::Context] The context for this query
|
42
|
-
attr_reader :context
|
43
|
-
|
44
|
-
# @return [GraphQL::Query::Arguments] The underlying arguments instance
|
45
|
-
attr_reader :arguments
|
46
|
-
|
47
|
-
# Ruby-like hash behaviors, read-only
|
48
|
-
def_delegators :@ruby_style_hash, :keys, :values, :each, :map, :any?, :empty?
|
49
|
-
|
50
39
|
def to_h
|
51
|
-
@ruby_style_hash
|
52
|
-
h.merge(key => unwrap_value(value))
|
53
|
-
end
|
40
|
+
unwrap_value(@ruby_style_hash)
|
54
41
|
end
|
55
42
|
|
56
43
|
def to_hash
|
@@ -58,7 +45,28 @@ module GraphQL
|
|
58
45
|
end
|
59
46
|
|
60
47
|
def prepare
|
61
|
-
|
48
|
+
if @context
|
49
|
+
object = @context[:current_object]
|
50
|
+
# Pass this object's class with `as` so that messages are rendered correctly from inherited validators
|
51
|
+
Schema::Validator.validate!(self.class.validators, object, @context, @ruby_style_hash, as: self.class)
|
52
|
+
self
|
53
|
+
else
|
54
|
+
self
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.authorized?(obj, value, ctx)
|
59
|
+
# Authorize each argument (but this doesn't apply if `prepare` is implemented):
|
60
|
+
if value.respond_to?(:key?)
|
61
|
+
arguments(ctx).each do |_name, input_obj_arg|
|
62
|
+
if value.key?(input_obj_arg.keyword) &&
|
63
|
+
!input_obj_arg.authorized?(obj, value[input_obj_arg.keyword], ctx)
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
# It didn't early-return false:
|
69
|
+
true
|
62
70
|
end
|
63
71
|
|
64
72
|
def unwrap_value(value)
|
@@ -66,8 +74,8 @@ module GraphQL
|
|
66
74
|
when Array
|
67
75
|
value.map { |item| unwrap_value(item) }
|
68
76
|
when Hash
|
69
|
-
value.
|
70
|
-
h.merge(key => unwrap_value(value))
|
77
|
+
value.reduce({}) do |h, (key, value)|
|
78
|
+
h.merge!(key => unwrap_value(value))
|
71
79
|
end
|
72
80
|
when InputObject
|
73
81
|
value.to_h
|
@@ -90,7 +98,7 @@ module GraphQL
|
|
90
98
|
end
|
91
99
|
|
92
100
|
def key?(key)
|
93
|
-
@ruby_style_hash.key?(key) || (@arguments && @arguments.key?(key))
|
101
|
+
@ruby_style_hash.key?(key) || (@arguments && @arguments.key?(key)) || false
|
94
102
|
end
|
95
103
|
|
96
104
|
# A copy of the Ruby-style hash
|
@@ -99,37 +107,116 @@ module GraphQL
|
|
99
107
|
end
|
100
108
|
|
101
109
|
class << self
|
102
|
-
# @return [Class<GraphQL::Arguments>]
|
103
|
-
attr_accessor :arguments_class
|
104
|
-
|
105
110
|
def argument(*args, **kwargs, &block)
|
106
111
|
argument_defn = super(*args, **kwargs, &block)
|
107
112
|
# Add a method access
|
108
113
|
method_name = argument_defn.keyword
|
109
|
-
|
110
|
-
|
114
|
+
class_eval <<-RUBY, __FILE__, __LINE__
|
115
|
+
def #{method_name}
|
116
|
+
self[#{method_name.inspect}]
|
117
|
+
end
|
118
|
+
RUBY
|
119
|
+
argument_defn
|
120
|
+
end
|
121
|
+
|
122
|
+
def kind
|
123
|
+
GraphQL::TypeKinds::INPUT_OBJECT
|
124
|
+
end
|
125
|
+
|
126
|
+
# @api private
|
127
|
+
INVALID_OBJECT_MESSAGE = "Expected %{object} to be a key-value object responding to `to_h` or `to_unsafe_h`."
|
128
|
+
|
129
|
+
def validate_non_null_input(input, ctx)
|
130
|
+
result = GraphQL::Query::InputValidationResult.new
|
131
|
+
|
132
|
+
warden = ctx.warden
|
133
|
+
|
134
|
+
if input.is_a?(Array)
|
135
|
+
result.add_problem(INVALID_OBJECT_MESSAGE % { object: JSON.generate(input, quirks_mode: true) })
|
136
|
+
return result
|
111
137
|
end
|
138
|
+
|
139
|
+
if !(input.respond_to?(:to_h) || input.respond_to?(:to_unsafe_h))
|
140
|
+
# We're not sure it'll act like a hash, so reject it:
|
141
|
+
result.add_problem(INVALID_OBJECT_MESSAGE % { object: JSON.generate(input, quirks_mode: true) })
|
142
|
+
return result
|
143
|
+
end
|
144
|
+
|
145
|
+
# Inject missing required arguments
|
146
|
+
missing_required_inputs = self.arguments(ctx).reduce({}) do |m, (argument_name, argument)|
|
147
|
+
if !input.key?(argument_name) && argument.type.non_null? && warden.get_argument(self, argument_name)
|
148
|
+
m[argument_name] = nil
|
149
|
+
end
|
150
|
+
|
151
|
+
m
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
[input, missing_required_inputs].each do |args_to_validate|
|
156
|
+
args_to_validate.each do |argument_name, value|
|
157
|
+
argument = warden.get_argument(self, argument_name)
|
158
|
+
# Items in the input that are unexpected
|
159
|
+
unless argument
|
160
|
+
result.add_problem("Field is not defined on #{self.graphql_name}", [argument_name])
|
161
|
+
next
|
162
|
+
end
|
163
|
+
# Items in the input that are expected, but have invalid values
|
164
|
+
argument_result = argument.type.validate_input(value, ctx)
|
165
|
+
result.merge_result!(argument_name, argument_result) unless argument_result.valid?
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
result
|
112
170
|
end
|
113
171
|
|
114
|
-
def
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
172
|
+
def coerce_input(value, ctx)
|
173
|
+
if value.nil?
|
174
|
+
return nil
|
175
|
+
end
|
176
|
+
|
177
|
+
arguments = coerce_arguments(nil, value, ctx)
|
178
|
+
|
179
|
+
ctx.schema.after_lazy(arguments) do |resolved_arguments|
|
180
|
+
if resolved_arguments.is_a?(GraphQL::Error)
|
181
|
+
raise resolved_arguments
|
182
|
+
else
|
183
|
+
input_obj_instance = self.new(resolved_arguments, ruby_kwargs: resolved_arguments.keyword_arguments, context: ctx, defaults_used: nil)
|
184
|
+
input_obj_instance.prepare
|
185
|
+
end
|
122
186
|
end
|
123
|
-
# Make a reference to a classic-style Arguments class
|
124
|
-
self.arguments_class = GraphQL::Query::Arguments.construct_arguments_class(type_defn)
|
125
|
-
# But use this InputObject class at runtime
|
126
|
-
type_defn.arguments_class = self
|
127
|
-
type_defn
|
128
187
|
end
|
129
188
|
|
130
|
-
|
131
|
-
|
189
|
+
# It's funny to think of a _result_ of an input object.
|
190
|
+
# This is used for rendering the default value in introspection responses.
|
191
|
+
def coerce_result(value, ctx)
|
192
|
+
# Allow the application to provide values as :snake_symbols, and convert them to the camelStrings
|
193
|
+
value = value.reduce({}) { |memo, (k, v)| memo[Member::BuildType.camelize(k.to_s)] = v; memo }
|
194
|
+
|
195
|
+
result = {}
|
196
|
+
|
197
|
+
arguments(ctx).each do |input_key, input_field_defn|
|
198
|
+
input_value = value[input_key]
|
199
|
+
if value.key?(input_key)
|
200
|
+
result[input_key] = if input_value.nil?
|
201
|
+
nil
|
202
|
+
else
|
203
|
+
input_field_defn.type.coerce_result(input_value, ctx)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
result
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
private
|
213
|
+
|
214
|
+
def overwrite_argument(key, value)
|
215
|
+
# Argument keywords come in frozen from the interpreter, dup them before modifying them.
|
216
|
+
if @ruby_style_hash.frozen?
|
217
|
+
@ruby_style_hash = @ruby_style_hash.dup
|
132
218
|
end
|
219
|
+
@ruby_style_hash[key] = value
|
133
220
|
end
|
134
221
|
end
|
135
222
|
end
|
@@ -4,14 +4,17 @@ module GraphQL
|
|
4
4
|
module Interface
|
5
5
|
include GraphQL::Schema::Member::GraphQLTypeNames
|
6
6
|
module DefinitionMethods
|
7
|
-
include GraphQL::Schema::Member::CachedGraphQLDefinition
|
8
|
-
include GraphQL::Relay::TypeExtensions
|
9
7
|
include GraphQL::Schema::Member::BaseDSLMethods
|
8
|
+
# ConfigurationExtension's responsibilities are in `def included` below
|
10
9
|
include GraphQL::Schema::Member::TypeSystemHelpers
|
11
10
|
include GraphQL::Schema::Member::HasFields
|
12
11
|
include GraphQL::Schema::Member::HasPath
|
13
12
|
include GraphQL::Schema::Member::RelayShortcuts
|
14
13
|
include GraphQL::Schema::Member::Scoped
|
14
|
+
include GraphQL::Schema::Member::HasAstNode
|
15
|
+
include GraphQL::Schema::Member::HasUnresolvedTypeError
|
16
|
+
include GraphQL::Schema::Member::HasDirectives
|
17
|
+
include GraphQL::Schema::Member::HasInterfaces
|
15
18
|
|
16
19
|
# Methods defined in this block will be:
|
17
20
|
# - Added as class methods to this interface
|
@@ -20,19 +23,14 @@ module GraphQL
|
|
20
23
|
self::DefinitionMethods.module_eval(&block)
|
21
24
|
end
|
22
25
|
|
23
|
-
#
|
26
|
+
# @see {Schema::Warden} hides interfaces without visible implementations
|
24
27
|
def visible?(context)
|
25
|
-
|
26
|
-
if context.schema.visible?(type, context)
|
27
|
-
return true
|
28
|
-
end
|
29
|
-
end
|
30
|
-
false
|
28
|
+
true
|
31
29
|
end
|
32
30
|
|
33
31
|
# The interface is accessible if any of its possible types are accessible
|
34
32
|
def accessible?(context)
|
35
|
-
context.schema.possible_types(self).each do |type|
|
33
|
+
context.schema.possible_types(self, context).each do |type|
|
36
34
|
if context.schema.accessible?(type, context)
|
37
35
|
return true
|
38
36
|
end
|
@@ -40,6 +38,14 @@ module GraphQL
|
|
40
38
|
false
|
41
39
|
end
|
42
40
|
|
41
|
+
def type_membership_class(membership_class = nil)
|
42
|
+
if membership_class
|
43
|
+
@type_membership_class = membership_class
|
44
|
+
else
|
45
|
+
@type_membership_class || find_inherited_value(:type_membership_class, GraphQL::Schema::TypeMembership)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
43
49
|
# Here's the tricky part. Make sure behavior keeps making its way down the inheritance chain.
|
44
50
|
def included(child_class)
|
45
51
|
if !child_class.is_a?(Class)
|
@@ -49,9 +55,11 @@ module GraphQL
|
|
49
55
|
# We need this before we can call `own_interfaces`
|
50
56
|
child_class.extend(Schema::Interface::DefinitionMethods)
|
51
57
|
|
52
|
-
child_class.
|
53
|
-
child_class.
|
54
|
-
|
58
|
+
child_class.type_membership_class(self.type_membership_class)
|
59
|
+
child_class.ancestors.reverse_each do |ancestor|
|
60
|
+
if ancestor.const_defined?(:DefinitionMethods)
|
61
|
+
child_class.extend(ancestor::DefinitionMethods)
|
62
|
+
end
|
55
63
|
end
|
56
64
|
|
57
65
|
# Use an instance variable to tell whether it's been included previously or not;
|
@@ -63,9 +71,15 @@ module GraphQL
|
|
63
71
|
child_class.const_set(:DefinitionMethods, defn_methods_module)
|
64
72
|
child_class.extend(child_class::DefinitionMethods)
|
65
73
|
end
|
74
|
+
child_class.introspection(introspection)
|
75
|
+
child_class.description(description)
|
76
|
+
# If interfaces are mixed into each other, only define this class once
|
77
|
+
if !child_class.const_defined?(:UnresolvedTypeError, false)
|
78
|
+
add_unresolved_type_error(child_class)
|
79
|
+
end
|
66
80
|
elsif child_class < GraphQL::Schema::Object
|
67
81
|
# This is being included into an object type, make sure it's using `implements(...)`
|
68
|
-
backtrace_line = caller(0, 10).find { |line| line.include?("schema/
|
82
|
+
backtrace_line = caller(0, 10).find { |line| line.include?("schema/member/has_interfaces.rb") && line.include?("in `implements'")}
|
69
83
|
if !backtrace_line
|
70
84
|
raise "Attach interfaces using `implements(#{self})`, not `include(#{self})`"
|
71
85
|
end
|
@@ -84,40 +98,11 @@ module GraphQL
|
|
84
98
|
end
|
85
99
|
end
|
86
100
|
|
87
|
-
def to_graphql
|
88
|
-
type_defn = GraphQL::InterfaceType.new
|
89
|
-
type_defn.name = graphql_name
|
90
|
-
type_defn.description = description
|
91
|
-
type_defn.orphan_types = orphan_types
|
92
|
-
fields.each do |field_name, field_inst|
|
93
|
-
field_defn = field_inst.graphql_definition
|
94
|
-
type_defn.fields[field_defn.name] = field_defn
|
95
|
-
end
|
96
|
-
type_defn.metadata[:type_class] = self
|
97
|
-
if respond_to?(:resolve_type)
|
98
|
-
type_defn.resolve_type = method(:resolve_type)
|
99
|
-
end
|
100
|
-
type_defn
|
101
|
-
end
|
102
|
-
|
103
101
|
def kind
|
104
102
|
GraphQL::TypeKinds::INTERFACE
|
105
103
|
end
|
106
|
-
|
107
|
-
protected
|
108
|
-
|
109
|
-
def own_interfaces
|
110
|
-
@own_interfaces ||= []
|
111
|
-
end
|
112
|
-
|
113
|
-
def interfaces
|
114
|
-
own_interfaces + (own_interfaces.map { |i| i.own_interfaces }).flatten
|
115
|
-
end
|
116
104
|
end
|
117
105
|
|
118
|
-
# Extend this _after_ `DefinitionMethods` is defined, so it will be used
|
119
|
-
extend GraphQL::Schema::Member::AcceptsDefinition
|
120
|
-
|
121
106
|
extend DefinitionMethods
|
122
107
|
|
123
108
|
def unwrap
|