graphql 1.13.12 → 2.0.21
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/install_generator.rb +1 -1
- data/lib/generators/graphql/relay.rb +3 -17
- data/lib/generators/graphql/templates/schema.erb +3 -0
- data/lib/graphql/analysis/ast/field_usage.rb +3 -1
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
- data/lib/graphql/analysis/ast/query_depth.rb +0 -1
- data/lib/graphql/analysis/ast/visitor.rb +43 -36
- data/lib/graphql/analysis/ast.rb +2 -12
- data/lib/graphql/analysis.rb +0 -7
- data/lib/graphql/backtrace/table.rb +2 -20
- data/lib/graphql/backtrace/trace.rb +96 -0
- data/lib/graphql/backtrace/tracer.rb +2 -3
- data/lib/graphql/backtrace.rb +7 -8
- data/lib/graphql/dataloader/null_dataloader.rb +3 -1
- data/lib/graphql/dataloader/source.rb +9 -0
- data/lib/graphql/dataloader.rb +4 -1
- data/lib/graphql/dig.rb +1 -1
- data/lib/graphql/execution/errors.rb +12 -82
- data/lib/graphql/execution/interpreter/arguments.rb +1 -1
- data/lib/graphql/execution/interpreter/arguments_cache.rb +2 -3
- data/lib/graphql/execution/interpreter/resolve.rb +26 -0
- data/lib/graphql/execution/interpreter/runtime.rb +300 -222
- data/lib/graphql/execution/interpreter.rb +187 -78
- data/lib/graphql/execution/lazy.rb +7 -21
- data/lib/graphql/execution/lookahead.rb +44 -40
- data/lib/graphql/execution/multiplex.rb +3 -174
- data/lib/graphql/execution.rb +11 -4
- data/lib/graphql/filter.rb +7 -2
- data/lib/graphql/introspection/directive_type.rb +2 -2
- data/lib/graphql/introspection/dynamic_fields.rb +3 -8
- data/lib/graphql/introspection/entry_points.rb +2 -15
- data/lib/graphql/introspection/field_type.rb +1 -1
- data/lib/graphql/introspection/schema_type.rb +2 -2
- data/lib/graphql/introspection/type_type.rb +13 -6
- data/lib/graphql/introspection.rb +4 -3
- data/lib/graphql/language/document_from_schema_definition.rb +43 -44
- data/lib/graphql/language/lexer.rb +216 -1488
- data/lib/graphql/language/nodes.rb +66 -40
- data/lib/graphql/language/parser.rb +539 -510
- data/lib/graphql/language/parser.y +53 -44
- data/lib/graphql/language/printer.rb +37 -21
- data/lib/graphql/language/visitor.rb +191 -83
- data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
- data/lib/graphql/pagination/array_connection.rb +4 -2
- data/lib/graphql/pagination/connection.rb +33 -6
- data/lib/graphql/pagination/connections.rb +3 -28
- data/lib/graphql/pagination/relation_connection.rb +2 -0
- data/lib/graphql/query/context.rb +156 -196
- data/lib/graphql/query/input_validation_result.rb +10 -1
- data/lib/graphql/query/null_context.rb +1 -4
- data/lib/graphql/query/validation_pipeline.rb +12 -37
- data/lib/graphql/query/variable_validation_error.rb +2 -2
- data/lib/graphql/query/variables.rb +35 -21
- data/lib/graphql/query.rb +39 -46
- data/lib/graphql/railtie.rb +0 -104
- data/lib/graphql/rake_task/validate.rb +1 -1
- data/lib/graphql/rake_task.rb +29 -1
- data/lib/graphql/relay/range_add.rb +9 -20
- data/lib/graphql/relay.rb +0 -15
- data/lib/graphql/schema/addition.rb +7 -9
- data/lib/graphql/schema/argument.rb +38 -47
- data/lib/graphql/schema/build_from_definition.rb +47 -21
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/transform.rb +1 -1
- data/lib/graphql/schema/directive.rb +12 -23
- data/lib/graphql/schema/enum.rb +29 -41
- data/lib/graphql/schema/enum_value.rb +2 -25
- data/lib/graphql/schema/field/connection_extension.rb +4 -0
- data/lib/graphql/schema/field.rb +256 -349
- data/lib/graphql/schema/field_extension.rb +1 -4
- data/lib/graphql/schema/find_inherited_value.rb +2 -7
- data/lib/graphql/schema/input_object.rb +57 -69
- data/lib/graphql/schema/interface.rb +0 -35
- data/lib/graphql/schema/introspection_system.rb +3 -8
- data/lib/graphql/schema/late_bound_type.rb +8 -2
- data/lib/graphql/schema/list.rb +18 -9
- data/lib/graphql/schema/loader.rb +1 -2
- data/lib/graphql/schema/member/base_dsl_methods.rb +17 -19
- data/lib/graphql/schema/member/build_type.rb +5 -7
- data/lib/graphql/schema/member/has_arguments.rb +147 -56
- 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 +97 -40
- data/lib/graphql/schema/member/has_interfaces.rb +49 -10
- 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/type_system_helpers.rb +17 -0
- data/lib/graphql/schema/member/validates_input.rb +3 -3
- data/lib/graphql/schema/member.rb +0 -6
- data/lib/graphql/schema/mutation.rb +0 -9
- data/lib/graphql/schema/non_null.rb +3 -9
- data/lib/graphql/schema/object.rb +15 -52
- data/lib/graphql/schema/relay_classic_mutation.rb +53 -42
- data/lib/graphql/schema/resolver/has_payload_type.rb +20 -10
- data/lib/graphql/schema/resolver.rb +43 -44
- data/lib/graphql/schema/scalar.rb +8 -23
- data/lib/graphql/schema/subscription.rb +0 -7
- data/lib/graphql/schema/timeout.rb +24 -28
- data/lib/graphql/schema/type_membership.rb +3 -0
- data/lib/graphql/schema/union.rb +10 -17
- data/lib/graphql/schema/validator.rb +1 -1
- data/lib/graphql/schema/warden.rb +37 -9
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +265 -968
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/base_visitor.rb +4 -21
- data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
- data/lib/graphql/static_validation/error.rb +2 -2
- data/lib/graphql/static_validation/literal_validator.rb +19 -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 +12 -12
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
- data/lib/graphql/static_validation/rules/fields_will_merge.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/unique_directives_per_location.rb +12 -6
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
- data/lib/graphql/static_validation/validator.rb +3 -25
- data/lib/graphql/static_validation.rb +0 -2
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -1
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
- data/lib/graphql/subscriptions/event.rb +3 -8
- data/lib/graphql/subscriptions/instrumentation.rb +0 -51
- data/lib/graphql/subscriptions.rb +32 -20
- data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
- data/lib/graphql/tracing/appoptics_trace.rb +231 -0
- data/lib/graphql/tracing/appsignal_trace.rb +77 -0
- data/lib/graphql/tracing/data_dog_trace.rb +148 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +21 -2
- data/lib/graphql/tracing/legacy_trace.rb +65 -0
- data/lib/graphql/tracing/new_relic_trace.rb +75 -0
- data/lib/graphql/tracing/notifications_trace.rb +42 -0
- data/lib/graphql/tracing/platform_trace.rb +109 -0
- data/lib/graphql/tracing/platform_tracing.rb +33 -43
- data/lib/graphql/tracing/prometheus_trace.rb +89 -0
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +1 -1
- data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
- data/lib/graphql/tracing/scout_trace.rb +72 -0
- data/lib/graphql/tracing/statsd_trace.rb +56 -0
- data/lib/graphql/tracing/trace.rb +75 -0
- data/lib/graphql/tracing.rb +16 -40
- data/lib/graphql/type_kinds.rb +6 -3
- data/lib/graphql/types/iso_8601_date.rb +4 -1
- data/lib/graphql/types/iso_8601_date_time.rb +4 -0
- data/lib/graphql/types/relay/base_connection.rb +16 -6
- data/lib/graphql/types/relay/connection_behaviors.rb +29 -27
- data/lib/graphql/types/relay/edge_behaviors.rb +16 -5
- 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 +1 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +17 -74
- metadata +33 -133
- 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 -232
- 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 -255
- 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 -55
- data/lib/graphql/directive/deprecated_directive.rb +0 -2
- data/lib/graphql/directive/include_directive.rb +0 -2
- data/lib/graphql/directive/skip_directive.rb +0 -2
- data/lib/graphql/directive.rb +0 -107
- data/lib/graphql/enum_type.rb +0 -133
- data/lib/graphql/execution/execute.rb +0 -333
- data/lib/graphql/execution/flatten.rb +0 -40
- data/lib/graphql/execution/instrumentation.rb +0 -92
- 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/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 -260
- 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 -54
- 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 -39
- data/lib/graphql/relay/global_id_resolve.rb +0 -17
- 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/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 -164
- data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
- 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/string_type.rb +0 -2
- 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 -31
- data/lib/graphql/types/relay/node_field.rb +0 -24
- data/lib/graphql/types/relay/nodes_field.rb +0 -43
- data/lib/graphql/union_type.rb +0 -115
- data/lib/graphql/upgrader/member.rb +0 -937
- data/lib/graphql/upgrader/schema.rb +0 -38
@@ -29,25 +29,19 @@ module GraphQL
|
|
29
29
|
# Override {GraphQL::Schema::Resolver#resolve_with_support} to
|
30
30
|
# delete `client_mutation_id` from the kwargs.
|
31
31
|
def resolve_with_support(**inputs)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
# don't re-add it if it wasn't given here.
|
45
|
-
if inputs.key?(ext)
|
46
|
-
input[ext] = inputs[ext]
|
47
|
-
end
|
32
|
+
input = inputs[:input].to_kwargs
|
33
|
+
|
34
|
+
new_extras = field ? field.extras : []
|
35
|
+
all_extras = self.class.extras + new_extras
|
36
|
+
|
37
|
+
# Transfer these from the top-level hash to the
|
38
|
+
# shortcutted `input:` object
|
39
|
+
all_extras.each do |ext|
|
40
|
+
# It's possible that the `extra` was not passed along by this point,
|
41
|
+
# don't re-add it if it wasn't given here.
|
42
|
+
if inputs.key?(ext)
|
43
|
+
input[ext] = inputs[ext]
|
48
44
|
end
|
49
|
-
else
|
50
|
-
input = inputs
|
51
45
|
end
|
52
46
|
|
53
47
|
if input
|
@@ -66,26 +60,46 @@ module GraphQL
|
|
66
60
|
super()
|
67
61
|
end
|
68
62
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
if return_hash.is_a?(Hash)
|
74
|
-
return_hash[:client_mutation_id] = client_mutation_id
|
75
|
-
end
|
76
|
-
return_hash
|
63
|
+
context.schema.after_lazy(return_value) do |return_hash|
|
64
|
+
# It might be an error
|
65
|
+
if return_hash.is_a?(Hash)
|
66
|
+
return_hash[:client_mutation_id] = client_mutation_id
|
77
67
|
end
|
78
|
-
|
79
|
-
return_value
|
68
|
+
return_hash
|
80
69
|
end
|
81
70
|
end
|
82
71
|
|
83
72
|
class << self
|
73
|
+
def dummy
|
74
|
+
@dummy ||= begin
|
75
|
+
d = Class.new(GraphQL::Schema::Resolver)
|
76
|
+
d.argument_class(self.argument_class)
|
77
|
+
# TODO make this lazier?
|
78
|
+
d.argument(:input, input_type, description: "Parameters for #{self.graphql_name}")
|
79
|
+
d
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def field_arguments(context = GraphQL::Query::NullContext)
|
84
|
+
dummy.arguments(context)
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_field_argument(name, context = GraphQL::Query::NullContext)
|
88
|
+
dummy.get_argument(name, context)
|
89
|
+
end
|
90
|
+
|
91
|
+
def own_field_arguments
|
92
|
+
dummy.own_arguments
|
93
|
+
end
|
94
|
+
|
95
|
+
def all_field_argument_definitions
|
96
|
+
dummy.all_argument_definitions
|
97
|
+
end
|
84
98
|
|
85
99
|
# Also apply this argument to the input type:
|
86
|
-
def argument(*args, **kwargs, &block)
|
100
|
+
def argument(*args, own_argument: false, **kwargs, &block)
|
87
101
|
it = input_type # make sure any inherited arguments are already added to it
|
88
|
-
arg = super
|
102
|
+
arg = super(*args, **kwargs, &block)
|
89
103
|
|
90
104
|
# This definition might be overriding something inherited;
|
91
105
|
# if it is, remove the inherited definition so it's not confused at runtime as having multiple definitions
|
@@ -125,15 +139,6 @@ module GraphQL
|
|
125
139
|
@input_type ||= generate_input_type
|
126
140
|
end
|
127
141
|
|
128
|
-
# Extend {Schema::Mutation.field_options} to add the `input` argument
|
129
|
-
def field_options
|
130
|
-
sig = super
|
131
|
-
# Arguments were added at the root, but they should be nested
|
132
|
-
sig[:arguments].clear
|
133
|
-
sig[:arguments][:input] = { type: input_type, required: true, description: "Parameters for #{graphql_name}" }
|
134
|
-
sig
|
135
|
-
end
|
136
|
-
|
137
142
|
private
|
138
143
|
|
139
144
|
# Generate the input type for the `input:` argument
|
@@ -141,11 +146,17 @@ module GraphQL
|
|
141
146
|
# @return [Class] a subclass of {.input_object_class}
|
142
147
|
def generate_input_type
|
143
148
|
mutation_args = all_argument_definitions
|
144
|
-
mutation_name = graphql_name
|
145
149
|
mutation_class = self
|
146
150
|
Class.new(input_object_class) do
|
147
|
-
|
148
|
-
|
151
|
+
class << self
|
152
|
+
def default_graphql_name
|
153
|
+
"#{self.mutation.graphql_name}Input"
|
154
|
+
end
|
155
|
+
|
156
|
+
def description(new_desc = nil)
|
157
|
+
super || "Autogenerated input type of #{self.mutation.graphql_name}"
|
158
|
+
end
|
159
|
+
end
|
149
160
|
mutation(mutation_class)
|
150
161
|
# these might be inherited:
|
151
162
|
mutation_args.each do |arg|
|
@@ -20,7 +20,17 @@ module GraphQL
|
|
20
20
|
@payload_type ||= generate_payload_type
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
def type(new_type = nil, null: nil)
|
24
|
+
if new_type
|
25
|
+
payload_type(new_type)
|
26
|
+
if !null.nil?
|
27
|
+
self.null(null)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
super()
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
alias :type_expr :payload_type
|
25
35
|
|
26
36
|
def field_class(new_class = nil)
|
@@ -79,16 +89,16 @@ module GraphQL
|
|
79
89
|
def generate_payload_type
|
80
90
|
resolver_name = graphql_name
|
81
91
|
resolver_fields = all_field_definitions
|
82
|
-
Class.new(object_class)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
92
|
+
pt = Class.new(object_class)
|
93
|
+
pt.graphql_name("#{resolver_name}Payload")
|
94
|
+
pt.description("Autogenerated return type of #{resolver_name}.")
|
95
|
+
resolver_fields.each do |f|
|
96
|
+
# Reattach the already-defined field here
|
97
|
+
# (The field's `.owner` will still point to the mutation, not the object type, I think)
|
98
|
+
# Don't re-warn about a method conflict. Since this type is generated, it should be fixed in the resolver instead.
|
99
|
+
pt.add_field(f, method_conflict_warning: false)
|
91
100
|
end
|
101
|
+
pt
|
92
102
|
end
|
93
103
|
end
|
94
104
|
end
|
@@ -15,8 +15,6 @@ module GraphQL
|
|
15
15
|
#
|
16
16
|
# A resolver's configuration may be overridden with other keywords in the `field(...)` call.
|
17
17
|
#
|
18
|
-
# See the {.field_options} to see how a Resolver becomes a set of field configuration options.
|
19
|
-
#
|
20
18
|
# @see {GraphQL::Schema::Mutation} for a concrete subclass of `Resolver`.
|
21
19
|
# @see {GraphQL::Function} `Resolver` is a replacement for `GraphQL::Function`
|
22
20
|
class Resolver
|
@@ -75,7 +73,7 @@ module GraphQL
|
|
75
73
|
context.schema.after_lazy(ready_val) do |is_ready, ready_early_return|
|
76
74
|
if ready_early_return
|
77
75
|
if is_ready != false
|
78
|
-
raise "Unexpected result from #ready? (expected `true`, `false` or `[false, {...}]`): [#{
|
76
|
+
raise "Unexpected result from #ready? (expected `true`, `false` or `[false, {...}]`): [#{is_ready.inspect}, #{ready_early_return.inspect}]"
|
79
77
|
else
|
80
78
|
ready_early_return
|
81
79
|
end
|
@@ -210,6 +208,18 @@ module GraphQL
|
|
210
208
|
end
|
211
209
|
|
212
210
|
class << self
|
211
|
+
def field_arguments(context = GraphQL::Query::NullContext)
|
212
|
+
arguments(context)
|
213
|
+
end
|
214
|
+
|
215
|
+
def get_field_argument(name, context = GraphQL::Query::NullContext)
|
216
|
+
get_argument(name, context)
|
217
|
+
end
|
218
|
+
|
219
|
+
def all_field_argument_definitions
|
220
|
+
all_argument_definitions
|
221
|
+
end
|
222
|
+
|
213
223
|
# Default `:resolve` set below.
|
214
224
|
# @return [Symbol] The method to call on instances of this object to resolve the field
|
215
225
|
def resolve_method(new_method = nil)
|
@@ -242,6 +252,14 @@ module GraphQL
|
|
242
252
|
@null.nil? ? (superclass.respond_to?(:null) ? superclass.null : true) : @null
|
243
253
|
end
|
244
254
|
|
255
|
+
def resolver_method(new_method_name = nil)
|
256
|
+
if new_method_name
|
257
|
+
@resolver_method = new_method_name
|
258
|
+
else
|
259
|
+
@resolver_method || :resolve_with_support
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
245
263
|
# Call this method to get the return type of the field,
|
246
264
|
# or use it as a configuration method to assign a return type
|
247
265
|
# instead of generating one.
|
@@ -257,8 +275,8 @@ module GraphQL
|
|
257
275
|
@type_expr = new_type
|
258
276
|
@null = null
|
259
277
|
else
|
260
|
-
if
|
261
|
-
GraphQL::Schema::Member::BuildType.parse_type(
|
278
|
+
if type_expr
|
279
|
+
GraphQL::Schema::Member::BuildType.parse_type(type_expr, null: self.null)
|
262
280
|
elsif superclass.respond_to?(:type)
|
263
281
|
superclass.type
|
264
282
|
else
|
@@ -293,8 +311,8 @@ module GraphQL
|
|
293
311
|
# (`nil` means "unlimited max page size".)
|
294
312
|
# @param max_page_size [Integer, nil] Set a new value
|
295
313
|
# @return [Integer, nil] The `max_page_size` assigned to fields that use this resolver
|
296
|
-
def max_page_size(new_max_page_size =
|
297
|
-
if new_max_page_size !=
|
314
|
+
def max_page_size(new_max_page_size = NOT_CONFIGURED)
|
315
|
+
if new_max_page_size != NOT_CONFIGURED
|
298
316
|
@max_page_size = new_max_page_size
|
299
317
|
elsif defined?(@max_page_size)
|
300
318
|
@max_page_size
|
@@ -307,47 +325,28 @@ module GraphQL
|
|
307
325
|
|
308
326
|
# @return [Boolean] `true` if this resolver or a superclass has an assigned `max_page_size`
|
309
327
|
def has_max_page_size?
|
310
|
-
defined?(@max_page_size) || (superclass.respond_to?(:has_max_page_size?) && superclass.has_max_page_size?)
|
328
|
+
(!!defined?(@max_page_size)) || (superclass.respond_to?(:has_max_page_size?) && superclass.has_max_page_size?)
|
311
329
|
end
|
312
330
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
end
|
327
|
-
|
328
|
-
field_opts = {
|
329
|
-
type: type_expr,
|
330
|
-
description: description,
|
331
|
-
extras: extras,
|
332
|
-
resolver_method: :resolve_with_support,
|
333
|
-
resolver_class: self,
|
334
|
-
arguments: all_args,
|
335
|
-
null: null,
|
336
|
-
complexity: complexity,
|
337
|
-
broadcastable: broadcastable?,
|
338
|
-
}
|
339
|
-
|
340
|
-
# If there aren't any, then the returned array is `[].freeze`,
|
341
|
-
# but passing that along breaks some user code.
|
342
|
-
if (exts = extensions).any?
|
343
|
-
field_opts[:extensions] = exts
|
344
|
-
end
|
345
|
-
|
346
|
-
if has_max_page_size?
|
347
|
-
field_opts[:max_page_size] = max_page_size
|
331
|
+
# Get or set the `default_page_size:` which will be configured for fields using this resolver
|
332
|
+
# (`nil` means "unlimited default page size".)
|
333
|
+
# @param default_page_size [Integer, nil] Set a new value
|
334
|
+
# @return [Integer, nil] The `default_page_size` assigned to fields that use this resolver
|
335
|
+
def default_page_size(new_default_page_size = NOT_CONFIGURED)
|
336
|
+
if new_default_page_size != NOT_CONFIGURED
|
337
|
+
@default_page_size = new_default_page_size
|
338
|
+
elsif defined?(@default_page_size)
|
339
|
+
@default_page_size
|
340
|
+
elsif superclass.respond_to?(:default_page_size)
|
341
|
+
superclass.default_page_size
|
342
|
+
else
|
343
|
+
nil
|
348
344
|
end
|
345
|
+
end
|
349
346
|
|
350
|
-
|
347
|
+
# @return [Boolean] `true` if this resolver or a superclass has an assigned `default_page_size`
|
348
|
+
def has_default_page_size?
|
349
|
+
(!!defined?(@default_page_size)) || (superclass.respond_to?(:has_default_page_size?) && superclass.has_default_page_size?)
|
351
350
|
end
|
352
351
|
|
353
352
|
# A non-normalized type configuration, without `null` applied
|
@@ -2,7 +2,6 @@
|
|
2
2
|
module GraphQL
|
3
3
|
class Schema
|
4
4
|
class Scalar < GraphQL::Schema::Member
|
5
|
-
extend GraphQL::Schema::Member::AcceptsDefinition
|
6
5
|
extend GraphQL::Schema::Member::ValidatesInput
|
7
6
|
|
8
7
|
class << self
|
@@ -14,20 +13,6 @@ module GraphQL
|
|
14
13
|
val
|
15
14
|
end
|
16
15
|
|
17
|
-
prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
|
18
|
-
|
19
|
-
def to_graphql
|
20
|
-
type_defn = GraphQL::ScalarType.new
|
21
|
-
type_defn.name = graphql_name
|
22
|
-
type_defn.description = description
|
23
|
-
type_defn.coerce_result = method(:coerce_result)
|
24
|
-
type_defn.coerce_input = method(:coerce_input)
|
25
|
-
type_defn.metadata[:type_class] = self
|
26
|
-
type_defn.default_scalar = default_scalar
|
27
|
-
type_defn.ast_node = ast_node
|
28
|
-
type_defn
|
29
|
-
end
|
30
|
-
|
31
16
|
def kind
|
32
17
|
GraphQL::TypeKinds::SCALAR
|
33
18
|
end
|
@@ -55,14 +40,13 @@ module GraphQL
|
|
55
40
|
@default_scalar ||= false
|
56
41
|
end
|
57
42
|
|
58
|
-
def validate_non_null_input(value, ctx)
|
59
|
-
result = Query::InputValidationResult.new
|
43
|
+
def validate_non_null_input(value, ctx, max_errors: nil)
|
60
44
|
coerced_result = begin
|
61
|
-
ctx
|
62
|
-
coerce_input(value, ctx)
|
63
|
-
end
|
45
|
+
coerce_input(value, ctx)
|
64
46
|
rescue GraphQL::CoercionError => err
|
65
47
|
err
|
48
|
+
rescue StandardError => err
|
49
|
+
ctx.query.handle_or_reraise(err)
|
66
50
|
end
|
67
51
|
|
68
52
|
if coerced_result.nil?
|
@@ -71,11 +55,12 @@ module GraphQL
|
|
71
55
|
else
|
72
56
|
" #{GraphQL::Language.serialize(value)}"
|
73
57
|
end
|
74
|
-
|
58
|
+
Query::InputValidationResult.from_problem("Could not coerce value#{str_value} to #{graphql_name}")
|
75
59
|
elsif coerced_result.is_a?(GraphQL::CoercionError)
|
76
|
-
|
60
|
+
Query::InputValidationResult.from_problem(coerced_result.message, message: coerced_result.message, extensions: coerced_result.extensions)
|
61
|
+
else
|
62
|
+
nil
|
77
63
|
end
|
78
|
-
result
|
79
64
|
end
|
80
65
|
end
|
81
66
|
end
|
@@ -143,13 +143,6 @@ module GraphQL
|
|
143
143
|
def self.topic_for(arguments:, field:, scope:)
|
144
144
|
Subscriptions::Serialize.dump_recursive([scope, field.graphql_name, arguments])
|
145
145
|
end
|
146
|
-
|
147
|
-
# Overriding Resolver#field_options to include subscription_scope
|
148
|
-
def self.field_options
|
149
|
-
super.merge(
|
150
|
-
subscription_scope: subscription_scope
|
151
|
-
)
|
152
|
-
end
|
153
146
|
end
|
154
147
|
end
|
155
148
|
end
|
@@ -33,60 +33,56 @@ module GraphQL
|
|
33
33
|
# end
|
34
34
|
#
|
35
35
|
class Timeout
|
36
|
-
def self.use(schema,
|
37
|
-
|
38
|
-
schema.
|
36
|
+
def self.use(schema, max_seconds: nil)
|
37
|
+
timeout = self.new(max_seconds: max_seconds)
|
38
|
+
schema.trace_with(self::Trace, timeout: timeout)
|
39
39
|
end
|
40
40
|
|
41
|
-
# @param max_seconds [Numeric] how many seconds the query should be allowed to resolve new fields
|
42
41
|
def initialize(max_seconds:)
|
43
42
|
@max_seconds = max_seconds
|
44
43
|
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
module Trace
|
46
|
+
# @param max_seconds [Numeric] how many seconds the query should be allowed to resolve new fields
|
47
|
+
def initialize(timeout:, **rest)
|
48
|
+
@timeout = timeout
|
49
|
+
super
|
50
|
+
end
|
51
|
+
|
52
|
+
def execute_multiplex(multiplex:)
|
53
|
+
multiplex.queries.each do |query|
|
54
|
+
timeout_duration_s = @timeout.max_seconds(query)
|
51
55
|
timeout_state = if timeout_duration_s == false
|
52
56
|
# if the method returns `false`, don't apply a timeout
|
53
57
|
false
|
54
58
|
else
|
55
59
|
now = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
|
56
|
-
timeout_at = now + (
|
60
|
+
timeout_at = now + (timeout_duration_s * 1000)
|
57
61
|
{
|
58
62
|
timeout_at: timeout_at,
|
59
63
|
timed_out: false
|
60
64
|
}
|
61
65
|
end
|
62
|
-
query.context.namespace(
|
66
|
+
query.context.namespace(@timeout)[:state] = timeout_state
|
63
67
|
end
|
68
|
+
super
|
69
|
+
end
|
64
70
|
|
65
|
-
|
66
|
-
|
67
|
-
query_context = data[:context] || data[:query].context
|
68
|
-
timeout_state = query_context.namespace(self.class).fetch(:state)
|
71
|
+
def execute_field(query:, field:, **_rest)
|
72
|
+
timeout_state = query.context.namespace(@timeout).fetch(:state)
|
69
73
|
# If the `:state` is `false`, then `max_seconds(query)` opted out of timeout for this query.
|
70
74
|
if timeout_state != false && Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) > timeout_state.fetch(:timeout_at)
|
71
|
-
error =
|
72
|
-
GraphQL::Schema::Timeout::TimeoutError.new(query_context.parent_type, query_context.field)
|
73
|
-
else
|
74
|
-
field = data.fetch(:field)
|
75
|
-
GraphQL::Schema::Timeout::TimeoutError.new(field.owner, field)
|
76
|
-
end
|
77
|
-
|
75
|
+
error = GraphQL::Schema::Timeout::TimeoutError.new(field)
|
78
76
|
# Only invoke the timeout callback for the first timeout
|
79
77
|
if !timeout_state[:timed_out]
|
80
78
|
timeout_state[:timed_out] = true
|
81
|
-
handle_timeout(error,
|
79
|
+
@timeout.handle_timeout(error, query)
|
82
80
|
end
|
83
81
|
|
84
82
|
error
|
85
83
|
else
|
86
|
-
|
84
|
+
super
|
87
85
|
end
|
88
|
-
else
|
89
|
-
yield
|
90
86
|
end
|
91
87
|
end
|
92
88
|
|
@@ -114,8 +110,8 @@ module GraphQL
|
|
114
110
|
# to take this error and raise a new one which _doesn't_ descend from {GraphQL::ExecutionError},
|
115
111
|
# such as `RuntimeError`.
|
116
112
|
class TimeoutError < GraphQL::ExecutionError
|
117
|
-
def initialize(
|
118
|
-
super("Timeout on #{
|
113
|
+
def initialize(field)
|
114
|
+
super("Timeout on #{field.path}")
|
119
115
|
end
|
120
116
|
end
|
121
117
|
end
|
@@ -11,6 +11,9 @@ module GraphQL
|
|
11
11
|
# @return [Class<GraphQL::Schema::Union>, Module<GraphQL::Schema::Interface>]
|
12
12
|
attr_reader :abstract_type
|
13
13
|
|
14
|
+
# @return [Hash]
|
15
|
+
attr_reader :options
|
16
|
+
|
14
17
|
# Called when an object is hooked up to an abstract type, such as {Schema::Union.possible_types}
|
15
18
|
# or {Schema::Object.implements} (for interfaces).
|
16
19
|
#
|
data/lib/graphql/schema/union.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
module GraphQL
|
3
3
|
class Schema
|
4
4
|
class Union < GraphQL::Schema::Member
|
5
|
-
extend GraphQL::Schema::Member::AcceptsDefinition
|
6
5
|
extend GraphQL::Schema::Member::HasUnresolvedTypeError
|
7
6
|
|
8
7
|
class << self
|
@@ -33,21 +32,6 @@ module GraphQL
|
|
33
32
|
type_memberships.map(&:object_type)
|
34
33
|
end
|
35
34
|
|
36
|
-
prepend GraphQL::Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
|
37
|
-
|
38
|
-
def to_graphql
|
39
|
-
type_defn = GraphQL::UnionType.new
|
40
|
-
type_defn.name = graphql_name
|
41
|
-
type_defn.description = description
|
42
|
-
type_defn.ast_node = ast_node
|
43
|
-
type_defn.type_memberships = type_memberships
|
44
|
-
if respond_to?(:resolve_type)
|
45
|
-
type_defn.resolve_type = method(:resolve_type)
|
46
|
-
end
|
47
|
-
type_defn.metadata[:type_class] = self
|
48
|
-
type_defn
|
49
|
-
end
|
50
|
-
|
51
35
|
def type_membership_class(membership_class = nil)
|
52
36
|
if membership_class
|
53
37
|
@type_membership_class = membership_class
|
@@ -86,9 +70,18 @@ module GraphQL
|
|
86
70
|
private
|
87
71
|
|
88
72
|
def assert_valid_union_member(type_defn)
|
89
|
-
|
73
|
+
case type_defn
|
74
|
+
when Class
|
75
|
+
if !type_defn.kind.object?
|
76
|
+
raise ArgumentError, "Union possible_types can only be object types (not #{type_defn.kind.name}, #{type_defn.inspect})"
|
77
|
+
end
|
78
|
+
when Module
|
90
79
|
# it's an interface type, defined as a module
|
91
80
|
raise ArgumentError, "Union possible_types can only be object types (not interface types), remove #{type_defn.graphql_name} (#{type_defn.inspect})"
|
81
|
+
when String, GraphQL::Schema::LateBoundType
|
82
|
+
# Ok - assume it will get checked later
|
83
|
+
else
|
84
|
+
raise ArgumentError, "Union possible_types can only be class-based GraphQL types (not #{type_defn.inspect} (#{type_defn.class.name}))."
|
92
85
|
end
|
93
86
|
end
|
94
87
|
end
|
@@ -10,7 +10,7 @@ module GraphQL
|
|
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
|
13
|
+
# @example Hiding private fields
|
14
14
|
# private_members = -> (member, ctx) { member.metadata[:private] }
|
15
15
|
# result = Schema.execute(query_string, except: private_members)
|
16
16
|
#
|
@@ -38,7 +38,9 @@ module GraphQL
|
|
38
38
|
# @api private
|
39
39
|
class Warden
|
40
40
|
def self.from_context(context)
|
41
|
-
|
41
|
+
context.warden # this might be a hash which won't respond to this
|
42
|
+
rescue
|
43
|
+
PassThruWarden
|
42
44
|
end
|
43
45
|
|
44
46
|
# @param visibility_method [Symbol] a Warden method to call for this entry
|
@@ -55,7 +57,9 @@ module GraphQL
|
|
55
57
|
if visible_item.nil?
|
56
58
|
visible_item = item
|
57
59
|
else
|
58
|
-
raise
|
60
|
+
raise DuplicateNamesError.new(
|
61
|
+
duplicated_name: item.path, duplicated_definition_1: visible_item.inspect, duplicated_definition_2: item.inspect
|
62
|
+
)
|
59
63
|
end
|
60
64
|
end
|
61
65
|
end
|
@@ -78,6 +82,8 @@ module GraphQL
|
|
78
82
|
def visible_type?(type, ctx); type.visible?(ctx); end
|
79
83
|
def visible_enum_value?(ev, ctx); ev.visible?(ctx); end
|
80
84
|
def visible_type_membership?(tm, ctx); tm.visible?(ctx); end
|
85
|
+
def interface_type_memberships(obj_t, ctx); obj_t.interface_type_memberships; end
|
86
|
+
def arguments(owner, ctx); owner.arguments(ctx); end
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
@@ -85,13 +91,20 @@ module GraphQL
|
|
85
91
|
# @param context [GraphQL::Query::Context]
|
86
92
|
# @param schema [GraphQL::Schema]
|
87
93
|
def initialize(filter, context:, schema:)
|
88
|
-
@schema = schema
|
94
|
+
@schema = schema
|
89
95
|
# Cache these to avoid repeated hits to the inheritance chain when one isn't present
|
90
96
|
@query = @schema.query
|
91
97
|
@mutation = @schema.mutation
|
92
98
|
@subscription = @schema.subscription
|
93
99
|
@context = context
|
94
100
|
@visibility_cache = read_through { |m| filter.call(m, context) }
|
101
|
+
# Initialize all ivars to improve object shape consistency:
|
102
|
+
@types = @visible_types = @reachable_types = @visible_parent_fields =
|
103
|
+
@visible_possible_types = @visible_fields = @visible_arguments = @visible_enum_arrays =
|
104
|
+
@visible_enum_values = @visible_interfaces = @type_visibility = @type_memberships =
|
105
|
+
@visible_and_reachable_type = @unions = @unfiltered_interfaces = @references_to =
|
106
|
+
@reachable_type_set =
|
107
|
+
nil
|
95
108
|
end
|
96
109
|
|
97
110
|
# @return [Hash<String, GraphQL::BaseType>] Visible types in the schema
|
@@ -172,14 +185,20 @@ module GraphQL
|
|
172
185
|
|
173
186
|
# @param argument_owner [GraphQL::Field, GraphQL::InputObjectType]
|
174
187
|
# @return [Array<GraphQL::Argument>] Visible arguments on `argument_owner`
|
175
|
-
def arguments(argument_owner)
|
176
|
-
@visible_arguments ||= read_through { |o| o.arguments(@context).each_value.select { |a| visible_argument?(a) } }
|
188
|
+
def arguments(argument_owner, ctx = nil)
|
189
|
+
@visible_arguments ||= read_through { |o| o.arguments(@context).each_value.select { |a| visible_argument?(a, @context) } }
|
177
190
|
@visible_arguments[argument_owner]
|
178
191
|
end
|
179
192
|
|
180
193
|
# @return [Array<GraphQL::EnumType::EnumValue>] Visible members of `enum_defn`
|
181
194
|
def enum_values(enum_defn)
|
182
|
-
@visible_enum_arrays ||= read_through { |e|
|
195
|
+
@visible_enum_arrays ||= read_through { |e|
|
196
|
+
values = e.enum_values(@context)
|
197
|
+
if values.size == 0
|
198
|
+
raise GraphQL::Schema::Enum::MissingValuesError.new(e)
|
199
|
+
end
|
200
|
+
values
|
201
|
+
}
|
183
202
|
@visible_enum_arrays[enum_defn]
|
184
203
|
end
|
185
204
|
|
@@ -231,6 +250,13 @@ module GraphQL
|
|
231
250
|
visible?(type_membership)
|
232
251
|
end
|
233
252
|
|
253
|
+
def interface_type_memberships(obj_type, _ctx = nil)
|
254
|
+
@type_memberships ||= read_through do |obj_t|
|
255
|
+
obj_t.interface_type_memberships
|
256
|
+
end
|
257
|
+
@type_memberships[obj_type]
|
258
|
+
end
|
259
|
+
|
234
260
|
private
|
235
261
|
|
236
262
|
def visible_and_reachable_type?(type_defn)
|
@@ -330,7 +356,7 @@ module GraphQL
|
|
330
356
|
end
|
331
357
|
|
332
358
|
def reachable_type_set
|
333
|
-
return @reachable_type_set if
|
359
|
+
return @reachable_type_set if @reachable_type_set
|
334
360
|
|
335
361
|
@reachable_type_set = Set.new
|
336
362
|
rt_hash = {}
|
@@ -362,7 +388,9 @@ module GraphQL
|
|
362
388
|
if @reachable_type_set.add?(type)
|
363
389
|
type_by_name = rt_hash[type.graphql_name] ||= type
|
364
390
|
if type_by_name != type
|
365
|
-
raise DuplicateNamesError
|
391
|
+
raise DuplicateNamesError.new(
|
392
|
+
duplicated_name: type.graphql_name, duplicated_definition_1: type.inspect, duplicated_definition_2: type_by_name.inspect
|
393
|
+
)
|
366
394
|
end
|
367
395
|
if type.kind.input_object?
|
368
396
|
# recurse into visible arguments
|