graphql 1.12.12 → 2.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/core.rb +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 +60 -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 +8 -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 +22 -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/analyzer.rb +89 -0
- data/lib/graphql/analysis/field_usage.rb +65 -28
- data/lib/graphql/analysis/max_query_complexity.rb +11 -17
- data/lib/graphql/analysis/max_query_depth.rb +13 -19
- data/lib/graphql/analysis/query_complexity.rb +156 -61
- data/lib/graphql/analysis/query_depth.rb +38 -23
- data/lib/graphql/analysis/visitor.rb +283 -0
- data/lib/graphql/analysis.rb +90 -6
- data/lib/graphql/autoload.rb +38 -0
- data/lib/graphql/backtrace/inspect_result.rb +0 -12
- 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/current.rb +52 -0
- data/lib/graphql/dataloader/async_dataloader.rb +89 -0
- data/lib/graphql/dataloader/null_dataloader.rb +4 -2
- data/lib/graphql/dataloader/request.rb +5 -0
- data/lib/graphql/dataloader/source.rb +125 -33
- data/lib/graphql/dataloader.rb +193 -143
- 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/argument_value.rb +5 -1
- data/lib/graphql/execution/interpreter/arguments.rb +2 -2
- data/lib/graphql/execution/interpreter/arguments_cache.rb +33 -36
- data/lib/graphql/execution/interpreter/resolve.rb +38 -4
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +175 -0
- data/lib/graphql/execution/interpreter/runtime.rb +447 -403
- data/lib/graphql/execution/interpreter.rb +126 -80
- data/lib/graphql/execution/lazy.rb +11 -21
- data/lib/graphql/execution/lookahead.rb +133 -55
- 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 +6 -4
- 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 +4 -4
- data/lib/graphql/introspection/input_value_type.rb +10 -4
- data/lib/graphql/introspection/schema_type.rb +17 -15
- data/lib/graphql/introspection/type_type.rb +29 -16
- data/lib/graphql/introspection.rb +6 -2
- data/lib/graphql/invalid_null_error.rb +1 -1
- data/lib/graphql/language/block_string.rb +37 -25
- data/lib/graphql/language/cache.rb +13 -0
- data/lib/graphql/language/comment.rb +18 -0
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/document_from_schema_definition.rb +122 -81
- data/lib/graphql/language/lexer.rb +364 -1467
- data/lib/graphql/language/nodes.rb +197 -106
- data/lib/graphql/language/parser.rb +799 -1920
- data/lib/graphql/language/printer.rb +372 -160
- data/lib/graphql/language/sanitized_printer.rb +25 -27
- data/lib/graphql/language/static_visitor.rb +167 -0
- data/lib/graphql/language/visitor.rb +188 -141
- data/lib/graphql/language.rb +62 -1
- 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 +146 -222
- data/lib/graphql/query/input_validation_result.rb +10 -1
- data/lib/graphql/query/null_context.rb +15 -32
- data/lib/graphql/query/validation_pipeline.rb +15 -39
- data/lib/graphql/query/variable_validation_error.rb +3 -3
- data/lib/graphql/query/variables.rb +35 -17
- data/lib/graphql/query.rb +149 -82
- data/lib/graphql/railtie.rb +15 -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/graphql/field_type_in_block.rb +144 -0
- data/lib/graphql/rubocop/graphql/root_types_in_block.rb +38 -0
- data/lib/graphql/rubocop.rb +6 -0
- data/lib/graphql/schema/addition.rb +98 -54
- data/lib/graphql/schema/always_visible.rb +14 -0
- data/lib/graphql/schema/argument.rb +179 -82
- data/lib/graphql/schema/base_64_encoder.rb +3 -5
- data/lib/graphql/schema/build_from_definition.rb +77 -39
- data/lib/graphql/schema/directive/feature.rb +1 -1
- data/lib/graphql/schema/directive/flagged.rb +4 -4
- 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 +36 -22
- data/lib/graphql/schema/enum.rb +158 -63
- data/lib/graphql/schema/enum_value.rb +12 -21
- data/lib/graphql/schema/field/connection_extension.rb +7 -17
- data/lib/graphql/schema/field/scope_extension.rb +8 -1
- data/lib/graphql/schema/field.rb +521 -359
- 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 +160 -0
- data/lib/graphql/schema/input_object.rb +148 -99
- data/lib/graphql/schema/interface.rb +41 -64
- data/lib/graphql/schema/introspection_system.rb +12 -26
- data/lib/graphql/schema/late_bound_type.rb +12 -2
- data/lib/graphql/schema/list.rb +18 -7
- data/lib/graphql/schema/loader.rb +6 -5
- data/lib/graphql/schema/member/base_dsl_methods.rb +32 -18
- data/lib/graphql/schema/member/build_type.rb +16 -13
- data/lib/graphql/schema/member/has_arguments.rb +270 -86
- 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 +169 -31
- data/lib/graphql/schema/member/has_interfaces.rb +143 -0
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +5 -1
- 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 +16 -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 +7 -9
- data/lib/graphql/schema/non_null.rb +7 -7
- data/lib/graphql/schema/object.rb +38 -119
- data/lib/graphql/schema/printer.rb +24 -25
- data/lib/graphql/schema/relay_classic_mutation.rb +13 -91
- data/lib/graphql/schema/resolver/has_payload_type.rb +46 -11
- data/lib/graphql/schema/resolver.rb +118 -115
- data/lib/graphql/schema/scalar.rb +20 -21
- data/lib/graphql/schema/subscription.rb +95 -21
- data/lib/graphql/schema/timeout.rb +25 -29
- data/lib/graphql/schema/type_expression.rb +2 -2
- data/lib/graphql/schema/type_membership.rb +21 -4
- data/lib/graphql/schema/union.rb +16 -16
- data/lib/graphql/schema/unique_within_type.rb +1 -1
- data/lib/graphql/schema/validator/all_validator.rb +62 -0
- 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 +56 -18
- data/lib/graphql/schema/validator.rb +38 -28
- data/lib/graphql/schema/visibility/migration.rb +188 -0
- data/lib/graphql/schema/visibility/profile.rb +359 -0
- data/lib/graphql/schema/visibility/visit.rb +190 -0
- data/lib/graphql/schema/visibility.rb +294 -0
- data/lib/graphql/schema/warden.rb +423 -134
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +1015 -1057
- data/lib/graphql/static_validation/all_rules.rb +3 -1
- data/lib/graphql/static_validation/base_visitor.rb +15 -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 +24 -7
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +1 -1
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +4 -3
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +13 -7
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +15 -13
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +12 -2
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +13 -5
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +62 -35
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +25 -4
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +12 -2
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +2 -2
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +1 -1
- 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 +7 -5
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -5
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +14 -8
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +18 -27
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +14 -8
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +11 -2
- data/lib/graphql/static_validation/validation_context.rb +32 -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 +49 -11
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +40 -1
- data/lib/graphql/subscriptions/event.rb +87 -38
- data/lib/graphql/subscriptions/serialize.rb +27 -3
- data/lib/graphql/subscriptions.rb +63 -49
- data/lib/graphql/testing/helpers.rb +155 -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 +253 -0
- data/lib/graphql/tracing/appoptics_tracing.rb +4 -2
- data/lib/graphql/tracing/appsignal_trace.rb +79 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +17 -0
- data/lib/graphql/tracing/call_legacy_tracers.rb +66 -0
- data/lib/graphql/tracing/data_dog_trace.rb +185 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +27 -15
- data/lib/graphql/{execution/instrumentation.rb → tracing/legacy_hooks_trace.rb} +11 -28
- data/lib/graphql/tracing/legacy_trace.rb +12 -0
- data/lib/graphql/tracing/new_relic_trace.rb +77 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +2 -0
- data/lib/graphql/tracing/notifications_trace.rb +45 -0
- data/lib/graphql/tracing/notifications_tracing.rb +61 -0
- data/lib/graphql/tracing/null_trace.rb +9 -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 +6 -2
- data/lib/graphql/tracing/prometheus_trace.rb +94 -0
- data/lib/graphql/tracing/prometheus_tracing.rb +5 -3
- data/lib/graphql/tracing/scout_trace.rb +74 -0
- data/lib/graphql/tracing/scout_tracing.rb +2 -0
- data/lib/graphql/tracing/sentry_trace.rb +114 -0
- data/lib/graphql/tracing/statsd_trace.rb +58 -0
- data/lib/graphql/tracing/statsd_tracing.rb +2 -0
- data/lib/graphql/tracing/trace.rb +79 -0
- data/lib/graphql/tracing.rb +29 -52
- data/lib/graphql/type_kinds.rb +7 -4
- 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 +92 -32
- data/lib/graphql/types/relay/edge_behaviors.rb +46 -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 +11 -2
- data/lib/graphql/types/relay.rb +0 -3
- data/lib/graphql/types/string.rb +2 -2
- data/lib/graphql/types.rb +18 -10
- data/lib/graphql/unauthorized_enum_value_error.rb +13 -0
- data/lib/graphql/unauthorized_error.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +82 -137
- data/readme.md +13 -6
- metadata +127 -186
- data/lib/graphql/analysis/analyze_query.rb +0 -98
- data/lib/graphql/analysis/ast/analyzer.rb +0 -84
- data/lib/graphql/analysis/ast/field_usage.rb +0 -28
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -23
- data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
- data/lib/graphql/analysis/ast/query_complexity.rb +0 -234
- data/lib/graphql/analysis/ast/query_depth.rb +0 -56
- data/lib/graphql/analysis/ast/visitor.rb +0 -268
- data/lib/graphql/analysis/ast.rb +0 -91
- 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/language/token.rb +0 -38
- 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/invalid_type_error.rb +0 -7
- 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
@@ -7,7 +7,6 @@ module GraphQL
|
|
7
7
|
# @return [GraphQL::Schema::Argument, GraphQL::Schema::Field, GraphQL::Schema::Resolver, Class<GraphQL::Schema::InputObject>]
|
8
8
|
attr_reader :validated
|
9
9
|
|
10
|
-
# TODO should this implement `if:` and `unless:` ?
|
11
10
|
# @param validated [GraphQL::Schema::Argument, GraphQL::Schema::Field, GraphQL::Schema::Resolver, Class<GraphQL::Schema::InputObject>] The argument or argument owner this validator is attached to
|
12
11
|
# @param allow_blank [Boolean] if `true`, then objects that respond to `.blank?` and return true for `.blank?` will skip this validation
|
13
12
|
# @param allow_null [Boolean] if `true`, then incoming `null`s will skip this validation
|
@@ -25,26 +24,6 @@ module GraphQL
|
|
25
24
|
raise GraphQL::RequiredImplementationMissingError, "Validator classes should implement #validate"
|
26
25
|
end
|
27
26
|
|
28
|
-
# This is called by the validation system and eventually calls {#validate}.
|
29
|
-
# @api private
|
30
|
-
def apply(object, context, value)
|
31
|
-
if value.nil?
|
32
|
-
if @allow_null
|
33
|
-
nil # skip this
|
34
|
-
else
|
35
|
-
"%{validated} can't be null"
|
36
|
-
end
|
37
|
-
elsif value.respond_to?(:blank?) && value.blank?
|
38
|
-
if @allow_blank
|
39
|
-
nil # skip this
|
40
|
-
else
|
41
|
-
"%{validated} can't be blank"
|
42
|
-
end
|
43
|
-
else
|
44
|
-
validate(object, context, value)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
27
|
# This is like `String#%`, but it supports the case that only some of `string`'s
|
49
28
|
# values are present in `substitutions`
|
50
29
|
def partial_format(string, substitutions)
|
@@ -55,6 +34,12 @@ module GraphQL
|
|
55
34
|
string
|
56
35
|
end
|
57
36
|
|
37
|
+
# @return [Boolean] `true` if `value` is `nil` and this validator has `allow_null: true` or if value is `.blank?` and this validator has `allow_blank: true`
|
38
|
+
def permitted_empty_value?(value)
|
39
|
+
(value.nil? && @allow_null) ||
|
40
|
+
(@allow_blank && value.respond_to?(:blank?) && value.blank?)
|
41
|
+
end
|
42
|
+
|
58
43
|
# @param schema_member [GraphQL::Schema::Field, GraphQL::Schema::Argument, Class<GraphQL::Schema::InputObject>]
|
59
44
|
# @param validates_hash [Hash{Symbol => Hash}, Hash{Class => Hash} nil] A configuration passed as `validates:`
|
60
45
|
# @return [Array<Validator>]
|
@@ -62,6 +47,21 @@ module GraphQL
|
|
62
47
|
if validates_hash.nil? || validates_hash.empty?
|
63
48
|
EMPTY_ARRAY
|
64
49
|
else
|
50
|
+
validates_hash = validates_hash.dup
|
51
|
+
|
52
|
+
default_options = {}
|
53
|
+
if validates_hash[:allow_null]
|
54
|
+
default_options[:allow_null] = validates_hash.delete(:allow_null)
|
55
|
+
end
|
56
|
+
if validates_hash[:allow_blank]
|
57
|
+
default_options[:allow_blank] = validates_hash.delete(:allow_blank)
|
58
|
+
end
|
59
|
+
|
60
|
+
# allow_nil or allow_blank are the _only_ validations:
|
61
|
+
if validates_hash.empty?
|
62
|
+
validates_hash = default_options
|
63
|
+
end
|
64
|
+
|
65
65
|
validates_hash.map do |validator_name, options|
|
66
66
|
validator_class = case validator_name
|
67
67
|
when Class
|
@@ -69,7 +69,11 @@ module GraphQL
|
|
69
69
|
else
|
70
70
|
all_validators[validator_name] || raise(ArgumentError, "unknown validation: #{validator_name.inspect}")
|
71
71
|
end
|
72
|
-
|
72
|
+
if options.is_a?(Hash)
|
73
|
+
validator_class.new(validated: schema_member, **(default_options.merge(options)))
|
74
|
+
else
|
75
|
+
validator_class.new(options, validated: schema_member, **default_options)
|
76
|
+
end
|
73
77
|
end
|
74
78
|
end
|
75
79
|
end
|
@@ -98,7 +102,7 @@ module GraphQL
|
|
98
102
|
|
99
103
|
self.all_validators = {}
|
100
104
|
|
101
|
-
include
|
105
|
+
include GraphQL::EmptyObjects
|
102
106
|
|
103
107
|
class ValidationFailedError < GraphQL::ExecutionError
|
104
108
|
attr_reader :errors
|
@@ -122,14 +126,14 @@ module GraphQL
|
|
122
126
|
|
123
127
|
validators.each do |validator|
|
124
128
|
validated = as || validator.validated
|
125
|
-
errors = validator.
|
129
|
+
errors = validator.validate(object, context, value)
|
126
130
|
if errors &&
|
127
|
-
|
128
|
-
|
131
|
+
(errors.is_a?(Array) && errors != EMPTY_ARRAY) ||
|
132
|
+
(errors.is_a?(String))
|
129
133
|
if all_errors.frozen? # It's empty
|
130
134
|
all_errors = []
|
131
135
|
end
|
132
|
-
interpolation_vars = { validated: validated.graphql_name }
|
136
|
+
interpolation_vars = { validated: validated.graphql_name, value: value.inspect }
|
133
137
|
if errors.is_a?(String)
|
134
138
|
all_errors << (errors % interpolation_vars)
|
135
139
|
else
|
@@ -139,7 +143,7 @@ module GraphQL
|
|
139
143
|
end
|
140
144
|
end
|
141
145
|
|
142
|
-
if all_errors.
|
146
|
+
if !all_errors.empty?
|
143
147
|
raise ValidationFailedError.new(errors: all_errors)
|
144
148
|
end
|
145
149
|
nil
|
@@ -161,3 +165,9 @@ require "graphql/schema/validator/exclusion_validator"
|
|
161
165
|
GraphQL::Schema::Validator.install(:exclusion, GraphQL::Schema::Validator::ExclusionValidator)
|
162
166
|
require "graphql/schema/validator/required_validator"
|
163
167
|
GraphQL::Schema::Validator.install(:required, GraphQL::Schema::Validator::RequiredValidator)
|
168
|
+
require "graphql/schema/validator/allow_null_validator"
|
169
|
+
GraphQL::Schema::Validator.install(:allow_null, GraphQL::Schema::Validator::AllowNullValidator)
|
170
|
+
require "graphql/schema/validator/allow_blank_validator"
|
171
|
+
GraphQL::Schema::Validator.install(:allow_blank, GraphQL::Schema::Validator::AllowBlankValidator)
|
172
|
+
require "graphql/schema/validator/all_validator"
|
173
|
+
GraphQL::Schema::Validator.install(:all, GraphQL::Schema::Validator::AllValidator)
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
class Visibility
|
5
|
+
# You can use this to see how {GraphQL::Schema::Warden} and {GraphQL::Schema::Visibility::Profile}
|
6
|
+
# handle `.visible?` differently in your schema.
|
7
|
+
#
|
8
|
+
# It runs the same method on both implementations and raises an error when the results diverge.
|
9
|
+
#
|
10
|
+
# To fix the error, modify your schema so that both implementations return the same thing.
|
11
|
+
# Or, open an issue on GitHub to discuss the difference.
|
12
|
+
#
|
13
|
+
# This plugin adds overhead to runtime and may cause unexpected crashes -- **don't** use it in production!
|
14
|
+
#
|
15
|
+
# This plugin adds two keys to `context` when running:
|
16
|
+
#
|
17
|
+
# - `visibility_migration_running: true`
|
18
|
+
# - For the {Schema::Warden} which it instantiates, it adds `visibility_migration_warden_running: true`.
|
19
|
+
#
|
20
|
+
# Use those keys to modify your `visible?` behavior as needed.
|
21
|
+
#
|
22
|
+
# Also, in a pinch, you can set `skip_visibility_migration_error: true` in context to turn off this behavior per-query.
|
23
|
+
# (In that case, it uses {Profile} directly.)
|
24
|
+
#
|
25
|
+
# @example Adding this plugin
|
26
|
+
#
|
27
|
+
# use GraphQL::Schema::Visibility, migration_errors: true
|
28
|
+
#
|
29
|
+
class Migration < GraphQL::Schema::Visibility::Profile
|
30
|
+
class RuntimeTypesMismatchError < GraphQL::Error
|
31
|
+
def initialize(method_called, warden_result, profile_result, method_args)
|
32
|
+
super(<<~ERR)
|
33
|
+
Mismatch in types for `##{method_called}(#{method_args.map(&:inspect).join(", ")})`:
|
34
|
+
|
35
|
+
#{compare_results(warden_result, profile_result)}
|
36
|
+
|
37
|
+
Update your `.visible?` implementation to make these implementations return the same value.
|
38
|
+
|
39
|
+
See: https://graphql-ruby.org/authorization/visibility_migration.html
|
40
|
+
ERR
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def compare_results(warden_result, profile_result)
|
45
|
+
if warden_result.is_a?(Array) && profile_result.is_a?(Array)
|
46
|
+
all_results = warden_result | profile_result
|
47
|
+
all_results.sort_by!(&:graphql_name)
|
48
|
+
|
49
|
+
entries_text = all_results.map { |entry| "#{entry.graphql_name} (#{entry})"}
|
50
|
+
width = entries_text.map(&:size).max
|
51
|
+
yes = " ✔ "
|
52
|
+
no = " "
|
53
|
+
res = "".dup
|
54
|
+
res << "#{"Result".center(width)} Warden Profile \n"
|
55
|
+
all_results.each_with_index do |entry, idx|
|
56
|
+
res << "#{entries_text[idx].ljust(width)}#{warden_result.include?(entry) ? yes : no}#{profile_result.include?(entry) ? yes : no}\n"
|
57
|
+
end
|
58
|
+
res << "\n"
|
59
|
+
else
|
60
|
+
"- Warden returned: #{humanize(warden_result)}\n\n- Visibility::Profile returned: #{humanize(profile_result)}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
def humanize(val)
|
64
|
+
case val
|
65
|
+
when Array
|
66
|
+
"#{val.size}: #{val.map { |v| humanize(v) }.sort.inspect}"
|
67
|
+
when Module
|
68
|
+
if val.respond_to?(:graphql_name)
|
69
|
+
"#{val.graphql_name} (#{val.inspect})"
|
70
|
+
else
|
71
|
+
val.inspect
|
72
|
+
end
|
73
|
+
else
|
74
|
+
val.inspect
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def initialize(context:, schema:, name: nil)
|
80
|
+
@name = name
|
81
|
+
@skip_error = context[:skip_visibility_migration_error] || context.is_a?(Query::NullContext) || context.is_a?(Hash)
|
82
|
+
@profile_types = GraphQL::Schema::Visibility::Profile.new(context: context, schema: schema)
|
83
|
+
if !@skip_error
|
84
|
+
context[:visibility_migration_running] = true
|
85
|
+
warden_ctx_vals = context.to_h.dup
|
86
|
+
warden_ctx_vals[:visibility_migration_warden_running] = true
|
87
|
+
if schema.const_defined?(:WardenCompatSchema, false) # don't use a defn from a superclass
|
88
|
+
warden_schema = schema.const_get(:WardenCompatSchema, false)
|
89
|
+
else
|
90
|
+
warden_schema = Class.new(schema)
|
91
|
+
warden_schema.use_visibility_profile = false
|
92
|
+
# TODO public API
|
93
|
+
warden_schema.send(:add_type_and_traverse, [warden_schema.query, warden_schema.mutation, warden_schema.subscription].compact, root: true)
|
94
|
+
warden_schema.send(:add_type_and_traverse, warden_schema.directives.values + warden_schema.orphan_types, root: false)
|
95
|
+
schema.const_set(:WardenCompatSchema, warden_schema)
|
96
|
+
end
|
97
|
+
warden_ctx = GraphQL::Query::Context.new(query: context.query, values: warden_ctx_vals)
|
98
|
+
warden_ctx.warden = GraphQL::Schema::Warden.new(schema: warden_schema, context: warden_ctx)
|
99
|
+
warden_ctx.warden.skip_warning = true
|
100
|
+
warden_ctx.types = @warden_types = warden_ctx.warden.visibility_profile
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def loaded_types
|
105
|
+
@profile_types.loaded_types
|
106
|
+
end
|
107
|
+
|
108
|
+
PUBLIC_PROFILE_METHODS = [
|
109
|
+
:enum_values,
|
110
|
+
:interfaces,
|
111
|
+
:all_types,
|
112
|
+
:all_types_h,
|
113
|
+
:fields,
|
114
|
+
:loadable?,
|
115
|
+
:loadable_possible_types,
|
116
|
+
:type,
|
117
|
+
:arguments,
|
118
|
+
:argument,
|
119
|
+
:directive_exists?,
|
120
|
+
:directives,
|
121
|
+
:field,
|
122
|
+
:query_root,
|
123
|
+
:mutation_root,
|
124
|
+
:possible_types,
|
125
|
+
:subscription_root,
|
126
|
+
:reachable_type?,
|
127
|
+
:visible_enum_value?,
|
128
|
+
]
|
129
|
+
|
130
|
+
PUBLIC_PROFILE_METHODS.each do |profile_method|
|
131
|
+
define_method(profile_method) do |*args|
|
132
|
+
call_method_and_compare(profile_method, args)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def call_method_and_compare(method, args)
|
137
|
+
res_1 = @profile_types.public_send(method, *args)
|
138
|
+
if @skip_error
|
139
|
+
return res_1
|
140
|
+
end
|
141
|
+
|
142
|
+
res_2 = @warden_types.public_send(method, *args)
|
143
|
+
normalized_res_1 = res_1.is_a?(Array) ? Set.new(res_1) : res_1
|
144
|
+
normalized_res_2 = res_2.is_a?(Array) ? Set.new(res_2) : res_2
|
145
|
+
if !equivalent_schema_members?(normalized_res_1, normalized_res_2)
|
146
|
+
# Raise the errors with the orignally returned values:
|
147
|
+
err = RuntimeTypesMismatchError.new(method, res_2, res_1, args)
|
148
|
+
raise err
|
149
|
+
else
|
150
|
+
res_1
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def equivalent_schema_members?(member1, member2)
|
155
|
+
if member1.class != member2.class
|
156
|
+
return false
|
157
|
+
end
|
158
|
+
|
159
|
+
case member1
|
160
|
+
when Set
|
161
|
+
member1_array = member1.to_a.sort_by(&:graphql_name)
|
162
|
+
member2_array = member2.to_a.sort_by(&:graphql_name)
|
163
|
+
member1_array.each_with_index do |inner_member1, idx|
|
164
|
+
inner_member2 = member2_array[idx]
|
165
|
+
equivalent_schema_members?(inner_member1, inner_member2)
|
166
|
+
end
|
167
|
+
when GraphQL::Schema::Field
|
168
|
+
member1.ensure_loaded
|
169
|
+
member2.ensure_loaded
|
170
|
+
if member1.introspection? && member2.introspection?
|
171
|
+
member1.inspect == member2.inspect
|
172
|
+
else
|
173
|
+
member1 == member2
|
174
|
+
end
|
175
|
+
when Module
|
176
|
+
if member1.introspection? && member2.introspection?
|
177
|
+
member1.graphql_name == member2.graphql_name
|
178
|
+
else
|
179
|
+
member1 == member2
|
180
|
+
end
|
181
|
+
else
|
182
|
+
member1 == member2
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,359 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
class Visibility
|
6
|
+
# This class filters the types, fields, arguments, enum values, and directives in a schema
|
7
|
+
# based on the given `context`.
|
8
|
+
#
|
9
|
+
# It's like {Warden}, but has some differences:
|
10
|
+
#
|
11
|
+
# - It doesn't use {Schema}'s top-level caches (eg {Schema.references_to}, {Schema.possible_types}, {Schema.types})
|
12
|
+
# - It doesn't hide Interface or Union types when all their possible types are hidden. (Instead, those types should implement `.visible?` to hide in that case.)
|
13
|
+
# - It checks `.visible?` on root introspection types
|
14
|
+
# - It can be used to cache profiles by name for re-use across queries
|
15
|
+
class Profile
|
16
|
+
# @return [Schema::Visibility::Profile]
|
17
|
+
def self.from_context(ctx, schema)
|
18
|
+
if ctx.respond_to?(:types) && (types = ctx.types).is_a?(self)
|
19
|
+
types
|
20
|
+
else
|
21
|
+
schema.visibility.profile_for(ctx, nil)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.null_profile(context:, schema:)
|
26
|
+
profile = self.new(name: "NullProfile", context: context, schema: schema)
|
27
|
+
profile.instance_variable_set(:@cached_visible, Hash.new { |k, v| k[v] = true }.compare_by_identity)
|
28
|
+
profile
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Symbol, nil]
|
32
|
+
attr_reader :name
|
33
|
+
|
34
|
+
def initialize(name: nil, context:, schema:)
|
35
|
+
@name = name
|
36
|
+
@context = context
|
37
|
+
@schema = schema
|
38
|
+
@all_types = {}
|
39
|
+
@all_types_loaded = false
|
40
|
+
@unvisited_types = []
|
41
|
+
@all_directives = nil
|
42
|
+
@cached_visible = Hash.new { |h, member| h[member] = @schema.visible?(member, @context) }.compare_by_identity
|
43
|
+
|
44
|
+
@cached_visible_fields = Hash.new { |h, owner|
|
45
|
+
h[owner] = Hash.new do |h2, field|
|
46
|
+
h2[field] = visible_field_for(owner, field)
|
47
|
+
end.compare_by_identity
|
48
|
+
}.compare_by_identity
|
49
|
+
|
50
|
+
@cached_visible_arguments = Hash.new do |h, arg|
|
51
|
+
h[arg] = if @cached_visible[arg] && (arg_type = arg.type.unwrap) && @cached_visible[arg_type]
|
52
|
+
true
|
53
|
+
else
|
54
|
+
false
|
55
|
+
end
|
56
|
+
end.compare_by_identity
|
57
|
+
|
58
|
+
@cached_parent_fields = Hash.new do |h, type|
|
59
|
+
h[type] = Hash.new do |h2, field_name|
|
60
|
+
h2[field_name] = type.get_field(field_name, @context)
|
61
|
+
end
|
62
|
+
end.compare_by_identity
|
63
|
+
|
64
|
+
@cached_parent_arguments = Hash.new do |h, arg_owner|
|
65
|
+
h[arg_owner] = Hash.new do |h2, arg_name|
|
66
|
+
h2[arg_name] = arg_owner.get_argument(arg_name, @context)
|
67
|
+
end
|
68
|
+
end.compare_by_identity
|
69
|
+
|
70
|
+
@cached_possible_types = Hash.new { |h, type| h[type] = possible_types_for(type) }.compare_by_identity
|
71
|
+
|
72
|
+
@cached_enum_values = Hash.new do |h, enum_t|
|
73
|
+
values = non_duplicate_items(enum_t.enum_values(@context), @cached_visible)
|
74
|
+
if values.size == 0
|
75
|
+
raise GraphQL::Schema::Enum::MissingValuesError.new(enum_t)
|
76
|
+
end
|
77
|
+
h[enum_t] = values
|
78
|
+
end.compare_by_identity
|
79
|
+
|
80
|
+
@cached_fields = Hash.new do |h, owner|
|
81
|
+
h[owner] = non_duplicate_items(owner.all_field_definitions.each(&:ensure_loaded), @cached_visible_fields[owner])
|
82
|
+
end.compare_by_identity
|
83
|
+
|
84
|
+
@cached_arguments = Hash.new do |h, owner|
|
85
|
+
h[owner] = non_duplicate_items(owner.all_argument_definitions, @cached_visible_arguments)
|
86
|
+
end.compare_by_identity
|
87
|
+
|
88
|
+
@loadable_possible_types = Hash.new { |h, union_type| h[union_type] = union_type.possible_types }.compare_by_identity
|
89
|
+
end
|
90
|
+
|
91
|
+
def field_on_visible_interface?(field, owner)
|
92
|
+
ints = owner.interface_type_memberships.map(&:abstract_type)
|
93
|
+
field_name = field.graphql_name
|
94
|
+
filtered_ints = interfaces(owner)
|
95
|
+
any_interface_has_field = false
|
96
|
+
any_interface_has_visible_field = false
|
97
|
+
ints.each do |int_t|
|
98
|
+
if (_int_f_defn = @cached_parent_fields[int_t][field_name])
|
99
|
+
any_interface_has_field = true
|
100
|
+
|
101
|
+
if filtered_ints.include?(int_t) # TODO cycles, or maybe not necessary since previously checked? && @cached_visible_fields[owner][field]
|
102
|
+
any_interface_has_visible_field = true
|
103
|
+
break
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if any_interface_has_field
|
109
|
+
any_interface_has_visible_field
|
110
|
+
else
|
111
|
+
true
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def type(type_name)
|
116
|
+
t = @schema.visibility.get_type(type_name) # rubocop:disable Development/ContextIsPassedCop
|
117
|
+
if t
|
118
|
+
if t.is_a?(Array)
|
119
|
+
vis_t = nil
|
120
|
+
t.each do |t_defn|
|
121
|
+
if @cached_visible[t_defn] && referenced?(t_defn)
|
122
|
+
if vis_t.nil?
|
123
|
+
vis_t = t_defn
|
124
|
+
else
|
125
|
+
raise_duplicate_definition(vis_t, t_defn)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
vis_t
|
130
|
+
else
|
131
|
+
if t && @cached_visible[t] && referenced?(t)
|
132
|
+
t
|
133
|
+
else
|
134
|
+
nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def field(owner, field_name)
|
141
|
+
f = if owner.kind.fields? && (field = @cached_parent_fields[owner][field_name])
|
142
|
+
field
|
143
|
+
elsif owner == query_root && (entry_point_field = @schema.introspection_system.entry_point(name: field_name))
|
144
|
+
entry_point_field
|
145
|
+
elsif (dynamic_field = @schema.introspection_system.dynamic_field(name: field_name))
|
146
|
+
dynamic_field
|
147
|
+
else
|
148
|
+
nil
|
149
|
+
end
|
150
|
+
if f.is_a?(Array)
|
151
|
+
visible_f = nil
|
152
|
+
f.each do |f_defn|
|
153
|
+
if @cached_visible_fields[owner][f_defn]
|
154
|
+
|
155
|
+
if visible_f.nil?
|
156
|
+
visible_f = f_defn
|
157
|
+
else
|
158
|
+
raise_duplicate_definition(visible_f, f_defn)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
visible_f.ensure_loaded
|
163
|
+
elsif f && @cached_visible_fields[owner][f.ensure_loaded]
|
164
|
+
f
|
165
|
+
else
|
166
|
+
nil
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def fields(owner)
|
171
|
+
@cached_fields[owner]
|
172
|
+
end
|
173
|
+
|
174
|
+
def arguments(owner)
|
175
|
+
@cached_arguments[owner]
|
176
|
+
end
|
177
|
+
|
178
|
+
def argument(owner, arg_name)
|
179
|
+
arg = @cached_parent_arguments[owner][arg_name]
|
180
|
+
if arg.is_a?(Array)
|
181
|
+
visible_arg = nil
|
182
|
+
arg.each do |arg_defn|
|
183
|
+
if @cached_visible_arguments[arg_defn]
|
184
|
+
if visible_arg.nil?
|
185
|
+
visible_arg = arg_defn
|
186
|
+
else
|
187
|
+
raise_duplicate_definition(visible_arg, arg_defn)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
visible_arg
|
192
|
+
else
|
193
|
+
if arg && @cached_visible_arguments[arg]
|
194
|
+
arg
|
195
|
+
else
|
196
|
+
nil
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def possible_types(type)
|
202
|
+
@cached_possible_types[type]
|
203
|
+
end
|
204
|
+
|
205
|
+
def interfaces(obj_or_int_type)
|
206
|
+
ints = obj_or_int_type.interface_type_memberships
|
207
|
+
.select { |itm| @cached_visible[itm] && @cached_visible[itm.abstract_type] }
|
208
|
+
.map!(&:abstract_type)
|
209
|
+
ints.uniq! # Remove any duplicate interfaces implemented via other interfaces
|
210
|
+
ints
|
211
|
+
end
|
212
|
+
|
213
|
+
def query_root
|
214
|
+
((t = @schema.query) && @cached_visible[t]) ? t : nil
|
215
|
+
end
|
216
|
+
|
217
|
+
def mutation_root
|
218
|
+
((t = @schema.mutation) && @cached_visible[t]) ? t : nil
|
219
|
+
end
|
220
|
+
|
221
|
+
def subscription_root
|
222
|
+
((t = @schema.subscription) && @cached_visible[t]) ? t : nil
|
223
|
+
end
|
224
|
+
|
225
|
+
def all_types
|
226
|
+
load_all_types
|
227
|
+
@all_types.values
|
228
|
+
end
|
229
|
+
|
230
|
+
def all_types_h
|
231
|
+
load_all_types
|
232
|
+
@all_types
|
233
|
+
end
|
234
|
+
|
235
|
+
def enum_values(owner)
|
236
|
+
@cached_enum_values[owner]
|
237
|
+
end
|
238
|
+
|
239
|
+
def directive_exists?(dir_name)
|
240
|
+
directives.any? { |d| d.graphql_name == dir_name }
|
241
|
+
end
|
242
|
+
|
243
|
+
def directives
|
244
|
+
@all_directives ||= @schema.visibility.all_directives.select { |dir|
|
245
|
+
@cached_visible[dir] && @schema.visibility.all_references[dir].any? { |ref| ref == true || (@cached_visible[ref] && referenced?(ref)) }
|
246
|
+
}
|
247
|
+
end
|
248
|
+
|
249
|
+
def loadable?(t, _ctx)
|
250
|
+
load_all_types
|
251
|
+
!@all_types[t.graphql_name] && @cached_visible[t]
|
252
|
+
end
|
253
|
+
|
254
|
+
def loadable_possible_types(t, _ctx)
|
255
|
+
@loadable_possible_types[t]
|
256
|
+
end
|
257
|
+
|
258
|
+
def loaded_types
|
259
|
+
@all_types.values
|
260
|
+
end
|
261
|
+
|
262
|
+
def reachable_type?(type_name)
|
263
|
+
load_all_types
|
264
|
+
!!@all_types[type_name]
|
265
|
+
end
|
266
|
+
|
267
|
+
def visible_enum_value?(enum_value, _ctx = nil)
|
268
|
+
@cached_visible[enum_value]
|
269
|
+
end
|
270
|
+
|
271
|
+
private
|
272
|
+
|
273
|
+
def non_duplicate_items(definitions, visibility_cache)
|
274
|
+
non_dups = []
|
275
|
+
definitions.each do |defn|
|
276
|
+
if visibility_cache[defn]
|
277
|
+
if (dup_defn = non_dups.find { |d| d.graphql_name == defn.graphql_name })
|
278
|
+
raise_duplicate_definition(dup_defn, defn)
|
279
|
+
end
|
280
|
+
non_dups << defn
|
281
|
+
end
|
282
|
+
end
|
283
|
+
non_dups
|
284
|
+
end
|
285
|
+
|
286
|
+
def raise_duplicate_definition(first_defn, second_defn)
|
287
|
+
raise DuplicateNamesError.new(duplicated_name: first_defn.path, duplicated_definition_1: first_defn.inspect, duplicated_definition_2: second_defn.inspect)
|
288
|
+
end
|
289
|
+
|
290
|
+
def load_all_types
|
291
|
+
return if @all_types_loaded
|
292
|
+
@all_types_loaded = true
|
293
|
+
visit = Visibility::Visit.new(@schema) do |member|
|
294
|
+
if member.is_a?(Module) && member.respond_to?(:kind)
|
295
|
+
if @cached_visible[member]
|
296
|
+
type_name = member.graphql_name
|
297
|
+
if (prev_t = @all_types[type_name]) && !prev_t.equal?(member)
|
298
|
+
raise_duplicate_definition(member, prev_t)
|
299
|
+
end
|
300
|
+
@all_types[type_name] = member
|
301
|
+
true
|
302
|
+
else
|
303
|
+
false
|
304
|
+
end
|
305
|
+
else
|
306
|
+
@cached_visible[member]
|
307
|
+
end
|
308
|
+
end
|
309
|
+
visit.visit_each
|
310
|
+
@all_types.delete_if { |type_name, type_defn| !referenced?(type_defn) }
|
311
|
+
nil
|
312
|
+
end
|
313
|
+
|
314
|
+
def referenced?(type_defn)
|
315
|
+
@schema.visibility.all_references[type_defn].any? { |r| r == true || @cached_visible[r] }
|
316
|
+
end
|
317
|
+
|
318
|
+
def possible_types_for(type)
|
319
|
+
case type.kind.name
|
320
|
+
when "INTERFACE"
|
321
|
+
pts = []
|
322
|
+
@schema.visibility.all_interface_type_memberships[type].each do |itm|
|
323
|
+
if @cached_visible[itm] && (ot = itm.object_type) && @cached_visible[ot] && referenced?(ot)
|
324
|
+
pts << ot
|
325
|
+
end
|
326
|
+
end
|
327
|
+
pts
|
328
|
+
when "UNION"
|
329
|
+
pts = []
|
330
|
+
type.type_memberships.each { |tm|
|
331
|
+
if @cached_visible[tm] &&
|
332
|
+
(ot = tm.object_type) &&
|
333
|
+
@cached_visible[ot] &&
|
334
|
+
referenced?(ot)
|
335
|
+
pts << ot
|
336
|
+
end
|
337
|
+
}
|
338
|
+
pts
|
339
|
+
when "OBJECT"
|
340
|
+
if @cached_visible[type]
|
341
|
+
[type]
|
342
|
+
else
|
343
|
+
EmptyObjects::EMPTY_ARRAY
|
344
|
+
end
|
345
|
+
else
|
346
|
+
GraphQL::EmptyObjects::EMPTY_ARRAY
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def visible_field_for(owner, field)
|
351
|
+
@cached_visible[field] &&
|
352
|
+
(ret_type = field.type.unwrap) &&
|
353
|
+
@cached_visible[ret_type] &&
|
354
|
+
(owner == field.owner || (!owner.kind.object?) || field_on_visible_interface?(field, owner))
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|