graphql 1.12.12 → 2.2.14
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 +3 -8
- 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 +14 -4
- data/lib/generators/graphql/interface_generator.rb +7 -7
- 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 +5 -30
- data/lib/generators/graphql/mutation_update_generator.rb +22 -0
- data/lib/generators/graphql/object_generator.rb +10 -38
- data/lib/generators/graphql/orm_mutations_base.rb +40 -0
- data/lib/generators/graphql/relay.rb +23 -12
- 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 +2 -0
- data/lib/generators/graphql/templates/base_edge.erb +2 -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_resolver.erb +6 -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 +5 -1
- data/lib/generators/graphql/templates/graphql_controller.erb +2 -0
- data/lib/generators/graphql/templates/input.erb +9 -0
- data/lib/generators/graphql/templates/interface.erb +4 -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 +2 -0
- data/lib/generators/graphql/templates/object.erb +4 -2
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/scalar.erb +3 -1
- data/lib/generators/graphql/templates/schema.erb +19 -2
- data/lib/generators/graphql/templates/union.erb +4 -2
- data/lib/generators/graphql/type_generator.rb +46 -10
- data/lib/generators/graphql/union_generator.rb +5 -5
- data/lib/graphql/analysis/ast/analyzer.rb +7 -0
- data/lib/graphql/analysis/ast/field_usage.rb +55 -1
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +88 -140
- data/lib/graphql/analysis/ast/query_depth.rb +7 -3
- data/lib/graphql/analysis/ast/visitor.rb +50 -42
- data/lib/graphql/analysis/ast.rb +26 -23
- data/lib/graphql/analysis.rb +0 -7
- data/lib/graphql/backtrace/table.rb +4 -22
- data/lib/graphql/backtrace/trace.rb +93 -0
- data/lib/graphql/backtrace/tracer.rb +8 -6
- data/lib/graphql/backtrace.rb +3 -8
- data/lib/graphql/coercion_error.rb +1 -9
- data/lib/graphql/dataloader/async_dataloader.rb +85 -0
- data/lib/graphql/dataloader/null_dataloader.rb +3 -1
- data/lib/graphql/dataloader/request.rb +5 -0
- data/lib/graphql/dataloader/source.rb +120 -31
- data/lib/graphql/dataloader.rb +168 -142
- data/lib/graphql/date_encoding_error.rb +16 -0
- data/lib/graphql/dig.rb +1 -1
- data/lib/graphql/duration_encoding_error.rb +16 -0
- data/lib/graphql/execution/errors.rb +12 -81
- data/lib/graphql/execution/interpreter/arguments.rb +2 -2
- data/lib/graphql/execution/interpreter/arguments_cache.rb +36 -34
- data/lib/graphql/execution/interpreter/resolve.rb +32 -2
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +170 -0
- data/lib/graphql/execution/interpreter/runtime.rb +414 -341
- data/lib/graphql/execution/interpreter.rb +122 -80
- data/lib/graphql/execution/lazy.rb +11 -21
- data/lib/graphql/execution/lookahead.rb +125 -54
- data/lib/graphql/execution/multiplex.rb +4 -172
- data/lib/graphql/execution.rb +11 -4
- 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 +5 -3
- data/lib/graphql/introspection/dynamic_fields.rb +3 -8
- data/lib/graphql/introspection/entry_points.rb +11 -18
- data/lib/graphql/introspection/enum_value_type.rb +2 -2
- data/lib/graphql/introspection/field_type.rb +3 -3
- data/lib/graphql/introspection/input_value_type.rb +10 -4
- data/lib/graphql/introspection/schema_type.rb +12 -5
- data/lib/graphql/introspection/type_type.rb +25 -12
- data/lib/graphql/introspection.rb +6 -2
- data/lib/graphql/language/block_string.rb +37 -25
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/document_from_schema_definition.rb +78 -65
- data/lib/graphql/language/lexer.rb +345 -1467
- data/lib/graphql/language/nodes.rb +145 -91
- data/lib/graphql/language/parser.rb +701 -1921
- data/lib/graphql/language/printer.rb +351 -155
- data/lib/graphql/language/sanitized_printer.rb +25 -27
- data/lib/graphql/language/static_visitor.rb +167 -0
- data/lib/graphql/language/token.rb +0 -4
- data/lib/graphql/language/visitor.rb +188 -141
- data/lib/graphql/language.rb +1 -0
- data/lib/graphql/load_application_object_failed_error.rb +5 -1
- data/lib/graphql/name_validator.rb +0 -4
- data/lib/graphql/pagination/active_record_relation_connection.rb +37 -8
- data/lib/graphql/pagination/array_connection.rb +8 -6
- data/lib/graphql/pagination/connection.rb +61 -7
- data/lib/graphql/pagination/connections.rb +22 -23
- data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -2
- data/lib/graphql/pagination/relation_connection.rb +60 -28
- data/lib/graphql/query/context/scoped_context.rb +101 -0
- data/lib/graphql/query/context.rb +109 -189
- data/lib/graphql/query/input_validation_result.rb +10 -1
- data/lib/graphql/query/null_context.rb +14 -29
- data/lib/graphql/query/validation_pipeline.rb +15 -39
- data/lib/graphql/query/variable_validation_error.rb +2 -2
- data/lib/graphql/query/variables.rb +35 -17
- data/lib/graphql/query.rb +78 -65
- data/lib/graphql/railtie.rb +8 -109
- data/lib/graphql/rake_task/validate.rb +1 -1
- data/lib/graphql/rake_task.rb +30 -11
- data/lib/graphql/relay/range_add.rb +9 -16
- 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 +78 -45
- data/lib/graphql/schema/always_visible.rb +10 -0
- data/lib/graphql/schema/argument.rb +134 -80
- data/lib/graphql/schema/base_64_encoder.rb +3 -5
- data/lib/graphql/schema/build_from_definition.rb +60 -38
- data/lib/graphql/schema/directive/feature.rb +1 -1
- data/lib/graphql/schema/directive/flagged.rb +2 -2
- data/lib/graphql/schema/directive/include.rb +1 -1
- data/lib/graphql/schema/directive/one_of.rb +24 -0
- data/lib/graphql/schema/directive/skip.rb +1 -1
- data/lib/graphql/schema/directive/specified_by.rb +14 -0
- data/lib/graphql/schema/directive/transform.rb +2 -2
- data/lib/graphql/schema/directive.rb +33 -21
- data/lib/graphql/schema/enum.rb +93 -46
- data/lib/graphql/schema/enum_value.rb +4 -21
- data/lib/graphql/schema/field/connection_extension.rb +6 -16
- data/lib/graphql/schema/field/scope_extension.rb +8 -1
- data/lib/graphql/schema/field.rb +432 -337
- data/lib/graphql/schema/field_extension.rb +86 -2
- data/lib/graphql/schema/find_inherited_value.rb +3 -7
- data/lib/graphql/schema/finder.rb +5 -5
- data/lib/graphql/schema/has_single_input_argument.rb +156 -0
- data/lib/graphql/schema/input_object.rb +88 -90
- data/lib/graphql/schema/interface.rb +19 -59
- data/lib/graphql/schema/introspection_system.rb +6 -9
- data/lib/graphql/schema/late_bound_type.rb +8 -2
- data/lib/graphql/schema/list.rb +18 -7
- data/lib/graphql/schema/loader.rb +3 -3
- data/lib/graphql/schema/member/base_dsl_methods.rb +18 -19
- data/lib/graphql/schema/member/build_type.rb +16 -13
- data/lib/graphql/schema/member/has_arguments.rb +288 -84
- data/lib/graphql/schema/member/has_ast_node.rb +12 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
- data/lib/graphql/schema/member/has_directives.rb +81 -61
- data/lib/graphql/schema/member/has_fields.rb +149 -31
- data/lib/graphql/schema/member/has_interfaces.rb +143 -0
- data/lib/graphql/schema/member/has_validators.rb +32 -6
- data/lib/graphql/schema/member/relay_shortcuts.rb +47 -2
- data/lib/graphql/schema/member/scoped.rb +19 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +17 -0
- data/lib/graphql/schema/member/validates_input.rb +6 -6
- data/lib/graphql/schema/member.rb +1 -6
- data/lib/graphql/schema/mutation.rb +0 -9
- data/lib/graphql/schema/non_null.rb +7 -7
- data/lib/graphql/schema/object.rb +30 -119
- data/lib/graphql/schema/printer.rb +23 -25
- data/lib/graphql/schema/relay_classic_mutation.rb +13 -90
- data/lib/graphql/schema/resolver/has_payload_type.rb +46 -11
- data/lib/graphql/schema/resolver.rb +101 -102
- data/lib/graphql/schema/scalar.rb +20 -21
- data/lib/graphql/schema/subscription.rb +45 -17
- data/lib/graphql/schema/timeout.rb +25 -29
- data/lib/graphql/schema/type_expression.rb +1 -1
- data/lib/graphql/schema/type_membership.rb +21 -4
- data/lib/graphql/schema/union.rb +15 -15
- data/lib/graphql/schema/unique_within_type.rb +1 -1
- 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 +3 -1
- data/lib/graphql/schema/validator/format_validator.rb +4 -5
- data/lib/graphql/schema/validator/inclusion_validator.rb +3 -1
- data/lib/graphql/schema/validator/length_validator.rb +5 -3
- data/lib/graphql/schema/validator/numericality_validator.rb +13 -2
- data/lib/graphql/schema/validator/required_validator.rb +29 -15
- data/lib/graphql/schema/validator.rb +35 -27
- data/lib/graphql/schema/warden.rb +259 -132
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +658 -989
- data/lib/graphql/static_validation/all_rules.rb +3 -1
- data/lib/graphql/static_validation/base_visitor.rb +14 -28
- 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 +21 -4
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +11 -5
- 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 +54 -28
- 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/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 +5 -3
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +4 -4
- 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 +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +13 -7
- data/lib/graphql/static_validation/validation_context.rb +16 -6
- data/lib/graphql/static_validation/validator.rb +11 -27
- data/lib/graphql/static_validation.rb +0 -3
- data/lib/graphql/string_encoding_error.rb +13 -3
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +46 -9
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
- data/lib/graphql/subscriptions/event.rb +75 -37
- data/lib/graphql/subscriptions/serialize.rb +25 -3
- data/lib/graphql/subscriptions.rb +59 -47
- data/lib/graphql/testing/helpers.rb +129 -0
- data/lib/graphql/testing.rb +2 -0
- data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +6 -20
- data/lib/graphql/tracing/appoptics_trace.rb +251 -0
- data/lib/graphql/tracing/appoptics_tracing.rb +2 -2
- 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 +183 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +25 -15
- data/lib/graphql/{execution/instrumentation.rb → tracing/legacy_hooks_trace.rb} +10 -28
- data/lib/graphql/tracing/legacy_trace.rb +69 -0
- data/lib/graphql/tracing/new_relic_trace.rb +75 -0
- data/lib/graphql/tracing/notifications_trace.rb +45 -0
- data/lib/graphql/tracing/notifications_tracing.rb +59 -0
- data/lib/graphql/tracing/platform_trace.rb +118 -0
- data/lib/graphql/tracing/platform_tracing.rb +46 -49
- data/lib/graphql/tracing/{prometheus_tracing → prometheus_trace}/graphql_collector.rb +4 -2
- data/lib/graphql/tracing/prometheus_trace.rb +89 -0
- data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
- data/lib/graphql/tracing/scout_trace.rb +72 -0
- data/lib/graphql/tracing/sentry_trace.rb +112 -0
- data/lib/graphql/tracing/statsd_trace.rb +56 -0
- data/lib/graphql/tracing/trace.rb +76 -0
- data/lib/graphql/tracing.rb +20 -41
- data/lib/graphql/type_kinds.rb +6 -3
- data/lib/graphql/types/big_int.rb +5 -1
- data/lib/graphql/types/int.rb +1 -1
- data/lib/graphql/types/iso_8601_date.rb +17 -6
- data/lib/graphql/types/iso_8601_date_time.rb +12 -1
- data/lib/graphql/types/iso_8601_duration.rb +77 -0
- data/lib/graphql/types/relay/base_connection.rb +16 -6
- data/lib/graphql/types/relay/connection_behaviors.rb +82 -32
- data/lib/graphql/types/relay/edge_behaviors.rb +36 -7
- data/lib/graphql/types/relay/has_node_field.rb +2 -2
- data/lib/graphql/types/relay/has_nodes_field.rb +2 -2
- data/lib/graphql/types/relay/node_behaviors.rb +12 -2
- data/lib/graphql/types/relay/page_info_behaviors.rb +7 -2
- data/lib/graphql/types/relay.rb +0 -3
- data/lib/graphql/types/string.rb +2 -2
- data/lib/graphql/types.rb +1 -0
- data/lib/graphql/unauthorized_error.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +33 -95
- data/readme.md +13 -6
- metadata +102 -185
- data/lib/graphql/analysis/analyze_query.rb +0 -98
- 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/backtrace/legacy_tracer.rb +0 -56
- data/lib/graphql/backwards_compatibility.rb +0 -61
- 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 -436
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
- data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
- 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 -266
- data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
- 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 -240
- 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 -47
- data/lib/graphql/deprecation.rb +0 -13
- 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 -111
- data/lib/graphql/enum_type.rb +0 -129
- data/lib/graphql/execution/execute.rb +0 -333
- data/lib/graphql/execution/flatten.rb +0 -40
- 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 -226
- data/lib/graphql/filter.rb +0 -53
- data/lib/graphql/float_type.rb +0 -2
- data/lib/graphql/function.rb +0 -128
- data/lib/graphql/id_type.rb +0 -2
- data/lib/graphql/input_object_type.rb +0 -138
- data/lib/graphql/int_type.rb +0 -2
- data/lib/graphql/interface_type.rb +0 -72
- 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 -262
- data/lib/graphql/language/parser.y +0 -543
- data/lib/graphql/list_type.rb +0 -80
- data/lib/graphql/non_null_type.rb +0 -71
- data/lib/graphql/object_type.rb +0 -130
- data/lib/graphql/query/arguments.rb +0 -189
- data/lib/graphql/query/arguments_cache.rb +0 -24
- data/lib/graphql/query/executor.rb +0 -52
- 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 -40
- data/lib/graphql/relay/array_connection.rb +0 -83
- data/lib/graphql/relay/base_connection.rb +0 -189
- 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 -106
- data/lib/graphql/relay/node.rb +0 -39
- data/lib/graphql/relay/page_info.rb +0 -7
- data/lib/graphql/relay/relation_connection.rb +0 -188
- data/lib/graphql/relay/type_extensions.rb +0 -32
- data/lib/graphql/scalar_type.rb +0 -91
- data/lib/graphql/schema/base_64_bp.rb +0 -26
- 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 -17
- 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 -131
- data/lib/graphql/schema/middleware_chain.rb +0 -82
- data/lib/graphql/schema/possible_types.rb +0 -44
- data/lib/graphql/schema/rescue_middleware.rb +0 -60
- data/lib/graphql/schema/timeout_middleware.rb +0 -88
- data/lib/graphql/schema/traversal.rb +0 -228
- data/lib/graphql/schema/validation.rb +0 -313
- data/lib/graphql/static_validation/default_visitor.rb +0 -15
- data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
- data/lib/graphql/static_validation/type_stack.rb +0 -216
- data/lib/graphql/string_type.rb +0 -2
- data/lib/graphql/subscriptions/instrumentation.rb +0 -79
- data/lib/graphql/subscriptions/subscription_root.rb +0 -76
- data/lib/graphql/tracing/skylight_tracing.rb +0 -70
- data/lib/graphql/types/relay/default_relay.rb +0 -27
- data/lib/graphql/types/relay/node_field.rb +0 -25
- data/lib/graphql/types/relay/nodes_field.rb +0 -27
- data/lib/graphql/union_type.rb +0 -115
- data/lib/graphql/upgrader/member.rb +0 -937
- data/lib/graphql/upgrader/schema.rb +0 -38
@@ -4,58 +4,119 @@ require 'set'
|
|
4
4
|
|
5
5
|
module GraphQL
|
6
6
|
class Schema
|
7
|
-
# Restrict access to a {GraphQL::Schema} with a user-defined
|
7
|
+
# Restrict access to a {GraphQL::Schema} with a user-defined `visible?` implementations.
|
8
8
|
#
|
9
9
|
# When validating and executing a query, all access to schema members
|
10
10
|
# should go through a warden. If you access the schema directly,
|
11
11
|
# you may show a client something that it shouldn't be allowed to see.
|
12
12
|
#
|
13
|
-
# @example Hidding private fields
|
14
|
-
# private_members = -> (member, ctx) { member.metadata[:private] }
|
15
|
-
# result = Schema.execute(query_string, except: private_members)
|
16
|
-
#
|
17
|
-
# @example Custom filter implementation
|
18
|
-
# # It must respond to `#call(member)`.
|
19
|
-
# class MissingRequiredFlags
|
20
|
-
# def initialize(user)
|
21
|
-
# @user = user
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# # Return `false` if any required flags are missing
|
25
|
-
# def call(member, ctx)
|
26
|
-
# member.metadata[:required_flags].any? do |flag|
|
27
|
-
# !@user.has_flag?(flag)
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# # Then, use the custom filter in query:
|
33
|
-
# missing_required_flags = MissingRequiredFlags.new(current_user)
|
34
|
-
#
|
35
|
-
# # This query can only access members which match the user's flags
|
36
|
-
# result = Schema.execute(query_string, except: missing_required_flags)
|
37
|
-
#
|
38
13
|
# @api private
|
39
14
|
class Warden
|
40
|
-
|
15
|
+
def self.from_context(context)
|
16
|
+
context.warden || PassThruWarden
|
17
|
+
rescue NoMethodError
|
18
|
+
# this might be a hash which won't respond to #warden
|
19
|
+
PassThruWarden
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param visibility_method [Symbol] a Warden method to call for this entry
|
23
|
+
# @param entry [Object, Array<Object>] One or more definitions for a given name in a GraphQL Schema
|
24
|
+
# @param context [GraphQL::Query::Context]
|
25
|
+
# @param warden [Warden]
|
26
|
+
# @return [Object] `entry` or one of `entry`'s items if exactly one of them is visible for this context
|
27
|
+
# @return [nil] If neither `entry` nor any of `entry`'s items are visible for this context
|
28
|
+
def self.visible_entry?(visibility_method, entry, context, warden = Warden.from_context(context))
|
29
|
+
if entry.is_a?(Array)
|
30
|
+
visible_item = nil
|
31
|
+
entry.each do |item|
|
32
|
+
if warden.public_send(visibility_method, item, context)
|
33
|
+
if visible_item.nil?
|
34
|
+
visible_item = item
|
35
|
+
else
|
36
|
+
raise DuplicateNamesError.new(
|
37
|
+
duplicated_name: item.path, duplicated_definition_1: visible_item.inspect, duplicated_definition_2: item.inspect
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
visible_item
|
43
|
+
elsif warden.public_send(visibility_method, entry, context)
|
44
|
+
entry
|
45
|
+
else
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# This is used when a caller provides a Hash for context.
|
51
|
+
# We want to call the schema's hooks, but we don't have a full-blown warden.
|
52
|
+
# The `context` arguments to these methods exist purely to simplify the code that
|
53
|
+
# calls methods on this object, so it will have everything it needs.
|
54
|
+
class PassThruWarden
|
55
|
+
class << self
|
56
|
+
def visible_field?(field, ctx); field.visible?(ctx); end
|
57
|
+
def visible_argument?(arg, ctx); arg.visible?(ctx); end
|
58
|
+
def visible_type?(type, ctx); type.visible?(ctx); end
|
59
|
+
def visible_enum_value?(ev, ctx); ev.visible?(ctx); end
|
60
|
+
def visible_type_membership?(tm, ctx); tm.visible?(ctx); end
|
61
|
+
def interface_type_memberships(obj_t, ctx); obj_t.interface_type_memberships; end
|
62
|
+
def arguments(owner, ctx); owner.arguments(ctx); end
|
63
|
+
def loadable?(type, ctx); type.visible?(ctx); end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class NullWarden
|
68
|
+
def initialize(_filter = nil, context:, schema:)
|
69
|
+
@schema = schema
|
70
|
+
end
|
71
|
+
|
72
|
+
def visible_field?(field_defn, _ctx = nil, owner = nil); true; end
|
73
|
+
def visible_argument?(arg_defn, _ctx = nil); true; end
|
74
|
+
def visible_type?(type_defn, _ctx = nil); true; end
|
75
|
+
def visible_enum_value?(enum_value, _ctx = nil); true; end
|
76
|
+
def visible_type_membership?(type_membership, _ctx = nil); true; end
|
77
|
+
def interface_type_memberships(obj_type, _ctx = nil); obj_type.interface_type_memberships; end
|
78
|
+
def get_type(type_name); @schema.get_type(type_name); end # rubocop:disable Development/ContextIsPassedCop
|
79
|
+
def arguments(argument_owner, ctx = nil); argument_owner.all_argument_definitions; end
|
80
|
+
def enum_values(enum_defn); enum_defn.enum_values; end # rubocop:disable Development/ContextIsPassedCop
|
81
|
+
def get_argument(parent_type, argument_name); parent_type.get_argument(argument_name); end # rubocop:disable Development/ContextIsPassedCop
|
82
|
+
def types; @schema.types; end # rubocop:disable Development/ContextIsPassedCop
|
83
|
+
def root_type_for_operation(op_name); @schema.root_type_for_operation(op_name); end
|
84
|
+
def directives; @schema.directives.values; end
|
85
|
+
def fields(type_defn); type_defn.all_field_definitions; end # rubocop:disable Development/ContextIsPassedCop
|
86
|
+
def get_field(parent_type, field_name); @schema.get_field(parent_type, field_name); end
|
87
|
+
def reachable_type?(type_name); true; end
|
88
|
+
def loadable?(type, _ctx); true; end
|
89
|
+
def reachable_types; @schema.types.values; end # rubocop:disable Development/ContextIsPassedCop
|
90
|
+
def possible_types(type_defn); @schema.possible_types(type_defn); end
|
91
|
+
def interfaces(obj_type); obj_type.interfaces; end
|
92
|
+
end
|
93
|
+
|
41
94
|
# @param context [GraphQL::Query::Context]
|
42
95
|
# @param schema [GraphQL::Schema]
|
43
|
-
def initialize(
|
44
|
-
@schema = schema
|
96
|
+
def initialize(context:, schema:)
|
97
|
+
@schema = schema
|
45
98
|
# Cache these to avoid repeated hits to the inheritance chain when one isn't present
|
46
99
|
@query = @schema.query
|
47
100
|
@mutation = @schema.mutation
|
48
101
|
@subscription = @schema.subscription
|
49
102
|
@context = context
|
50
|
-
@visibility_cache = read_through { |m|
|
103
|
+
@visibility_cache = read_through { |m| schema.visible?(m, context) }
|
104
|
+
@visibility_cache.compare_by_identity
|
105
|
+
# Initialize all ivars to improve object shape consistency:
|
106
|
+
@types = @visible_types = @reachable_types = @visible_parent_fields =
|
107
|
+
@visible_possible_types = @visible_fields = @visible_arguments = @visible_enum_arrays =
|
108
|
+
@visible_enum_values = @visible_interfaces = @type_visibility = @type_memberships =
|
109
|
+
@visible_and_reachable_type = @unions = @unfiltered_interfaces =
|
110
|
+
@reachable_type_set =
|
111
|
+
nil
|
51
112
|
end
|
52
113
|
|
53
114
|
# @return [Hash<String, GraphQL::BaseType>] Visible types in the schema
|
54
115
|
def types
|
55
116
|
@types ||= begin
|
56
117
|
vis_types = {}
|
57
|
-
@schema.types.each do |n, t|
|
58
|
-
if
|
118
|
+
@schema.types(@context).each do |n, t|
|
119
|
+
if visible_and_reachable_type?(t)
|
59
120
|
vis_types[n] = t
|
60
121
|
end
|
61
122
|
end
|
@@ -63,11 +124,16 @@ module GraphQL
|
|
63
124
|
end
|
64
125
|
end
|
65
126
|
|
127
|
+
# @return [Boolean] True if this type is used for `loads:` but not in the schema otherwise and not _explicitly_ hidden.
|
128
|
+
def loadable?(type, _ctx)
|
129
|
+
!reachable_type_set.include?(type) && visible_type?(type)
|
130
|
+
end
|
131
|
+
|
66
132
|
# @return [GraphQL::BaseType, nil] The type named `type_name`, if it exists (else `nil`)
|
67
133
|
def get_type(type_name)
|
68
134
|
@visible_types ||= read_through do |name|
|
69
|
-
type_defn = @schema.get_type(name)
|
70
|
-
if type_defn &&
|
135
|
+
type_defn = @schema.get_type(name, @context)
|
136
|
+
if type_defn && visible_and_reachable_type?(type_defn)
|
71
137
|
type_defn
|
72
138
|
else
|
73
139
|
nil
|
@@ -84,7 +150,7 @@ module GraphQL
|
|
84
150
|
|
85
151
|
# @return Boolean True if the type is visible and reachable in the schema
|
86
152
|
def reachable_type?(type_name)
|
87
|
-
type = get_type(type_name)
|
153
|
+
type = get_type(type_name) # rubocop:disable Development/ContextIsPassedCop -- `self` is query-aware
|
88
154
|
type && reachable_type_set.include?(type)
|
89
155
|
end
|
90
156
|
|
@@ -92,8 +158,8 @@ module GraphQL
|
|
92
158
|
def get_field(parent_type, field_name)
|
93
159
|
@visible_parent_fields ||= read_through do |type|
|
94
160
|
read_through do |f_name|
|
95
|
-
field_defn = @schema.get_field(type, f_name)
|
96
|
-
if field_defn && visible_field?(
|
161
|
+
field_defn = @schema.get_field(type, f_name, @context)
|
162
|
+
if field_defn && visible_field?(field_defn, nil, type)
|
97
163
|
field_defn
|
98
164
|
else
|
99
165
|
nil
|
@@ -106,15 +172,15 @@ module GraphQL
|
|
106
172
|
|
107
173
|
# @return [GraphQL::Argument, nil] The argument named `argument_name` on `parent_type`, if it exists and is visible
|
108
174
|
def get_argument(parent_type, argument_name)
|
109
|
-
argument = parent_type.get_argument(argument_name)
|
110
|
-
return argument if argument && visible_argument?(argument)
|
175
|
+
argument = parent_type.get_argument(argument_name, @context)
|
176
|
+
return argument if argument && visible_argument?(argument, @context)
|
111
177
|
end
|
112
178
|
|
113
179
|
# @return [Array<GraphQL::BaseType>] The types which may be member of `type_defn`
|
114
180
|
def possible_types(type_defn)
|
115
181
|
@visible_possible_types ||= read_through { |type_defn|
|
116
182
|
pt = @schema.possible_types(type_defn, @context)
|
117
|
-
pt.select { |t|
|
183
|
+
pt.select { |t| visible_and_reachable_type?(t) }
|
118
184
|
}
|
119
185
|
@visible_possible_types[type_defn]
|
120
186
|
end
|
@@ -122,26 +188,52 @@ module GraphQL
|
|
122
188
|
# @param type_defn [GraphQL::ObjectType, GraphQL::InterfaceType]
|
123
189
|
# @return [Array<GraphQL::Field>] Fields on `type_defn`
|
124
190
|
def fields(type_defn)
|
125
|
-
@visible_fields ||= read_through { |t| @schema.get_fields(t
|
191
|
+
@visible_fields ||= read_through { |t| @schema.get_fields(t, @context).values }
|
126
192
|
@visible_fields[type_defn]
|
127
193
|
end
|
128
194
|
|
129
195
|
# @param argument_owner [GraphQL::Field, GraphQL::InputObjectType]
|
130
196
|
# @return [Array<GraphQL::Argument>] Visible arguments on `argument_owner`
|
131
|
-
def arguments(argument_owner)
|
132
|
-
@visible_arguments ||= read_through { |o|
|
197
|
+
def arguments(argument_owner, ctx = nil)
|
198
|
+
@visible_arguments ||= read_through { |o|
|
199
|
+
args = o.arguments(@context)
|
200
|
+
if args.any?
|
201
|
+
args = args.values
|
202
|
+
args.select! { |a| visible_argument?(a, @context) }
|
203
|
+
args
|
204
|
+
else
|
205
|
+
EmptyObjects::EMPTY_ARRAY
|
206
|
+
end
|
207
|
+
}
|
133
208
|
@visible_arguments[argument_owner]
|
134
209
|
end
|
135
210
|
|
136
211
|
# @return [Array<GraphQL::EnumType::EnumValue>] Visible members of `enum_defn`
|
137
212
|
def enum_values(enum_defn)
|
138
|
-
@
|
139
|
-
|
213
|
+
@visible_enum_arrays ||= read_through { |e|
|
214
|
+
values = e.enum_values(@context)
|
215
|
+
if values.size == 0
|
216
|
+
raise GraphQL::Schema::Enum::MissingValuesError.new(e)
|
217
|
+
end
|
218
|
+
values
|
219
|
+
}
|
220
|
+
@visible_enum_arrays[enum_defn]
|
221
|
+
end
|
222
|
+
|
223
|
+
def visible_enum_value?(enum_value, _ctx = nil)
|
224
|
+
@visible_enum_values ||= read_through { |ev| visible?(ev) }
|
225
|
+
@visible_enum_values[enum_value]
|
140
226
|
end
|
141
227
|
|
142
228
|
# @return [Array<GraphQL::InterfaceType>] Visible interfaces implemented by `obj_type`
|
143
229
|
def interfaces(obj_type)
|
144
|
-
@visible_interfaces ||= read_through { |t|
|
230
|
+
@visible_interfaces ||= read_through { |t|
|
231
|
+
ints = t.interfaces(@context)
|
232
|
+
if ints.any?
|
233
|
+
ints.select! { |i| visible_type?(i) }
|
234
|
+
end
|
235
|
+
ints
|
236
|
+
}
|
145
237
|
@visible_interfaces[obj_type]
|
146
238
|
end
|
147
239
|
|
@@ -158,25 +250,74 @@ module GraphQL
|
|
158
250
|
end
|
159
251
|
end
|
160
252
|
|
161
|
-
|
162
|
-
|
163
|
-
def union_memberships(obj_type)
|
164
|
-
@unions ||= read_through { |obj_type| @schema.union_memberships(obj_type).select { |u| visible?(u) } }
|
165
|
-
@unions[obj_type]
|
166
|
-
end
|
167
|
-
|
168
|
-
def visible_argument?(arg_defn)
|
169
|
-
visible?(arg_defn) && visible_type?(arg_defn.type.unwrap)
|
170
|
-
end
|
171
|
-
|
172
|
-
def visible_field?(owner_type, field_defn)
|
253
|
+
# @param owner [Class, Module] If provided, confirm that field has the given owner.
|
254
|
+
def visible_field?(field_defn, _ctx = nil, owner = field_defn.owner)
|
173
255
|
# This field is visible in its own right
|
174
256
|
visible?(field_defn) &&
|
175
257
|
# This field's return type is visible
|
176
|
-
|
258
|
+
visible_and_reachable_type?(field_defn.type.unwrap) &&
|
177
259
|
# This field is either defined on this object type,
|
178
260
|
# or the interface it's inherited from is also visible
|
179
|
-
((field_defn.respond_to?(:owner) && field_defn.owner ==
|
261
|
+
((field_defn.respond_to?(:owner) && field_defn.owner == owner) || field_on_visible_interface?(field_defn, owner))
|
262
|
+
end
|
263
|
+
|
264
|
+
def visible_argument?(arg_defn, _ctx = nil)
|
265
|
+
visible?(arg_defn) && visible_and_reachable_type?(arg_defn.type.unwrap)
|
266
|
+
end
|
267
|
+
|
268
|
+
def visible_type?(type_defn, _ctx = nil)
|
269
|
+
@type_visibility ||= read_through { |type_defn| visible?(type_defn) }
|
270
|
+
@type_visibility[type_defn]
|
271
|
+
end
|
272
|
+
|
273
|
+
def visible_type_membership?(type_membership, _ctx = nil)
|
274
|
+
visible?(type_membership)
|
275
|
+
end
|
276
|
+
|
277
|
+
def interface_type_memberships(obj_type, _ctx = nil)
|
278
|
+
@type_memberships ||= read_through do |obj_t|
|
279
|
+
obj_t.interface_type_memberships
|
280
|
+
end
|
281
|
+
@type_memberships[obj_type]
|
282
|
+
end
|
283
|
+
|
284
|
+
private
|
285
|
+
|
286
|
+
def visible_and_reachable_type?(type_defn)
|
287
|
+
@visible_and_reachable_type ||= read_through do |type_defn|
|
288
|
+
next false unless visible_type?(type_defn)
|
289
|
+
next true if root_type?(type_defn) || type_defn.introspection?
|
290
|
+
|
291
|
+
if type_defn.kind.union?
|
292
|
+
possible_types(type_defn).any? && (referenced?(type_defn) || orphan_type?(type_defn))
|
293
|
+
elsif type_defn.kind.interface?
|
294
|
+
if possible_types(type_defn).any?
|
295
|
+
true
|
296
|
+
else
|
297
|
+
if @context.respond_to?(:logger) && (logger = @context.logger)
|
298
|
+
logger.debug { "Interface `#{type_defn.graphql_name}` hidden because it has no visible implementors" }
|
299
|
+
end
|
300
|
+
false
|
301
|
+
end
|
302
|
+
else
|
303
|
+
if referenced?(type_defn)
|
304
|
+
true
|
305
|
+
elsif type_defn.kind.object?
|
306
|
+
# Show this object if it belongs to ...
|
307
|
+
interfaces(type_defn).any? { |t| referenced?(t) } || # an interface which is referenced in the schema
|
308
|
+
union_memberships(type_defn).any? { |t| referenced?(t) || orphan_type?(t) } # or a union which is referenced or added via orphan_types
|
309
|
+
else
|
310
|
+
false
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
@visible_and_reachable_type[type_defn]
|
316
|
+
end
|
317
|
+
|
318
|
+
def union_memberships(obj_type)
|
319
|
+
@unions ||= read_through { |obj_type| @schema.union_memberships(obj_type).select { |u| visible?(u) } }
|
320
|
+
@unions[obj_type]
|
180
321
|
end
|
181
322
|
|
182
323
|
# We need this to tell whether a field was inherited by an interface
|
@@ -195,10 +336,10 @@ module GraphQL
|
|
195
336
|
any_interface_has_visible_field = false
|
196
337
|
ints = unfiltered_interfaces(type_defn)
|
197
338
|
ints.each do |interface_type|
|
198
|
-
if (iface_field_defn = interface_type.get_field(field_defn.graphql_name))
|
339
|
+
if (iface_field_defn = interface_type.get_field(field_defn.graphql_name, @context))
|
199
340
|
any_interface_has_field = true
|
200
341
|
|
201
|
-
if interfaces(type_defn).include?(interface_type) && visible_field?(
|
342
|
+
if interfaces(type_defn).include?(interface_type) && visible_field?(iface_field_defn, nil, interface_type)
|
202
343
|
any_interface_has_visible_field = true
|
203
344
|
end
|
204
345
|
end
|
@@ -215,23 +356,6 @@ module GraphQL
|
|
215
356
|
end
|
216
357
|
end
|
217
358
|
|
218
|
-
def visible_type?(type_defn)
|
219
|
-
@type_visibility ||= read_through do |type_defn|
|
220
|
-
next false unless visible?(type_defn)
|
221
|
-
next true if root_type?(type_defn) || type_defn.introspection?
|
222
|
-
|
223
|
-
if type_defn.kind.union?
|
224
|
-
visible_possible_types?(type_defn) && (referenced?(type_defn) || orphan_type?(type_defn))
|
225
|
-
elsif type_defn.kind.interface?
|
226
|
-
visible_possible_types?(type_defn)
|
227
|
-
else
|
228
|
-
referenced?(type_defn) || visible_abstract_type?(type_defn)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
@type_visibility[type_defn]
|
233
|
-
end
|
234
|
-
|
235
359
|
def root_type?(type_defn)
|
236
360
|
@query == type_defn ||
|
237
361
|
@mutation == type_defn ||
|
@@ -239,41 +363,30 @@ module GraphQL
|
|
239
363
|
end
|
240
364
|
|
241
365
|
def referenced?(type_defn)
|
242
|
-
@references_to ||= @schema.references_to
|
243
366
|
graphql_name = type_defn.unwrap.graphql_name
|
244
|
-
members = @references_to
|
367
|
+
members = @schema.references_to(graphql_name)
|
245
368
|
members.any? { |m| visible?(m) }
|
246
369
|
end
|
247
370
|
|
248
|
-
NO_REFERENCES = [].freeze
|
249
|
-
|
250
371
|
def orphan_type?(type_defn)
|
251
372
|
@schema.orphan_types.include?(type_defn)
|
252
373
|
end
|
253
374
|
|
254
|
-
def visible_abstract_type?(type_defn)
|
255
|
-
type_defn.kind.object? && (
|
256
|
-
interfaces(type_defn).any? ||
|
257
|
-
union_memberships(type_defn).any?
|
258
|
-
)
|
259
|
-
end
|
260
|
-
|
261
|
-
def visible_possible_types?(type_defn)
|
262
|
-
possible_types(type_defn).any? { |t| visible_type?(t) }
|
263
|
-
end
|
264
|
-
|
265
375
|
def visible?(member)
|
266
376
|
@visibility_cache[member]
|
267
377
|
end
|
268
378
|
|
269
379
|
def read_through
|
270
|
-
Hash.new { |h, k| h[k] = yield(k) }
|
380
|
+
h = Hash.new { |h, k| h[k] = yield(k) }
|
381
|
+
h.compare_by_identity
|
382
|
+
h
|
271
383
|
end
|
272
384
|
|
273
385
|
def reachable_type_set
|
274
|
-
return @reachable_type_set if
|
386
|
+
return @reachable_type_set if @reachable_type_set
|
275
387
|
|
276
388
|
@reachable_type_set = Set.new
|
389
|
+
rt_hash = {}
|
277
390
|
|
278
391
|
unvisited_types = []
|
279
392
|
['query', 'mutation', 'subscription'].each do |op_name|
|
@@ -283,62 +396,76 @@ module GraphQL
|
|
283
396
|
unvisited_types.concat(@schema.introspection_system.types.values)
|
284
397
|
|
285
398
|
directives.each do |dir_class|
|
286
|
-
dir_class.
|
399
|
+
arguments(dir_class).each do |arg_defn|
|
287
400
|
arg_t = arg_defn.type.unwrap
|
288
|
-
if get_type(arg_t.graphql_name)
|
401
|
+
if get_type(arg_t.graphql_name) # rubocop:disable Development/ContextIsPassedCop -- `self` is query-aware
|
289
402
|
unvisited_types << arg_t
|
290
403
|
end
|
291
404
|
end
|
292
405
|
end
|
293
406
|
|
294
407
|
@schema.orphan_types.each do |orphan_type|
|
295
|
-
if get_type(orphan_type.graphql_name)
|
408
|
+
if get_type(orphan_type.graphql_name) == orphan_type # rubocop:disable Development/ContextIsPassedCop -- `self` is query-aware
|
296
409
|
unvisited_types << orphan_type
|
297
410
|
end
|
298
411
|
end
|
299
412
|
|
413
|
+
included_interface_possible_types_set = Set.new
|
414
|
+
|
300
415
|
until unvisited_types.empty?
|
301
416
|
type = unvisited_types.pop
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
417
|
+
visit_type(type, unvisited_types, @reachable_type_set, rt_hash, included_interface_possible_types_set, include_interface_possible_types: false)
|
418
|
+
end
|
419
|
+
|
420
|
+
@reachable_type_set
|
421
|
+
end
|
422
|
+
|
423
|
+
def visit_type(type, unvisited_types, visited_type_set, type_by_name_hash, included_interface_possible_types_set, include_interface_possible_types:)
|
424
|
+
if visited_type_set.add?(type) || (include_interface_possible_types && type.kind.interface? && included_interface_possible_types_set.add?(type))
|
425
|
+
type_by_name = type_by_name_hash[type.graphql_name] ||= type
|
426
|
+
if type_by_name != type
|
427
|
+
name_1, name_2 = [type.inspect, type_by_name.inspect].sort
|
428
|
+
raise DuplicateNamesError.new(
|
429
|
+
duplicated_name: type.graphql_name, duplicated_definition_1: name_1, duplicated_definition_2: name_2
|
430
|
+
)
|
431
|
+
end
|
432
|
+
if type.kind.input_object?
|
433
|
+
# recurse into visible arguments
|
434
|
+
arguments(type).each do |argument|
|
435
|
+
argument_type = argument.type.unwrap
|
436
|
+
unvisited_types << argument_type
|
437
|
+
end
|
438
|
+
elsif type.kind.union?
|
439
|
+
# recurse into visible possible types
|
440
|
+
possible_types(type).each do |possible_type|
|
441
|
+
unvisited_types << possible_type
|
442
|
+
end
|
443
|
+
elsif type.kind.fields?
|
444
|
+
if type.kind.object?
|
445
|
+
# recurse into visible implemented interfaces
|
446
|
+
interfaces(type).each do |interface|
|
447
|
+
unvisited_types << interface
|
313
448
|
end
|
314
|
-
elsif
|
315
|
-
|
316
|
-
|
317
|
-
possible_types(type).each do |possible_type|
|
318
|
-
unvisited_types << possible_type
|
319
|
-
end
|
320
|
-
elsif type.kind.object?
|
321
|
-
# recurse into visible implemented interfaces
|
322
|
-
interfaces(type).each do |interface|
|
323
|
-
unvisited_types << interface
|
324
|
-
end
|
449
|
+
elsif include_interface_possible_types
|
450
|
+
possible_types(type).each do |pt|
|
451
|
+
unvisited_types << pt
|
325
452
|
end
|
453
|
+
end
|
454
|
+
# Don't visit interface possible types -- it's not enough to justify visibility
|
326
455
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
456
|
+
# recurse into visible fields
|
457
|
+
fields(type).each do |field|
|
458
|
+
field_type = field.type.unwrap
|
459
|
+
# In this case, if it's an interface, we want to include
|
460
|
+
visit_type(field_type, unvisited_types, visited_type_set, type_by_name_hash, included_interface_possible_types_set, include_interface_possible_types: true)
|
461
|
+
# recurse into visible arguments
|
462
|
+
arguments(field).each do |argument|
|
463
|
+
argument_type = argument.type.unwrap
|
464
|
+
unvisited_types << argument_type
|
336
465
|
end
|
337
466
|
end
|
338
467
|
end
|
339
468
|
end
|
340
|
-
|
341
|
-
@reachable_type_set
|
342
469
|
end
|
343
470
|
end
|
344
471
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
module GraphQL
|
4
4
|
class Schema
|
5
5
|
class Wrapper
|
6
|
-
include GraphQL::Schema::Member::CachedGraphQLDefinition
|
7
6
|
include GraphQL::Schema::Member::TypeSystemHelpers
|
8
7
|
|
9
8
|
# @return [Class, Module] The inner type of this wrapping type, the type of which one or more objects may be present.
|
@@ -13,10 +12,6 @@ module GraphQL
|
|
13
12
|
@of_type = of_type
|
14
13
|
end
|
15
14
|
|
16
|
-
def to_graphql
|
17
|
-
raise GraphQL::RequiredImplementationMissingError
|
18
|
-
end
|
19
|
-
|
20
15
|
def unwrap
|
21
16
|
@of_type.unwrap
|
22
17
|
end
|