graphql 1.10.2 → 2.0.21
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 +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 +24 -33
- 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 +30 -1
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +125 -117
- data/lib/graphql/analysis/ast/query_depth.rb +0 -1
- data/lib/graphql/analysis/ast/visitor.rb +52 -36
- data/lib/graphql/analysis/ast.rb +7 -8
- data/lib/graphql/analysis.rb +0 -7
- data/lib/graphql/backtrace/inspect_result.rb +0 -1
- data/lib/graphql/backtrace/table.rb +31 -18
- data/lib/graphql/backtrace/trace.rb +96 -0
- data/lib/graphql/backtrace/traced_error.rb +0 -1
- data/lib/graphql/backtrace/tracer.rb +39 -9
- data/lib/graphql/backtrace.rb +26 -18
- 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/errors.rb +77 -44
- 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 +104 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +18 -0
- data/lib/graphql/execution/interpreter/resolve.rb +62 -24
- data/lib/graphql/execution/interpreter/runtime.rb +826 -464
- data/lib/graphql/execution/interpreter.rb +206 -68
- data/lib/graphql/execution/lazy.rb +11 -21
- data/lib/graphql/execution/lookahead.rb +55 -136
- data/lib/graphql/execution/multiplex.rb +6 -162
- data/lib/graphql/execution.rb +11 -4
- data/lib/graphql/filter.rb +7 -2
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +18 -2
- 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 +4 -17
- 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 +15 -3
- data/lib/graphql/introspection/introspection_query.rb +6 -92
- data/lib/graphql/introspection/schema_type.rb +11 -6
- data/lib/graphql/introspection/type_type.rb +31 -14
- 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/document_from_schema_definition.rb +96 -44
- data/lib/graphql/language/lexer.rb +216 -1462
- data/lib/graphql/language/nodes.rb +126 -129
- data/lib/graphql/language/parser.rb +997 -933
- data/lib/graphql/language/parser.y +148 -118
- 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 +192 -84
- data/lib/graphql/language.rb +2 -0
- data/lib/graphql/name_validator.rb +2 -7
- data/lib/graphql/pagination/active_record_relation_connection.rb +45 -3
- data/lib/graphql/pagination/array_connection.rb +6 -4
- data/lib/graphql/pagination/connection.rb +105 -23
- data/lib/graphql/pagination/connections.rb +62 -35
- data/lib/graphql/pagination/relation_connection.rb +88 -36
- data/lib/graphql/parse_error.rb +0 -1
- data/lib/graphql/query/context.rb +203 -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 +22 -9
- 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 +36 -12
- data/lib/graphql/query.rb +92 -44
- data/lib/graphql/railtie.rb +6 -102
- data/lib/graphql/rake_task/validate.rb +1 -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 +250 -46
- data/lib/graphql/schema/base_64_encoder.rb +2 -0
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +3 -1
- data/lib/graphql/schema/build_from_definition.rb +243 -89
- data/lib/graphql/schema/directive/deprecated.rb +1 -1
- 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 +1 -1
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/skip.rb +1 -1
- data/lib/graphql/schema/directive/transform.rb +14 -2
- data/lib/graphql/schema/directive.rb +108 -20
- data/lib/graphql/schema/enum.rb +105 -44
- data/lib/graphql/schema/enum_value.rb +15 -25
- data/lib/graphql/schema/field/connection_extension.rb +50 -30
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +476 -331
- data/lib/graphql/schema/field_extension.rb +86 -2
- data/lib/graphql/schema/find_inherited_value.rb +6 -8
- data/lib/graphql/schema/finder.rb +5 -5
- data/lib/graphql/schema/input_object.rb +133 -121
- data/lib/graphql/schema/interface.rb +17 -45
- data/lib/graphql/schema/introspection_system.rb +3 -8
- data/lib/graphql/schema/late_bound_type.rb +8 -2
- data/lib/graphql/schema/list.rb +25 -8
- data/lib/graphql/schema/loader.rb +139 -103
- data/lib/graphql/schema/member/base_dsl_methods.rb +29 -35
- data/lib/graphql/schema/member/build_type.rb +19 -14
- data/lib/graphql/schema/member/has_arguments.rb +310 -26
- data/lib/graphql/schema/member/has_ast_node.rb +16 -1
- data/lib/graphql/schema/member/has_deprecation_reason.rb +24 -0
- data/lib/graphql/schema/member/has_directives.rb +118 -0
- data/lib/graphql/schema/member/has_fields.rb +164 -42
- data/lib/graphql/schema/member/has_interfaces.rb +129 -0
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +15 -0
- data/lib/graphql/schema/member/has_validators.rb +57 -0
- data/lib/graphql/schema/member/relay_shortcuts.rb +47 -2
- data/lib/graphql/schema/member/type_system_helpers.rb +20 -3
- data/lib/graphql/schema/member/validates_input.rb +3 -3
- data/lib/graphql/schema/member.rb +6 -6
- data/lib/graphql/schema/mutation.rb +4 -9
- data/lib/graphql/schema/non_null.rb +12 -7
- data/lib/graphql/schema/object.rb +35 -69
- data/lib/graphql/schema/printer.rb +16 -34
- data/lib/graphql/schema/relay_classic_mutation.rb +90 -43
- data/lib/graphql/schema/resolver/has_payload_type.rb +51 -11
- data/lib/graphql/schema/resolver.rb +144 -79
- data/lib/graphql/schema/scalar.rb +27 -18
- data/lib/graphql/schema/subscription.rb +55 -26
- data/lib/graphql/schema/timeout.rb +45 -35
- data/lib/graphql/schema/type_expression.rb +1 -1
- data/lib/graphql/schema/type_membership.rb +21 -4
- data/lib/graphql/schema/union.rb +48 -13
- 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 +185 -32
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +471 -1116
- data/lib/graphql/static_validation/all_rules.rb +3 -0
- data/lib/graphql/static_validation/base_visitor.rb +13 -27
- 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 +69 -26
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +44 -87
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +22 -6
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +28 -22
- 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 +13 -13
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +92 -49
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +25 -4
- 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 +6 -7
- 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 +9 -10
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +14 -8
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +4 -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 +32 -20
- 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 +126 -19
- 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 +81 -35
- data/lib/graphql/subscriptions/instrumentation.rb +0 -52
- data/lib/graphql/subscriptions/serialize.rb +53 -6
- data/lib/graphql/subscriptions.rb +113 -58
- data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +8 -21
- data/lib/graphql/tracing/appoptics_trace.rb +231 -0
- data/lib/graphql/tracing/appoptics_tracing.rb +173 -0
- data/lib/graphql/tracing/appsignal_trace.rb +77 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +15 -0
- data/lib/graphql/tracing/data_dog_trace.rb +148 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +26 -2
- data/lib/graphql/tracing/legacy_trace.rb +65 -0
- data/lib/graphql/tracing/new_relic_trace.rb +75 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +1 -12
- data/lib/graphql/tracing/notifications_trace.rb +42 -0
- data/lib/graphql/tracing/notifications_tracing.rb +59 -0
- data/lib/graphql/tracing/platform_trace.rb +109 -0
- data/lib/graphql/tracing/platform_tracing.rb +64 -43
- data/lib/graphql/tracing/prometheus_trace.rb +89 -0
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +5 -2
- data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
- data/lib/graphql/tracing/scout_trace.rb +72 -0
- data/lib/graphql/tracing/scout_tracing.rb +11 -0
- data/lib/graphql/tracing/statsd_trace.rb +56 -0
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing/trace.rb +75 -0
- data/lib/graphql/tracing.rb +23 -71
- data/lib/graphql/type_kinds.rb +6 -3
- 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 -92
- data/lib/graphql/types/relay/base_edge.rb +2 -34
- data/lib/graphql/types/relay/connection_behaviors.rb +176 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +75 -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 +25 -0
- data/lib/graphql/types/relay/page_info.rb +2 -14
- data/lib/graphql/types/relay/page_info_behaviors.rb +30 -0
- data/lib/graphql/types/relay.rb +10 -5
- data/lib/graphql/types/string.rb +8 -2
- data/lib/graphql/unauthorized_error.rb +2 -2
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +54 -65
- data/readme.md +3 -6
- metadata +116 -236
- 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 -131
- data/lib/graphql/authorization.rb +0 -82
- data/lib/graphql/backwards_compatibility.rb +0 -60
- data/lib/graphql/base_type.rb +0 -230
- 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 -87
- 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 -210
- 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 -2
- data/lib/graphql/directive/include_directive.rb +0 -2
- data/lib/graphql/directive/skip_directive.rb +0 -2
- data/lib/graphql/directive.rb +0 -107
- data/lib/graphql/enum_type.rb +0 -127
- 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 -222
- data/lib/graphql/float_type.rb +0 -2
- data/lib/graphql/function.rb +0 -124
- data/lib/graphql/id_type.rb +0 -2
- data/lib/graphql/input_object_type.rb +0 -132
- data/lib/graphql/int_type.rb +0 -2
- data/lib/graphql/interface_type.rb +0 -65
- 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/language/lexer.rl +0 -258
- 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 -71
- data/lib/graphql/object_type.rb +0 -121
- data/lib/graphql/query/arguments.rb +0 -188
- 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 -136
- 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 -176
- 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 -41
- data/lib/graphql/relay/edge.rb +0 -27
- data/lib/graphql/relay/edge_type.rb +0 -19
- 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 -105
- 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 -76
- 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 -31
- 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 -65
- data/lib/graphql/tracing/skylight_tracing.rb +0 -70
- 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 -113
- data/lib/graphql/upgrader/member.rb +0 -936
- data/lib/graphql/upgrader/schema.rb +0 -37
@@ -5,31 +5,26 @@ 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(schema_superclass, definition_string, parser: GraphQL.default_parser, **kwargs)
|
10
|
+
from_document(schema_superclass, parser.parse(definition_string), **kwargs)
|
11
11
|
end
|
12
|
-
end
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
def from_definition_path(schema_superclass, definition_path, parser: GraphQL.default_parser, **kwargs)
|
14
|
+
from_document(schema_superclass, 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(schema_superclass, document, default_resolve:, using: {}, relay: false)
|
18
|
+
Builder.build(schema_superclass, document, default_resolve: default_resolve || {}, relay: relay, using: using)
|
25
19
|
end
|
26
20
|
end
|
27
21
|
|
28
22
|
# @api private
|
29
23
|
module Builder
|
24
|
+
include GraphQL::EmptyObjects
|
30
25
|
extend self
|
31
26
|
|
32
|
-
def build(document, default_resolve
|
27
|
+
def build(schema_superclass, document, default_resolve:, using: {}, relay:)
|
33
28
|
raise InvalidDocumentError.new('Must provide a document ast.') if !document || !document.is_a?(GraphQL::Language::Nodes::Document)
|
34
29
|
|
35
30
|
if default_resolve.is_a?(Hash)
|
@@ -42,34 +37,53 @@ module GraphQL
|
|
42
37
|
end
|
43
38
|
schema_definition = schema_defns.first
|
44
39
|
types = {}
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
directives = schema_superclass.directives.dup
|
41
|
+
type_resolver = build_resolve_type(types, directives, ->(type_name) { types[type_name] ||= Schema::LateBoundType.new(type_name)})
|
42
|
+
# Make a different type resolver because we need to coerce directive arguments
|
43
|
+
# _while_ building the schema.
|
44
|
+
# It will dig for a type if it encounters a custom type. This could be a problem if there are cycles.
|
45
|
+
directive_type_resolver = nil
|
46
|
+
directive_type_resolver = build_resolve_type(types, directives, ->(type_name) {
|
47
|
+
types[type_name] ||= begin
|
48
|
+
defn = document.definitions.find { |d| d.respond_to?(:name) && d.name == type_name }
|
49
|
+
if defn
|
50
|
+
build_definition_from_node(defn, directive_type_resolver, default_resolve)
|
51
|
+
elsif (built_in_defn = GraphQL::Schema::BUILT_IN_TYPES[type_name])
|
52
|
+
built_in_defn
|
53
|
+
else
|
54
|
+
raise "No definition for #{type_name.inspect} found in schema document or built-in types. Add a definition for it or remove it."
|
55
|
+
end
|
56
|
+
end
|
57
|
+
})
|
48
58
|
|
59
|
+
directives.merge!(GraphQL::Schema.default_directives)
|
60
|
+
document.definitions.each do |definition|
|
61
|
+
if definition.is_a?(GraphQL::Language::Nodes::DirectiveDefinition)
|
62
|
+
directives[definition.name] = build_directive(definition, directive_type_resolver)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# In case any directives referenced built-in types for their arguments:
|
67
|
+
replace_late_bound_types_with_built_in(types)
|
68
|
+
|
69
|
+
schema_extensions = nil
|
49
70
|
document.definitions.each do |definition|
|
50
71
|
case definition
|
51
|
-
when GraphQL::Language::Nodes::SchemaDefinition
|
72
|
+
when GraphQL::Language::Nodes::SchemaDefinition, GraphQL::Language::Nodes::DirectiveDefinition
|
52
73
|
nil # already handled
|
53
|
-
when GraphQL::Language::Nodes::
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
types[definition.name]
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
types[definition.name] = build_union_type(definition, type_resolver)
|
63
|
-
when GraphQL::Language::Nodes::ScalarTypeDefinition
|
64
|
-
types[definition.name] = build_scalar_type(definition, type_resolver, default_resolve: default_resolve)
|
65
|
-
when GraphQL::Language::Nodes::InputObjectTypeDefinition
|
66
|
-
types[definition.name] = build_input_object_type(definition, type_resolver)
|
67
|
-
when GraphQL::Language::Nodes::DirectiveDefinition
|
68
|
-
directives[definition.name] = build_directive(definition, type_resolver)
|
74
|
+
when GraphQL::Language::Nodes::SchemaExtension
|
75
|
+
schema_extensions ||= []
|
76
|
+
schema_extensions << definition
|
77
|
+
else
|
78
|
+
# It's possible that this was already loaded by the directives
|
79
|
+
prev_type = types[definition.name]
|
80
|
+
if prev_type.nil? || prev_type.is_a?(Schema::LateBoundType)
|
81
|
+
types[definition.name] = build_definition_from_node(definition, type_resolver, default_resolve)
|
82
|
+
end
|
69
83
|
end
|
70
84
|
end
|
71
85
|
|
72
|
-
|
86
|
+
replace_late_bound_types_with_built_in(types)
|
73
87
|
|
74
88
|
if schema_definition
|
75
89
|
if schema_definition.query
|
@@ -86,6 +100,16 @@ module GraphQL
|
|
86
100
|
raise InvalidDocumentError.new("Specified subscription type \"#{schema_definition.subscription}\" not found in document.") unless types[schema_definition.subscription]
|
87
101
|
subscription_root_type = types[schema_definition.subscription]
|
88
102
|
end
|
103
|
+
|
104
|
+
if schema_definition.query.nil? &&
|
105
|
+
schema_definition.mutation.nil? &&
|
106
|
+
schema_definition.subscription.nil?
|
107
|
+
# This schema may have been given with directives only,
|
108
|
+
# check for defaults:
|
109
|
+
query_root_type = types['Query']
|
110
|
+
mutation_root_type = types['Mutation']
|
111
|
+
subscription_root_type = types['Subscription']
|
112
|
+
end
|
89
113
|
else
|
90
114
|
query_root_type = types['Query']
|
91
115
|
mutation_root_type = types['Mutation']
|
@@ -94,7 +118,9 @@ module GraphQL
|
|
94
118
|
|
95
119
|
raise InvalidDocumentError.new('Must provide schema definition with query type or a type named Query.') unless query_root_type
|
96
120
|
|
97
|
-
|
121
|
+
builder = self
|
122
|
+
|
123
|
+
schema_class = Class.new(schema_superclass) do
|
98
124
|
begin
|
99
125
|
# Add these first so that there's some chance of resolving late-bound types
|
100
126
|
orphan_types types.values
|
@@ -108,11 +134,11 @@ module GraphQL
|
|
108
134
|
end
|
109
135
|
|
110
136
|
if default_resolve.respond_to?(:resolve_type)
|
111
|
-
|
112
|
-
|
137
|
+
def self.resolve_type(*args)
|
138
|
+
self.definition_default_resolve.resolve_type(*args)
|
113
139
|
end
|
114
140
|
else
|
115
|
-
|
141
|
+
def self.resolve_type(*args)
|
116
142
|
NullResolveType.call(*args)
|
117
143
|
end
|
118
144
|
end
|
@@ -121,11 +147,7 @@ module GraphQL
|
|
121
147
|
|
122
148
|
if schema_definition
|
123
149
|
ast_node(schema_definition)
|
124
|
-
|
125
|
-
|
126
|
-
if interpreter
|
127
|
-
use GraphQL::Execution::Interpreter
|
128
|
-
use GraphQL::Analysis::AST
|
150
|
+
builder.build_directives(self, schema_definition, type_resolver)
|
129
151
|
end
|
130
152
|
|
131
153
|
using.each do |plugin, options|
|
@@ -135,17 +157,122 @@ module GraphQL
|
|
135
157
|
use(plugin)
|
136
158
|
end
|
137
159
|
end
|
160
|
+
|
161
|
+
# Empty `orphan_types` -- this will make unreachable types ... unreachable.
|
162
|
+
own_orphan_types.clear
|
163
|
+
|
164
|
+
class << self
|
165
|
+
attr_accessor :definition_default_resolve
|
166
|
+
end
|
167
|
+
|
168
|
+
self.definition_default_resolve = default_resolve
|
169
|
+
|
170
|
+
def definition_default_resolve
|
171
|
+
self.class.definition_default_resolve
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.inherited(child_class)
|
175
|
+
child_class.definition_default_resolve = self.definition_default_resolve
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
if schema_extensions
|
180
|
+
schema_extensions.each do |ext|
|
181
|
+
build_directives(schema_class, ext, type_resolver)
|
182
|
+
end
|
138
183
|
end
|
184
|
+
|
185
|
+
schema_class
|
139
186
|
end
|
140
187
|
|
141
188
|
NullResolveType = ->(type, obj, ctx) {
|
142
189
|
raise(GraphQL::RequiredImplementationMissingError, "Generated Schema cannot use Interface or Union types for execution. Implement resolve_type on your resolver.")
|
143
190
|
}
|
144
191
|
|
192
|
+
def build_definition_from_node(definition, type_resolver, default_resolve)
|
193
|
+
case definition
|
194
|
+
when GraphQL::Language::Nodes::EnumTypeDefinition
|
195
|
+
build_enum_type(definition, type_resolver)
|
196
|
+
when GraphQL::Language::Nodes::ObjectTypeDefinition
|
197
|
+
build_object_type(definition, type_resolver)
|
198
|
+
when GraphQL::Language::Nodes::InterfaceTypeDefinition
|
199
|
+
build_interface_type(definition, type_resolver)
|
200
|
+
when GraphQL::Language::Nodes::UnionTypeDefinition
|
201
|
+
build_union_type(definition, type_resolver)
|
202
|
+
when GraphQL::Language::Nodes::ScalarTypeDefinition
|
203
|
+
build_scalar_type(definition, type_resolver, default_resolve: default_resolve)
|
204
|
+
when GraphQL::Language::Nodes::InputObjectTypeDefinition
|
205
|
+
build_input_object_type(definition, type_resolver)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
# Modify `types`, replacing any late-bound references to built-in types
|
210
|
+
# with their actual definitions.
|
211
|
+
#
|
212
|
+
# (Schema definitions are allowed to reference those built-ins without redefining them.)
|
213
|
+
# @return void
|
214
|
+
def replace_late_bound_types_with_built_in(types)
|
215
|
+
GraphQL::Schema::BUILT_IN_TYPES.each do |scalar_name, built_in_scalar|
|
216
|
+
existing_type = types[scalar_name]
|
217
|
+
if existing_type.is_a?(GraphQL::Schema::LateBoundType)
|
218
|
+
types[scalar_name] = built_in_scalar
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def build_directives(definition, ast_node, type_resolver)
|
224
|
+
dirs = prepare_directives(ast_node, type_resolver)
|
225
|
+
dirs.each do |(dir_class, options)|
|
226
|
+
if definition.respond_to?(:schema_directive)
|
227
|
+
# it's a schema
|
228
|
+
definition.schema_directive(dir_class, **options)
|
229
|
+
else
|
230
|
+
definition.directive(dir_class, **options)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def prepare_directives(ast_node, type_resolver)
|
236
|
+
dirs = []
|
237
|
+
ast_node.directives.each do |dir_node|
|
238
|
+
if dir_node.name == "deprecated"
|
239
|
+
# This is handled using `deprecation_reason`
|
240
|
+
next
|
241
|
+
else
|
242
|
+
dir_class = type_resolver.call(dir_node.name)
|
243
|
+
if dir_class.nil?
|
244
|
+
raise ArgumentError, "No definition for @#{dir_node.name} #{ast_node.respond_to?(:name) ? "on #{ast_node.name} " : ""}at #{ast_node.line}:#{ast_node.col}"
|
245
|
+
end
|
246
|
+
options = args_to_kwargs(dir_class, dir_node)
|
247
|
+
dirs << [dir_class, options]
|
248
|
+
end
|
249
|
+
end
|
250
|
+
dirs
|
251
|
+
end
|
252
|
+
|
253
|
+
def args_to_kwargs(arg_owner, node)
|
254
|
+
if node.respond_to?(:arguments)
|
255
|
+
kwargs = {}
|
256
|
+
node.arguments.each do |arg_node|
|
257
|
+
arg_defn = arg_owner.get_argument(arg_node.name)
|
258
|
+
kwargs[arg_defn.keyword] = args_to_kwargs(arg_defn.type.unwrap, arg_node.value)
|
259
|
+
end
|
260
|
+
kwargs
|
261
|
+
elsif node.is_a?(Array)
|
262
|
+
node.map { |n| args_to_kwargs(arg_owner, n) }
|
263
|
+
elsif node.is_a?(Language::Nodes::Enum)
|
264
|
+
node.name
|
265
|
+
else
|
266
|
+
# scalar
|
267
|
+
node
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
145
271
|
def build_enum_type(enum_type_definition, type_resolver)
|
146
272
|
builder = self
|
147
273
|
Class.new(GraphQL::Schema::Enum) do
|
148
274
|
graphql_name(enum_type_definition.name)
|
275
|
+
builder.build_directives(self, enum_type_definition, type_resolver)
|
149
276
|
description(enum_type_definition.description)
|
150
277
|
ast_node(enum_type_definition)
|
151
278
|
enum_type_definition.values.each do |enum_value_definition|
|
@@ -153,6 +280,7 @@ module GraphQL
|
|
153
280
|
value: enum_value_definition.name,
|
154
281
|
deprecation_reason: builder.build_deprecation_reason(enum_value_definition.directives),
|
155
282
|
description: enum_value_definition.description,
|
283
|
+
directives: builder.prepare_directives(enum_value_definition, type_resolver),
|
156
284
|
ast_node: enum_value_definition,
|
157
285
|
)
|
158
286
|
end
|
@@ -170,53 +298,54 @@ module GraphQL
|
|
170
298
|
end
|
171
299
|
|
172
300
|
def build_scalar_type(scalar_type_definition, type_resolver, default_resolve:)
|
301
|
+
builder = self
|
173
302
|
Class.new(GraphQL::Schema::Scalar) do
|
174
303
|
graphql_name(scalar_type_definition.name)
|
175
304
|
description(scalar_type_definition.description)
|
176
305
|
ast_node(scalar_type_definition)
|
306
|
+
builder.build_directives(self, scalar_type_definition, type_resolver)
|
177
307
|
|
178
308
|
if default_resolve.respond_to?(:coerce_input)
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
define_singleton_method(:coerce_result) do |val, ctx|
|
184
|
-
default_resolve.coerce_result(self, val, ctx)
|
185
|
-
end
|
309
|
+
# Put these method definitions in another method to avoid retaining `type_resolve`
|
310
|
+
# from this method's bindiing
|
311
|
+
builder.build_scalar_type_coerce_method(self, :coerce_input, default_resolve)
|
312
|
+
builder.build_scalar_type_coerce_method(self, :coerce_result, default_resolve)
|
186
313
|
end
|
187
314
|
end
|
188
315
|
end
|
189
316
|
|
317
|
+
def build_scalar_type_coerce_method(scalar_class, method_name, default_definition_resolve)
|
318
|
+
scalar_class.define_singleton_method(method_name) do |val, ctx|
|
319
|
+
default_definition_resolve.public_send(method_name, self, val, ctx)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
190
323
|
def build_union_type(union_type_definition, type_resolver)
|
324
|
+
builder = self
|
191
325
|
Class.new(GraphQL::Schema::Union) do
|
192
326
|
graphql_name(union_type_definition.name)
|
193
327
|
description(union_type_definition.description)
|
194
328
|
possible_types(*union_type_definition.types.map { |type_name| type_resolver.call(type_name) })
|
195
329
|
ast_node(union_type_definition)
|
330
|
+
builder.build_directives(self, union_type_definition, type_resolver)
|
196
331
|
end
|
197
332
|
end
|
198
333
|
|
199
|
-
def build_object_type(object_type_definition, type_resolver
|
334
|
+
def build_object_type(object_type_definition, type_resolver)
|
200
335
|
builder = self
|
201
|
-
type_def = nil
|
202
|
-
typed_resolve_fn = ->(field, obj, args, ctx) { default_resolve.call(type_def, field, obj, args, ctx) }
|
203
336
|
|
204
337
|
Class.new(GraphQL::Schema::Object) do
|
205
|
-
type_def = self
|
206
338
|
graphql_name(object_type_definition.name)
|
207
339
|
description(object_type_definition.description)
|
208
340
|
ast_node(object_type_definition)
|
209
|
-
|
210
|
-
# This has to come before `field ...` configurations since it modifies them
|
211
|
-
extend Subscriptions::SubscriptionRoot
|
212
|
-
end
|
341
|
+
builder.build_directives(self, object_type_definition, type_resolver)
|
213
342
|
|
214
343
|
object_type_definition.interfaces.each do |interface_name|
|
215
344
|
interface_defn = type_resolver.call(interface_name)
|
216
345
|
implements(interface_defn)
|
217
346
|
end
|
218
347
|
|
219
|
-
builder.build_fields(self, object_type_definition.fields, type_resolver, default_resolve:
|
348
|
+
builder.build_fields(self, object_type_definition.fields, type_resolver, default_resolve: true)
|
220
349
|
end
|
221
350
|
end
|
222
351
|
|
@@ -226,6 +355,7 @@ module GraphQL
|
|
226
355
|
graphql_name(input_object_type_definition.name)
|
227
356
|
description(input_object_type_definition.description)
|
228
357
|
ast_node(input_object_type_definition)
|
358
|
+
builder.build_directives(self, input_object_type_definition, type_resolver)
|
229
359
|
builder.build_arguments(self, input_object_type_definition.fields, type_resolver)
|
230
360
|
end
|
231
361
|
end
|
@@ -249,9 +379,10 @@ module GraphQL
|
|
249
379
|
builder = self
|
250
380
|
|
251
381
|
arguments.each do |argument_defn|
|
252
|
-
default_value_kwargs =
|
253
|
-
|
254
|
-
|
382
|
+
default_value_kwargs = if !argument_defn.default_value.nil?
|
383
|
+
{ default_value: builder.build_default_value(argument_defn.default_value) }
|
384
|
+
else
|
385
|
+
EMPTY_HASH
|
255
386
|
end
|
256
387
|
|
257
388
|
type_class.argument(
|
@@ -259,9 +390,10 @@ module GraphQL
|
|
259
390
|
type: type_resolver.call(argument_defn.type),
|
260
391
|
required: false,
|
261
392
|
description: argument_defn.description,
|
393
|
+
deprecation_reason: builder.build_deprecation_reason(argument_defn.directives),
|
262
394
|
ast_node: argument_defn,
|
263
395
|
camelize: false,
|
264
|
-
|
396
|
+
directives: prepare_directives(argument_defn, type_resolver),
|
265
397
|
**default_value_kwargs
|
266
398
|
)
|
267
399
|
end
|
@@ -272,6 +404,7 @@ module GraphQL
|
|
272
404
|
Class.new(GraphQL::Schema::Directive) do
|
273
405
|
graphql_name(directive_definition.name)
|
274
406
|
description(directive_definition.description)
|
407
|
+
repeatable(directive_definition.repeatable)
|
275
408
|
locations(*directive_definition.locations.map { |location| location.name.to_sym })
|
276
409
|
ast_node(directive_definition)
|
277
410
|
builder.build_arguments(self, directive_definition.arguments, type_resolver)
|
@@ -284,7 +417,12 @@ module GraphQL
|
|
284
417
|
include GraphQL::Schema::Interface
|
285
418
|
graphql_name(interface_type_definition.name)
|
286
419
|
description(interface_type_definition.description)
|
420
|
+
interface_type_definition.interfaces.each do |interface_name|
|
421
|
+
interface_defn = type_resolver.call(interface_name)
|
422
|
+
implements(interface_defn)
|
423
|
+
end
|
287
424
|
ast_node(interface_type_definition)
|
425
|
+
builder.build_directives(self, interface_type_definition, type_resolver)
|
288
426
|
|
289
427
|
builder.build_fields(self, interface_type_definition.fields, type_resolver, default_resolve: nil)
|
290
428
|
end
|
@@ -293,45 +431,61 @@ module GraphQL
|
|
293
431
|
def build_fields(owner, field_definitions, type_resolver, default_resolve:)
|
294
432
|
builder = self
|
295
433
|
|
296
|
-
field_definitions.
|
434
|
+
field_definitions.each do |field_definition|
|
297
435
|
type_name = resolve_type_name(field_definition.type)
|
298
|
-
|
299
|
-
owner.field(
|
436
|
+
resolve_method_name = -"resolve_field_#{field_definition.name}"
|
437
|
+
schema_field_defn = owner.field(
|
300
438
|
field_definition.name,
|
301
439
|
description: field_definition.description,
|
302
440
|
type: type_resolver.call(field_definition.type),
|
303
441
|
null: true,
|
304
442
|
connection: type_name.end_with?("Connection"),
|
443
|
+
connection_extension: nil,
|
305
444
|
deprecation_reason: build_deprecation_reason(field_definition.directives),
|
306
445
|
ast_node: field_definition,
|
307
446
|
method_conflict_warning: false,
|
308
447
|
camelize: false,
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
448
|
+
directives: prepare_directives(field_definition, type_resolver),
|
449
|
+
resolver_method: resolve_method_name,
|
450
|
+
)
|
451
|
+
|
452
|
+
builder.build_arguments(schema_field_defn, field_definition.arguments, type_resolver)
|
453
|
+
|
454
|
+
# Don't do this for interfaces
|
455
|
+
if default_resolve
|
456
|
+
owner.class_eval <<-RUBY, __FILE__, __LINE__
|
457
|
+
# frozen_string_literal: true
|
458
|
+
def #{resolve_method_name}(**args)
|
459
|
+
field_instance = self.class.get_field("#{field_definition.name}")
|
460
|
+
context.schema.definition_default_resolve.call(self.class, field_instance, object, args, context)
|
317
461
|
end
|
318
|
-
|
462
|
+
RUBY
|
319
463
|
end
|
320
464
|
end
|
321
465
|
end
|
322
466
|
|
323
|
-
def
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
467
|
+
def build_resolve_type(lookup_hash, directives, missing_type_handler)
|
468
|
+
resolve_type_proc = nil
|
469
|
+
resolve_type_proc = ->(ast_node) {
|
470
|
+
case ast_node
|
471
|
+
when GraphQL::Language::Nodes::TypeName
|
472
|
+
type_name = ast_node.name
|
473
|
+
if lookup_hash.key?(type_name)
|
474
|
+
lookup_hash[type_name]
|
475
|
+
else
|
476
|
+
missing_type_handler.call(type_name)
|
477
|
+
end
|
478
|
+
when GraphQL::Language::Nodes::NonNullType
|
479
|
+
resolve_type_proc.call(ast_node.of_type).to_non_null_type
|
480
|
+
when GraphQL::Language::Nodes::ListType
|
481
|
+
resolve_type_proc.call(ast_node.of_type).to_list_type
|
482
|
+
when String
|
483
|
+
directives[ast_node]
|
484
|
+
else
|
485
|
+
raise "Unexpected ast_node: #{ast_node.inspect}"
|
486
|
+
end
|
487
|
+
}
|
488
|
+
resolve_type_proc
|
335
489
|
end
|
336
490
|
|
337
491
|
def resolve_type_name(type)
|
@@ -4,7 +4,7 @@ module GraphQL
|
|
4
4
|
class Directive < GraphQL::Schema::Member
|
5
5
|
class Deprecated < GraphQL::Schema::Directive
|
6
6
|
description "Marks an element of a GraphQL schema as no longer supported."
|
7
|
-
locations(GraphQL::Schema::Directive::FIELD_DEFINITION, GraphQL::Schema::Directive::ENUM_VALUE)
|
7
|
+
locations(GraphQL::Schema::Directive::FIELD_DEFINITION, GraphQL::Schema::Directive::ENUM_VALUE, GraphQL::Schema::Directive::ARGUMENT_DEFINITION, GraphQL::Schema::Directive::INPUT_FIELD_DEFINITION)
|
8
8
|
|
9
9
|
reason_description = "Explains why this element was deprecated, usually also including a "\
|
10
10
|
"suggestion for how to access supported similar data. Formatted "\
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
class Directive < GraphQL::Schema::Member
|
5
|
+
# This is _similar_ to {Directive::Feature}, except it's prescribed by the server, not the client.
|
6
|
+
#
|
7
|
+
# In this case, the server hides types and fields _entirely_, unless the current context has certain `:flags` present.
|
8
|
+
class Flagged < GraphQL::Schema::Directive
|
9
|
+
def initialize(target, **options)
|
10
|
+
if target.is_a?(Module) && !target.ancestors.include?(VisibleByFlag)
|
11
|
+
# This is type class of some kind, `include` will put this module
|
12
|
+
# in between the type class itself and its super class, so `super` will work fine
|
13
|
+
target.include(VisibleByFlag)
|
14
|
+
elsif !target.is_a?(VisibleByFlag)
|
15
|
+
# This is an instance of a base class. `include` won't put this in front of the
|
16
|
+
# base class implementation, so we need to `.prepend`.
|
17
|
+
# `#visible?` could probably be moved to a module and then this could use `include` instead.
|
18
|
+
target.class.prepend(VisibleByFlag)
|
19
|
+
end
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
description "Hides this part of the schema unless the named flag is present in context[:flags]"
|
24
|
+
|
25
|
+
locations(
|
26
|
+
GraphQL::Schema::Directive::FIELD_DEFINITION,
|
27
|
+
GraphQL::Schema::Directive::OBJECT,
|
28
|
+
GraphQL::Schema::Directive::SCALAR,
|
29
|
+
GraphQL::Schema::Directive::ENUM,
|
30
|
+
GraphQL::Schema::Directive::UNION,
|
31
|
+
GraphQL::Schema::Directive::INTERFACE,
|
32
|
+
GraphQL::Schema::Directive::INPUT_OBJECT,
|
33
|
+
GraphQL::Schema::Directive::ENUM_VALUE,
|
34
|
+
GraphQL::Schema::Directive::ARGUMENT_DEFINITION,
|
35
|
+
GraphQL::Schema::Directive::INPUT_FIELD_DEFINITION,
|
36
|
+
)
|
37
|
+
|
38
|
+
argument :by, [String], "Flags to check for this schema member"
|
39
|
+
|
40
|
+
module VisibleByFlag
|
41
|
+
def self.included(schema_class)
|
42
|
+
schema_class.extend(self)
|
43
|
+
end
|
44
|
+
|
45
|
+
def visible?(context)
|
46
|
+
if dir = self.directives.find { |d| d.is_a?(Flagged) }
|
47
|
+
relevant_flags = (f = context[:flags]) && dir.arguments[:by] & f # rubocop:disable Development/ContextIsPassedCop -- definition-related
|
48
|
+
relevant_flags && relevant_flags.any? && super
|
49
|
+
else
|
50
|
+
super
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
class Directive < GraphQL::Schema::Member
|
5
|
+
class OneOf < GraphQL::Schema::Directive
|
6
|
+
description "Requires that exactly one field must be supplied and that field must not be `null`."
|
7
|
+
locations(GraphQL::Schema::Directive::INPUT_OBJECT)
|
8
|
+
default_directive true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -24,7 +24,7 @@ module GraphQL
|
|
24
24
|
GraphQL::Schema::Directive::FIELD,
|
25
25
|
)
|
26
26
|
|
27
|
-
argument :by, String,
|
27
|
+
argument :by, String,
|
28
28
|
description: "The name of the transform to run if applicable"
|
29
29
|
|
30
30
|
TRANSFORMS = [
|
@@ -39,7 +39,19 @@ module GraphQL
|
|
39
39
|
transform_name = arguments[:by]
|
40
40
|
if TRANSFORMS.include?(transform_name) && return_value.respond_to?(transform_name)
|
41
41
|
return_value = return_value.public_send(transform_name)
|
42
|
-
context.namespace(:
|
42
|
+
response = context.namespace(:interpreter_runtime)[:runtime].final_result
|
43
|
+
*keys, last = path
|
44
|
+
keys.each do |key|
|
45
|
+
if response && (response = response[key])
|
46
|
+
next
|
47
|
+
else
|
48
|
+
break
|
49
|
+
end
|
50
|
+
end
|
51
|
+
if response
|
52
|
+
response[last] = return_value
|
53
|
+
end
|
54
|
+
nil
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|