graphql 1.9.18 → 1.13.24
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 +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/analyze_query.rb +7 -0
- data/lib/graphql/analysis/ast/field_usage.rb +29 -2
- data/lib/graphql/analysis/ast/query_complexity.rb +174 -67
- data/lib/graphql/analysis/ast/visitor.rb +16 -7
- data/lib/graphql/analysis/ast.rb +21 -11
- data/lib/graphql/argument.rb +8 -36
- data/lib/graphql/backtrace/inspect_result.rb +0 -1
- data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
- data/lib/graphql/backtrace/table.rb +44 -5
- data/lib/graphql/backtrace/traced_error.rb +0 -1
- data/lib/graphql/backtrace/tracer.rb +40 -9
- data/lib/graphql/backtrace.rb +28 -19
- data/lib/graphql/backwards_compatibility.rb +2 -1
- data/lib/graphql/base_type.rb +10 -4
- data/lib/graphql/boolean_type.rb +1 -1
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +2 -2
- data/lib/graphql/compatibility/execution_specification.rb +1 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +2 -0
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +5 -9
- data/lib/graphql/compatibility/query_parser_specification.rb +2 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +2 -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/date_encoding_error.rb +16 -0
- data/lib/graphql/define/assign_enum_value.rb +1 -1
- data/lib/graphql/define/assign_global_id_field.rb +2 -2
- data/lib/graphql/define/assign_object_field.rb +1 -1
- data/lib/graphql/define/defined_object_proxy.rb +5 -8
- data/lib/graphql/define/instance_definable.rb +60 -110
- data/lib/graphql/define/type_definer.rb +5 -5
- data/lib/graphql/deprecated_dsl.rb +18 -5
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/directive/deprecated_directive.rb +1 -12
- data/lib/graphql/directive/include_directive.rb +1 -1
- data/lib/graphql/directive/skip_directive.rb +1 -1
- data/lib/graphql/directive.rb +9 -6
- data/lib/graphql/enum_type.rb +14 -74
- data/lib/graphql/execution/directive_checks.rb +2 -2
- data/lib/graphql/execution/errors.rb +110 -8
- data/lib/graphql/execution/execute.rb +8 -1
- 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 +721 -386
- data/lib/graphql/execution/interpreter.rb +42 -19
- 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 +39 -114
- data/lib/graphql/execution/multiplex.rb +50 -25
- data/lib/graphql/field.rb +15 -119
- data/lib/graphql/filter.rb +1 -1
- data/lib/graphql/float_type.rb +1 -1
- data/lib/graphql/function.rb +5 -30
- data/lib/graphql/id_type.rb +1 -1
- data/lib/graphql/input_object_type.rb +9 -25
- data/lib/graphql/int_type.rb +1 -1
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +18 -2
- data/lib/graphql/interface_type.rb +10 -24
- data/lib/graphql/internal_representation/document.rb +2 -2
- data/lib/graphql/internal_representation/rewrite.rb +1 -1
- data/lib/graphql/internal_representation/scope.rb +2 -2
- data/lib/graphql/internal_representation/visit.rb +2 -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 +12 -6
- data/lib/graphql/introspection/entry_points.rb +9 -9
- 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 +12 -12
- 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 +116 -63
- data/lib/graphql/language/lexer.rb +53 -27
- data/lib/graphql/language/lexer.rl +5 -3
- data/lib/graphql/language/nodes.rb +67 -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/non_null_type.rb +0 -10
- data/lib/graphql/object_type.rb +47 -58
- 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 +160 -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/arguments.rb +6 -4
- data/lib/graphql/query/arguments_cache.rb +1 -2
- data/lib/graphql/query/context.rb +52 -7
- data/lib/graphql/query/executor.rb +0 -1
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +32 -6
- data/lib/graphql/query/literal_input.rb +31 -11
- data/lib/graphql/query/null_context.rb +24 -8
- data/lib/graphql/query/serial_execution/field_resolution.rb +1 -1
- data/lib/graphql/query/serial_execution.rb +1 -0
- data/lib/graphql/query/validation_pipeline.rb +6 -4
- data/lib/graphql/query/variable_validation_error.rb +3 -3
- data/lib/graphql/query/variables.rb +50 -10
- data/lib/graphql/query.rb +77 -18
- data/lib/graphql/railtie.rb +9 -1
- data/lib/graphql/rake_task/validate.rb +3 -0
- data/lib/graphql/rake_task.rb +12 -9
- data/lib/graphql/relay/array_connection.rb +10 -12
- data/lib/graphql/relay/base_connection.rb +30 -13
- data/lib/graphql/relay/connection_instrumentation.rb +4 -4
- data/lib/graphql/relay/connection_type.rb +18 -4
- data/lib/graphql/relay/edge_type.rb +1 -0
- data/lib/graphql/relay/edges_instrumentation.rb +1 -2
- data/lib/graphql/relay/global_id_resolve.rb +1 -2
- data/lib/graphql/relay/mutation.rb +3 -87
- data/lib/graphql/relay/node.rb +3 -0
- data/lib/graphql/relay/page_info.rb +1 -1
- data/lib/graphql/relay/range_add.rb +27 -9
- data/lib/graphql/relay/relation_connection.rb +8 -10
- data/lib/graphql/relay/type_extensions.rb +2 -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/scalar_type.rb +18 -60
- data/lib/graphql/schema/addition.rb +247 -0
- data/lib/graphql/schema/argument.rb +274 -18
- 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 +320 -219
- data/lib/graphql/schema/built_in_types.rb +5 -5
- data/lib/graphql/schema/default_type_error.rb +2 -0
- 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 +130 -6
- data/lib/graphql/schema/enum.rb +121 -12
- data/lib/graphql/schema/enum_value.rb +24 -7
- 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 +465 -181
- 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 +172 -37
- data/lib/graphql/schema/interface.rb +39 -25
- data/lib/graphql/schema/introspection_system.rb +106 -38
- data/lib/graphql/schema/late_bound_type.rb +3 -2
- data/lib/graphql/schema/list.rb +65 -1
- data/lib/graphql/schema/loader.rb +145 -102
- data/lib/graphql/schema/member/accepts_definition.rb +15 -3
- data/lib/graphql/schema/member/base_dsl_methods.rb +34 -28
- data/lib/graphql/schema/member/build_type.rb +19 -8
- data/lib/graphql/schema/member/cached_graphql_definition.rb +34 -2
- data/lib/graphql/schema/member/has_arguments.rb +206 -13
- 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 +97 -32
- data/lib/graphql/schema/member/has_interfaces.rb +100 -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 +0 -1
- 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 -0
- data/lib/graphql/schema/middleware_chain.rb +1 -1
- data/lib/graphql/schema/mutation.rb +4 -0
- data/lib/graphql/schema/non_null.rb +37 -1
- data/lib/graphql/schema/object.rb +51 -38
- data/lib/graphql/schema/possible_types.rb +9 -4
- data/lib/graphql/schema/printer.rb +16 -35
- data/lib/graphql/schema/relay_classic_mutation.rb +40 -4
- 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 +43 -3
- data/lib/graphql/schema/subscription.rb +57 -21
- data/lib/graphql/schema/timeout.rb +29 -15
- data/lib/graphql/schema/timeout_middleware.rb +3 -1
- data/lib/graphql/schema/traversal.rb +2 -2
- data/lib/graphql/schema/type_expression.rb +21 -13
- data/lib/graphql/schema/type_membership.rb +19 -5
- data/lib/graphql/schema/union.rb +44 -3
- data/lib/graphql/schema/unique_within_type.rb +1 -2
- data/lib/graphql/schema/validation.rb +14 -4
- 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 +193 -34
- data/lib/graphql/schema.rb +882 -247
- data/lib/graphql/static_validation/all_rules.rb +2 -0
- data/lib/graphql/static_validation/base_visitor.rb +17 -10
- 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 +2 -2
- 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 +43 -9
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/string_encoding_error.rb +13 -3
- data/lib/graphql/string_type.rb +1 -1
- 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 +21 -0
- data/lib/graphql/subscriptions/event.rb +84 -30
- data/lib/graphql/subscriptions/instrumentation.rb +10 -6
- data/lib/graphql/subscriptions/serialize.rb +53 -6
- data/lib/graphql/subscriptions/subscription_root.rb +15 -5
- data/lib/graphql/subscriptions.rb +117 -49
- 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 +32 -15
- 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 +66 -10
- 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/skylight_tracing.rb +9 -1
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +15 -35
- 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 +174 -0
- data/lib/graphql/types/relay/default_relay.rb +31 -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 +15 -0
- data/lib/graphql/types/relay/node_field.rb +3 -22
- data/lib/graphql/types/relay/nodes_field.rb +16 -18
- 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 -3
- data/lib/graphql/types/string.rb +8 -2
- data/lib/graphql/unauthorized_error.rb +2 -2
- data/lib/graphql/union_type.rb +5 -25
- data/lib/graphql/unresolved_type_error.rb +2 -2
- data/lib/graphql/upgrader/member.rb +1 -0
- data/lib/graphql/upgrader/schema.rb +1 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +87 -31
- data/readme.md +3 -6
- metadata +126 -124
- data/lib/graphql/execution/interpreter/hash_response.rb +0 -46
- data/lib/graphql/literal_validation_error.rb +0 -6
- 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
|
@@ -5,23 +5,17 @@ module GraphQL
|
|
|
5
5
|
class Schema
|
|
6
6
|
module BuildFromDefinition
|
|
7
7
|
class << self
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
# @see {Schema.from_definition}
|
|
9
|
+
def from_definition(definition_string, parser: GraphQL.default_parser, **kwargs)
|
|
10
|
+
from_document(parser.parse(definition_string), **kwargs)
|
|
11
11
|
end
|
|
12
|
-
end
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
def from_definition_path(definition_path, parser: GraphQL.default_parser, **kwargs)
|
|
14
|
+
from_document(parser.parse_file(definition_path), **kwargs)
|
|
15
|
+
end
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def self.call(type, field, obj, args, ctx)
|
|
20
|
-
if field.arguments.any?
|
|
21
|
-
obj.public_send(field.name, args, ctx)
|
|
22
|
-
else
|
|
23
|
-
obj.public_send(field.name)
|
|
24
|
-
end
|
|
17
|
+
def from_document(document, default_resolve:, using: {}, relay: false)
|
|
18
|
+
Builder.build(document, default_resolve: default_resolve || {}, relay: relay, using: using)
|
|
25
19
|
end
|
|
26
20
|
end
|
|
27
21
|
|
|
@@ -29,43 +23,64 @@ module GraphQL
|
|
|
29
23
|
module Builder
|
|
30
24
|
extend self
|
|
31
25
|
|
|
32
|
-
def build(document, default_resolve:
|
|
26
|
+
def build(document, default_resolve:, using: {}, relay:)
|
|
33
27
|
raise InvalidDocumentError.new('Must provide a document ast.') if !document || !document.is_a?(GraphQL::Language::Nodes::Document)
|
|
34
28
|
|
|
35
29
|
if default_resolve.is_a?(Hash)
|
|
36
30
|
default_resolve = ResolveMap.new(default_resolve)
|
|
37
31
|
end
|
|
38
32
|
|
|
39
|
-
|
|
33
|
+
schema_defns = document.definitions.select { |d| d.is_a?(GraphQL::Language::Nodes::SchemaDefinition) }
|
|
34
|
+
if schema_defns.size > 1
|
|
35
|
+
raise InvalidDocumentError.new('Must provide only one schema definition.')
|
|
36
|
+
end
|
|
37
|
+
schema_definition = schema_defns.first
|
|
40
38
|
types = {}
|
|
41
|
-
types.merge!(GraphQL::Schema::BUILT_IN_TYPES)
|
|
42
39
|
directives = {}
|
|
43
|
-
type_resolver = ->(
|
|
40
|
+
type_resolver = build_resolve_type(types, directives, ->(type_name) { types[type_name] ||= Schema::LateBoundType.new(type_name)})
|
|
41
|
+
# Make a different type resolver because we need to coerce directive arguments
|
|
42
|
+
# _while_ building the schema.
|
|
43
|
+
# It will dig for a type if it encounters a custom type. This could be a problem if there are cycles.
|
|
44
|
+
directive_type_resolver = nil
|
|
45
|
+
directive_type_resolver = build_resolve_type(types, directives, ->(type_name) {
|
|
46
|
+
types[type_name] ||= begin
|
|
47
|
+
defn = document.definitions.find { |d| d.respond_to?(:name) && d.name == type_name }
|
|
48
|
+
if defn
|
|
49
|
+
build_definition_from_node(defn, directive_type_resolver, default_resolve)
|
|
50
|
+
elsif (built_in_defn = GraphQL::Schema::BUILT_IN_TYPES[type_name])
|
|
51
|
+
built_in_defn
|
|
52
|
+
else
|
|
53
|
+
raise "No definition for #{type_name.inspect} found in schema document or built-in types. Add a definition for it or remove it."
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
})
|
|
44
57
|
|
|
45
58
|
document.definitions.each do |definition|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
raise InvalidDocumentError.new('Must provide only one schema definition.') if schema_definition
|
|
49
|
-
schema_definition = definition
|
|
50
|
-
when GraphQL::Language::Nodes::EnumTypeDefinition
|
|
51
|
-
types[definition.name] = build_enum_type(definition, type_resolver)
|
|
52
|
-
when GraphQL::Language::Nodes::ObjectTypeDefinition
|
|
53
|
-
types[definition.name] = build_object_type(definition, type_resolver, default_resolve: default_resolve)
|
|
54
|
-
when GraphQL::Language::Nodes::InterfaceTypeDefinition
|
|
55
|
-
types[definition.name] = build_interface_type(definition, type_resolver)
|
|
56
|
-
when GraphQL::Language::Nodes::UnionTypeDefinition
|
|
57
|
-
types[definition.name] = build_union_type(definition, type_resolver)
|
|
58
|
-
when GraphQL::Language::Nodes::ScalarTypeDefinition
|
|
59
|
-
types[definition.name] = build_scalar_type(definition, type_resolver, default_resolve: default_resolve)
|
|
60
|
-
when GraphQL::Language::Nodes::InputObjectTypeDefinition
|
|
61
|
-
types[definition.name] = build_input_object_type(definition, type_resolver)
|
|
62
|
-
when GraphQL::Language::Nodes::DirectiveDefinition
|
|
63
|
-
directives[definition.name] = build_directive(definition, type_resolver)
|
|
59
|
+
if definition.is_a?(GraphQL::Language::Nodes::DirectiveDefinition)
|
|
60
|
+
directives[definition.name] = build_directive(definition, directive_type_resolver)
|
|
64
61
|
end
|
|
65
62
|
end
|
|
66
63
|
|
|
67
64
|
directives = GraphQL::Schema.default_directives.merge(directives)
|
|
68
65
|
|
|
66
|
+
# In case any directives referenced built-in types for their arguments:
|
|
67
|
+
replace_late_bound_types_with_built_in(types)
|
|
68
|
+
|
|
69
|
+
document.definitions.each do |definition|
|
|
70
|
+
case definition
|
|
71
|
+
when GraphQL::Language::Nodes::SchemaDefinition, GraphQL::Language::Nodes::DirectiveDefinition
|
|
72
|
+
nil # already handled
|
|
73
|
+
else
|
|
74
|
+
# It's possible that this was already loaded by the directives
|
|
75
|
+
prev_type = types[definition.name]
|
|
76
|
+
if prev_type.nil? || prev_type.is_a?(Schema::LateBoundType)
|
|
77
|
+
types[definition.name] = build_definition_from_node(definition, type_resolver, default_resolve)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
replace_late_bound_types_with_built_in(types)
|
|
83
|
+
|
|
69
84
|
if schema_definition
|
|
70
85
|
if schema_definition.query
|
|
71
86
|
raise InvalidDocumentError.new("Specified query type \"#{schema_definition.query}\" not found in document.") unless types[schema_definition.query]
|
|
@@ -89,54 +104,157 @@ module GraphQL
|
|
|
89
104
|
|
|
90
105
|
raise InvalidDocumentError.new('Must provide schema definition with query type or a type named Query.') unless query_root_type
|
|
91
106
|
|
|
92
|
-
|
|
93
|
-
|
|
107
|
+
Class.new(GraphQL::Schema) do
|
|
108
|
+
begin
|
|
109
|
+
# Add these first so that there's some chance of resolving late-bound types
|
|
110
|
+
orphan_types types.values
|
|
111
|
+
query query_root_type
|
|
112
|
+
mutation mutation_root_type
|
|
113
|
+
subscription subscription_root_type
|
|
114
|
+
rescue Schema::UnresolvedLateBoundTypeError => err
|
|
115
|
+
type_name = err.type.name
|
|
116
|
+
err_backtrace = err.backtrace
|
|
117
|
+
raise InvalidDocumentError, "Type \"#{type_name}\" not found in document.", err_backtrace
|
|
118
|
+
end
|
|
94
119
|
|
|
95
|
-
query query_root_type
|
|
96
|
-
mutation mutation_root_type
|
|
97
|
-
subscription subscription_root_type
|
|
98
|
-
orphan_types types.values
|
|
99
120
|
if default_resolve.respond_to?(:resolve_type)
|
|
100
|
-
resolve_type(
|
|
121
|
+
def self.resolve_type(*args)
|
|
122
|
+
self.definition_default_resolve.resolve_type(*args)
|
|
123
|
+
end
|
|
101
124
|
else
|
|
102
|
-
resolve_type(
|
|
125
|
+
def self.resolve_type(*args)
|
|
126
|
+
NullResolveType.call(*args)
|
|
127
|
+
end
|
|
103
128
|
end
|
|
104
129
|
|
|
105
130
|
directives directives.values
|
|
106
|
-
end
|
|
107
131
|
|
|
108
|
-
|
|
132
|
+
if schema_definition
|
|
133
|
+
ast_node(schema_definition)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
using.each do |plugin, options|
|
|
137
|
+
if options
|
|
138
|
+
use(plugin, **options)
|
|
139
|
+
else
|
|
140
|
+
use(plugin)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Empty `orphan_types` -- this will make unreachable types ... unreachable.
|
|
145
|
+
own_orphan_types.clear
|
|
146
|
+
|
|
147
|
+
class << self
|
|
148
|
+
attr_accessor :definition_default_resolve
|
|
149
|
+
end
|
|
109
150
|
|
|
110
|
-
|
|
151
|
+
self.definition_default_resolve = default_resolve
|
|
152
|
+
|
|
153
|
+
def definition_default_resolve
|
|
154
|
+
self.class.definition_default_resolve
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def self.inherited(child_class)
|
|
158
|
+
child_class.definition_default_resolve = self.definition_default_resolve
|
|
159
|
+
end
|
|
160
|
+
end
|
|
111
161
|
end
|
|
112
162
|
|
|
113
163
|
NullResolveType = ->(type, obj, ctx) {
|
|
114
164
|
raise(GraphQL::RequiredImplementationMissingError, "Generated Schema cannot use Interface or Union types for execution. Implement resolve_type on your resolver.")
|
|
115
165
|
}
|
|
116
166
|
|
|
117
|
-
|
|
167
|
+
def build_definition_from_node(definition, type_resolver, default_resolve)
|
|
168
|
+
case definition
|
|
169
|
+
when GraphQL::Language::Nodes::EnumTypeDefinition
|
|
170
|
+
build_enum_type(definition, type_resolver)
|
|
171
|
+
when GraphQL::Language::Nodes::ObjectTypeDefinition
|
|
172
|
+
build_object_type(definition, type_resolver)
|
|
173
|
+
when GraphQL::Language::Nodes::InterfaceTypeDefinition
|
|
174
|
+
build_interface_type(definition, type_resolver)
|
|
175
|
+
when GraphQL::Language::Nodes::UnionTypeDefinition
|
|
176
|
+
build_union_type(definition, type_resolver)
|
|
177
|
+
when GraphQL::Language::Nodes::ScalarTypeDefinition
|
|
178
|
+
build_scalar_type(definition, type_resolver, default_resolve: default_resolve)
|
|
179
|
+
when GraphQL::Language::Nodes::InputObjectTypeDefinition
|
|
180
|
+
build_input_object_type(definition, type_resolver)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
118
183
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
184
|
+
# Modify `types`, replacing any late-bound references to built-in types
|
|
185
|
+
# with their actual definitions.
|
|
186
|
+
#
|
|
187
|
+
# (Schema definitions are allowed to reference those built-ins without redefining them.)
|
|
188
|
+
# @return void
|
|
189
|
+
def replace_late_bound_types_with_built_in(types)
|
|
190
|
+
GraphQL::Schema::BUILT_IN_TYPES.each do |scalar_name, built_in_scalar|
|
|
191
|
+
existing_type = types[scalar_name]
|
|
192
|
+
if existing_type.is_a?(GraphQL::Schema::LateBoundType)
|
|
193
|
+
types[scalar_name] = built_in_scalar
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
130
197
|
|
|
131
|
-
|
|
198
|
+
def build_directives(definition, ast_node, type_resolver)
|
|
199
|
+
dirs = prepare_directives(ast_node, type_resolver)
|
|
200
|
+
dirs.each do |dir_class, options|
|
|
201
|
+
definition.directive(dir_class, **options)
|
|
202
|
+
end
|
|
203
|
+
end
|
|
132
204
|
|
|
133
|
-
|
|
205
|
+
def prepare_directives(ast_node, type_resolver)
|
|
206
|
+
dirs = {}
|
|
207
|
+
ast_node.directives.each do |dir_node|
|
|
208
|
+
if dir_node.name == "deprecated"
|
|
209
|
+
# This is handled using `deprecation_reason`
|
|
210
|
+
next
|
|
211
|
+
else
|
|
212
|
+
dir_class = type_resolver.call(dir_node.name)
|
|
213
|
+
if dir_class.nil?
|
|
214
|
+
raise ArgumentError, "No definition for @#{dir_node.name} on #{ast_node.name} at #{ast_node.line}:#{ast_node.col}"
|
|
215
|
+
end
|
|
216
|
+
options = args_to_kwargs(dir_class, dir_node)
|
|
217
|
+
dirs[dir_class] = options
|
|
134
218
|
end
|
|
135
|
-
|
|
219
|
+
end
|
|
220
|
+
dirs
|
|
221
|
+
end
|
|
136
222
|
|
|
137
|
-
|
|
223
|
+
def args_to_kwargs(arg_owner, node)
|
|
224
|
+
if node.respond_to?(:arguments)
|
|
225
|
+
kwargs = {}
|
|
226
|
+
node.arguments.each do |arg_node|
|
|
227
|
+
arg_defn = arg_owner.get_argument(arg_node.name)
|
|
228
|
+
kwargs[arg_defn.keyword] = args_to_kwargs(arg_defn.type.unwrap, arg_node.value)
|
|
229
|
+
end
|
|
230
|
+
kwargs
|
|
231
|
+
elsif node.is_a?(Array)
|
|
232
|
+
node.map { |n| args_to_kwargs(arg_owner, n) }
|
|
233
|
+
elsif node.is_a?(Language::Nodes::Enum)
|
|
234
|
+
node.name
|
|
235
|
+
else
|
|
236
|
+
# scalar
|
|
237
|
+
node
|
|
238
|
+
end
|
|
239
|
+
end
|
|
138
240
|
|
|
139
|
-
|
|
241
|
+
def build_enum_type(enum_type_definition, type_resolver)
|
|
242
|
+
builder = self
|
|
243
|
+
Class.new(GraphQL::Schema::Enum) do
|
|
244
|
+
graphql_name(enum_type_definition.name)
|
|
245
|
+
builder.build_directives(self, enum_type_definition, type_resolver)
|
|
246
|
+
description(enum_type_definition.description)
|
|
247
|
+
ast_node(enum_type_definition)
|
|
248
|
+
enum_type_definition.values.each do |enum_value_definition|
|
|
249
|
+
value(enum_value_definition.name,
|
|
250
|
+
value: enum_value_definition.name,
|
|
251
|
+
deprecation_reason: builder.build_deprecation_reason(enum_value_definition.directives),
|
|
252
|
+
description: enum_value_definition.description,
|
|
253
|
+
directives: builder.prepare_directives(enum_value_definition, type_resolver),
|
|
254
|
+
ast_node: enum_value_definition,
|
|
255
|
+
)
|
|
256
|
+
end
|
|
257
|
+
end
|
|
140
258
|
end
|
|
141
259
|
|
|
142
260
|
def build_deprecation_reason(directives)
|
|
@@ -144,69 +262,72 @@ module GraphQL
|
|
|
144
262
|
return unless deprecated_directive
|
|
145
263
|
|
|
146
264
|
reason = deprecated_directive.arguments.find{ |a| a.name == 'reason' }
|
|
147
|
-
return GraphQL::Directive::DEFAULT_DEPRECATION_REASON unless reason
|
|
265
|
+
return GraphQL::Schema::Directive::DEFAULT_DEPRECATION_REASON unless reason
|
|
148
266
|
|
|
149
267
|
reason.value
|
|
150
268
|
end
|
|
151
269
|
|
|
152
270
|
def build_scalar_type(scalar_type_definition, type_resolver, default_resolve:)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
271
|
+
builder = self
|
|
272
|
+
Class.new(GraphQL::Schema::Scalar) do
|
|
273
|
+
graphql_name(scalar_type_definition.name)
|
|
274
|
+
description(scalar_type_definition.description)
|
|
275
|
+
ast_node(scalar_type_definition)
|
|
276
|
+
builder.build_directives(self, scalar_type_definition, type_resolver)
|
|
277
|
+
|
|
278
|
+
if default_resolve.respond_to?(:coerce_input)
|
|
279
|
+
# Put these method definitions in another method to avoid retaining `type_resolve`
|
|
280
|
+
# from this method's bindiing
|
|
281
|
+
builder.build_scalar_type_coerce_method(self, :coerce_input, default_resolve)
|
|
282
|
+
builder.build_scalar_type_coerce_method(self, :coerce_result, default_resolve)
|
|
283
|
+
end
|
|
166
284
|
end
|
|
285
|
+
end
|
|
167
286
|
|
|
168
|
-
|
|
287
|
+
def build_scalar_type_coerce_method(scalar_class, method_name, default_definition_resolve)
|
|
288
|
+
scalar_class.define_singleton_method(method_name) do |val, ctx|
|
|
289
|
+
default_definition_resolve.public_send(method_name, self, val, ctx)
|
|
290
|
+
end
|
|
169
291
|
end
|
|
170
292
|
|
|
171
293
|
def build_union_type(union_type_definition, type_resolver)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
294
|
+
builder = self
|
|
295
|
+
Class.new(GraphQL::Schema::Union) do
|
|
296
|
+
graphql_name(union_type_definition.name)
|
|
297
|
+
description(union_type_definition.description)
|
|
298
|
+
possible_types(*union_type_definition.types.map { |type_name| type_resolver.call(type_name) })
|
|
299
|
+
ast_node(union_type_definition)
|
|
300
|
+
builder.build_directives(self, union_type_definition, type_resolver)
|
|
301
|
+
end
|
|
302
|
+
end
|
|
177
303
|
|
|
178
|
-
|
|
304
|
+
def build_object_type(object_type_definition, type_resolver)
|
|
305
|
+
builder = self
|
|
179
306
|
|
|
180
|
-
|
|
181
|
-
|
|
307
|
+
Class.new(GraphQL::Schema::Object) do
|
|
308
|
+
graphql_name(object_type_definition.name)
|
|
309
|
+
description(object_type_definition.description)
|
|
310
|
+
ast_node(object_type_definition)
|
|
311
|
+
builder.build_directives(self, object_type_definition, type_resolver)
|
|
182
312
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
interfaces: object_type_definition.interfaces.map{ |interface_name| type_resolver.call(interface_name) },
|
|
190
|
-
}
|
|
191
|
-
obj_fields = Hash[build_fields(object_type_definition.fields, type_resolver, default_resolve: typed_resolve_fn)]
|
|
192
|
-
if obj_fields.any?
|
|
193
|
-
defns[:fields] = obj_fields
|
|
313
|
+
object_type_definition.interfaces.each do |interface_name|
|
|
314
|
+
interface_defn = type_resolver.call(interface_name)
|
|
315
|
+
implements(interface_defn)
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
builder.build_fields(self, object_type_definition.fields, type_resolver, default_resolve: true)
|
|
194
319
|
end
|
|
195
|
-
type_def = GraphQL::ObjectType.define(**defns)
|
|
196
|
-
type_def.ast_node = object_type_definition
|
|
197
|
-
type_def
|
|
198
320
|
end
|
|
199
321
|
|
|
200
322
|
def build_input_object_type(input_object_type_definition, type_resolver)
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
input
|
|
323
|
+
builder = self
|
|
324
|
+
Class.new(GraphQL::Schema::InputObject) do
|
|
325
|
+
graphql_name(input_object_type_definition.name)
|
|
326
|
+
description(input_object_type_definition.description)
|
|
327
|
+
ast_node(input_object_type_definition)
|
|
328
|
+
builder.build_directives(self, input_object_type_definition, type_resolver)
|
|
329
|
+
builder.build_arguments(self, input_object_type_definition.fields, type_resolver)
|
|
330
|
+
end
|
|
210
331
|
end
|
|
211
332
|
|
|
212
333
|
def build_default_value(default_value)
|
|
@@ -224,142 +345,122 @@ module GraphQL
|
|
|
224
345
|
end
|
|
225
346
|
end
|
|
226
347
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
348
|
+
NO_DEFAULT_VALUE = {}.freeze
|
|
349
|
+
|
|
350
|
+
def build_arguments(type_class, arguments, type_resolver)
|
|
351
|
+
builder = self
|
|
230
352
|
|
|
231
|
-
|
|
232
|
-
|
|
353
|
+
arguments.each do |argument_defn|
|
|
354
|
+
default_value_kwargs = if !argument_defn.default_value.nil?
|
|
355
|
+
{ default_value: builder.build_default_value(argument_defn.default_value) }
|
|
356
|
+
else
|
|
357
|
+
NO_DEFAULT_VALUE
|
|
233
358
|
end
|
|
234
359
|
|
|
235
|
-
argument
|
|
236
|
-
|
|
237
|
-
type: type_resolver.call(
|
|
238
|
-
|
|
360
|
+
type_class.argument(
|
|
361
|
+
argument_defn.name,
|
|
362
|
+
type: type_resolver.call(argument_defn.type),
|
|
363
|
+
required: false,
|
|
364
|
+
description: argument_defn.description,
|
|
365
|
+
deprecation_reason: builder.build_deprecation_reason(argument_defn.directives),
|
|
366
|
+
ast_node: argument_defn,
|
|
367
|
+
camelize: false,
|
|
239
368
|
method_access: false,
|
|
240
|
-
|
|
369
|
+
directives: prepare_directives(argument_defn, type_resolver),
|
|
370
|
+
**default_value_kwargs
|
|
241
371
|
)
|
|
242
|
-
|
|
243
|
-
argument.ast_node = input_argument
|
|
244
|
-
|
|
245
|
-
[
|
|
246
|
-
input_argument.name,
|
|
247
|
-
argument
|
|
248
|
-
]
|
|
249
372
|
end
|
|
250
373
|
end
|
|
251
374
|
|
|
252
375
|
def build_directive(directive_definition, type_resolver)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
locations
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if directive_args.any?
|
|
262
|
-
defn[:arguments] = directive_args
|
|
376
|
+
builder = self
|
|
377
|
+
Class.new(GraphQL::Schema::Directive) do
|
|
378
|
+
graphql_name(directive_definition.name)
|
|
379
|
+
description(directive_definition.description)
|
|
380
|
+
repeatable(directive_definition.repeatable)
|
|
381
|
+
locations(*directive_definition.locations.map { |location| location.name.to_sym })
|
|
382
|
+
ast_node(directive_definition)
|
|
383
|
+
builder.build_arguments(self, directive_definition.arguments, type_resolver)
|
|
263
384
|
end
|
|
264
|
-
|
|
265
|
-
directive = GraphQL::Directive.define(**defn)
|
|
266
|
-
directive.ast_node = directive_definition
|
|
267
|
-
|
|
268
|
-
directive
|
|
269
385
|
end
|
|
270
386
|
|
|
271
|
-
def
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
387
|
+
def build_interface_type(interface_type_definition, type_resolver)
|
|
388
|
+
builder = self
|
|
389
|
+
Module.new do
|
|
390
|
+
include GraphQL::Schema::Interface
|
|
391
|
+
graphql_name(interface_type_definition.name)
|
|
392
|
+
description(interface_type_definition.description)
|
|
393
|
+
interface_type_definition.interfaces.each do |interface_name|
|
|
394
|
+
"Implements: #{interface_type_definition} -> #{interface_name}"
|
|
395
|
+
interface_defn = type_resolver.call(interface_name)
|
|
396
|
+
implements(interface_defn)
|
|
277
397
|
end
|
|
398
|
+
ast_node(interface_type_definition)
|
|
399
|
+
builder.build_directives(self, interface_type_definition, type_resolver)
|
|
278
400
|
|
|
279
|
-
|
|
280
|
-
name: directive_argument.name,
|
|
281
|
-
type: type_resolver.call(directive_argument.type),
|
|
282
|
-
description: directive_argument.description,
|
|
283
|
-
method_access: false,
|
|
284
|
-
**kwargs,
|
|
285
|
-
)
|
|
286
|
-
|
|
287
|
-
argument.ast_node = directive_argument
|
|
288
|
-
|
|
289
|
-
[
|
|
290
|
-
directive_argument.name,
|
|
291
|
-
argument
|
|
292
|
-
]
|
|
401
|
+
builder.build_fields(self, interface_type_definition.fields, type_resolver, default_resolve: nil)
|
|
293
402
|
end
|
|
294
403
|
end
|
|
295
404
|
|
|
296
|
-
def
|
|
297
|
-
|
|
298
|
-
name: interface_type_definition.name,
|
|
299
|
-
description: interface_type_definition.description,
|
|
300
|
-
fields: Hash[build_fields(interface_type_definition.fields, type_resolver, default_resolve: nil)],
|
|
301
|
-
)
|
|
302
|
-
|
|
303
|
-
interface.ast_node = interface_type_definition
|
|
304
|
-
|
|
305
|
-
interface
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
def build_fields(field_definitions, type_resolver, default_resolve:)
|
|
309
|
-
field_definitions.map do |field_definition|
|
|
310
|
-
field_arguments = Hash[field_definition.arguments.map do |argument|
|
|
311
|
-
kwargs = {}
|
|
312
|
-
|
|
313
|
-
if !argument.default_value.nil?
|
|
314
|
-
kwargs[:default_value] = build_default_value(argument.default_value)
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
arg = GraphQL::Argument.define(
|
|
318
|
-
name: argument.name,
|
|
319
|
-
description: argument.description,
|
|
320
|
-
type: type_resolver.call(argument.type),
|
|
321
|
-
method_access: false,
|
|
322
|
-
**kwargs,
|
|
323
|
-
)
|
|
324
|
-
|
|
325
|
-
arg.ast_node = argument
|
|
326
|
-
|
|
327
|
-
[argument.name, arg]
|
|
328
|
-
end]
|
|
329
|
-
|
|
330
|
-
field = nil
|
|
405
|
+
def build_fields(owner, field_definitions, type_resolver, default_resolve:)
|
|
406
|
+
builder = self
|
|
331
407
|
|
|
332
|
-
|
|
333
|
-
|
|
408
|
+
field_definitions.each do |field_definition|
|
|
409
|
+
type_name = resolve_type_name(field_definition.type)
|
|
410
|
+
resolve_method_name = -"resolve_field_#{field_definition.name}"
|
|
411
|
+
schema_field_defn = owner.field(
|
|
412
|
+
field_definition.name,
|
|
334
413
|
description: field_definition.description,
|
|
335
414
|
type: type_resolver.call(field_definition.type),
|
|
336
|
-
|
|
415
|
+
null: true,
|
|
416
|
+
connection: type_name.end_with?("Connection"),
|
|
417
|
+
connection_extension: nil,
|
|
337
418
|
deprecation_reason: build_deprecation_reason(field_definition.directives),
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
field = GraphQL::Field.define(**defns)
|
|
419
|
+
ast_node: field_definition,
|
|
420
|
+
method_conflict_warning: false,
|
|
421
|
+
camelize: false,
|
|
422
|
+
directives: prepare_directives(field_definition, type_resolver),
|
|
423
|
+
resolver_method: resolve_method_name,
|
|
424
|
+
)
|
|
345
425
|
|
|
346
|
-
|
|
426
|
+
builder.build_arguments(schema_field_defn, field_definition.arguments, type_resolver)
|
|
347
427
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
428
|
+
# Don't do this for interfaces
|
|
429
|
+
if default_resolve
|
|
430
|
+
define_field_resolve_method(owner, resolve_method_name, field_definition.name)
|
|
431
|
+
end
|
|
351
432
|
end
|
|
352
433
|
end
|
|
353
434
|
|
|
354
|
-
def
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
435
|
+
def define_field_resolve_method(owner, method_name, field_name)
|
|
436
|
+
owner.define_method(method_name) { |**args|
|
|
437
|
+
field_instance = self.class.get_field(field_name)
|
|
438
|
+
context.schema.definition_default_resolve.call(self.class, field_instance, object, args, context)
|
|
439
|
+
}
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
def build_resolve_type(lookup_hash, directives, missing_type_handler)
|
|
443
|
+
resolve_type_proc = nil
|
|
444
|
+
resolve_type_proc = ->(ast_node) {
|
|
445
|
+
case ast_node
|
|
446
|
+
when GraphQL::Language::Nodes::TypeName
|
|
447
|
+
type_name = ast_node.name
|
|
448
|
+
if lookup_hash.key?(type_name)
|
|
449
|
+
lookup_hash[type_name]
|
|
450
|
+
else
|
|
451
|
+
missing_type_handler.call(type_name)
|
|
452
|
+
end
|
|
453
|
+
when GraphQL::Language::Nodes::NonNullType
|
|
454
|
+
resolve_type_proc.call(ast_node.of_type).to_non_null_type
|
|
455
|
+
when GraphQL::Language::Nodes::ListType
|
|
456
|
+
resolve_type_proc.call(ast_node.of_type).to_list_type
|
|
457
|
+
when String
|
|
458
|
+
directives[ast_node]
|
|
459
|
+
else
|
|
460
|
+
raise "Unexpected ast_node: #{ast_node.inspect}"
|
|
359
461
|
end
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
type
|
|
462
|
+
}
|
|
463
|
+
resolve_type_proc
|
|
363
464
|
end
|
|
364
465
|
|
|
365
466
|
def resolve_type_name(type)
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
module GraphQL
|
|
3
3
|
class Schema
|
|
4
4
|
BUILT_IN_TYPES = {
|
|
5
|
-
"Int" =>
|
|
6
|
-
"String" =>
|
|
7
|
-
"Float" =>
|
|
8
|
-
"Boolean" =>
|
|
9
|
-
"ID" =>
|
|
5
|
+
"Int" => GraphQL::Types::Int,
|
|
6
|
+
"String" => GraphQL::Types::String,
|
|
7
|
+
"Float" => GraphQL::Types::Float,
|
|
8
|
+
"Boolean" => GraphQL::Types::Boolean,
|
|
9
|
+
"ID" => GraphQL::Types::ID,
|
|
10
10
|
}
|
|
11
11
|
end
|
|
12
12
|
end
|