graphql 2.0.13 → 2.3.10
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/install/mutation_root_generator.rb +2 -2
- data/lib/generators/graphql/install/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/install/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/install_generator.rb +3 -0
- data/lib/generators/graphql/mutation_delete_generator.rb +1 -1
- data/lib/generators/graphql/mutation_update_generator.rb +1 -1
- data/lib/generators/graphql/relay.rb +18 -1
- 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/graphql_controller.erb +2 -0
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +2 -0
- data/lib/generators/graphql/templates/node_type.erb +2 -0
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +8 -0
- data/lib/graphql/analysis/analyzer.rb +89 -0
- data/lib/graphql/analysis/field_usage.rb +82 -0
- data/lib/graphql/analysis/max_query_complexity.rb +20 -0
- data/lib/graphql/analysis/max_query_depth.rb +20 -0
- data/lib/graphql/analysis/query_complexity.rb +183 -0
- data/lib/graphql/analysis/query_depth.rb +58 -0
- data/lib/graphql/analysis/visitor.rb +283 -0
- data/lib/graphql/analysis.rb +92 -1
- data/lib/graphql/backtrace/inspect_result.rb +0 -12
- data/lib/graphql/backtrace/table.rb +2 -2
- data/lib/graphql/backtrace/trace.rb +93 -0
- data/lib/graphql/backtrace/tracer.rb +1 -1
- data/lib/graphql/backtrace.rb +2 -1
- data/lib/graphql/coercion_error.rb +1 -9
- data/lib/graphql/dataloader/async_dataloader.rb +88 -0
- data/lib/graphql/dataloader/null_dataloader.rb +1 -1
- data/lib/graphql/dataloader/request.rb +5 -0
- data/lib/graphql/dataloader/source.rb +89 -45
- data/lib/graphql/dataloader.rb +115 -142
- data/lib/graphql/duration_encoding_error.rb +16 -0
- data/lib/graphql/execution/interpreter/argument_value.rb +5 -1
- data/lib/graphql/execution/interpreter/arguments.rb +1 -1
- data/lib/graphql/execution/interpreter/arguments_cache.rb +33 -33
- data/lib/graphql/execution/interpreter/resolve.rb +19 -0
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +175 -0
- data/lib/graphql/execution/interpreter/runtime.rb +331 -455
- data/lib/graphql/execution/interpreter.rb +125 -61
- data/lib/graphql/execution/lazy.rb +6 -12
- data/lib/graphql/execution/lookahead.rb +124 -46
- data/lib/graphql/execution/multiplex.rb +3 -117
- data/lib/graphql/execution.rb +0 -1
- data/lib/graphql/introspection/directive_type.rb +3 -3
- data/lib/graphql/introspection/dynamic_fields.rb +1 -1
- data/lib/graphql/introspection/entry_points.rb +11 -5
- data/lib/graphql/introspection/field_type.rb +2 -2
- data/lib/graphql/introspection/schema_type.rb +10 -13
- data/lib/graphql/introspection/type_type.rb +17 -10
- data/lib/graphql/introspection.rb +3 -2
- data/lib/graphql/language/block_string.rb +34 -18
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/document_from_schema_definition.rb +75 -59
- data/lib/graphql/language/lexer.rb +358 -1506
- data/lib/graphql/language/nodes.rb +166 -93
- data/lib/graphql/language/parser.rb +795 -1953
- data/lib/graphql/language/printer.rb +340 -160
- data/lib/graphql/language/sanitized_printer.rb +21 -23
- data/lib/graphql/language/static_visitor.rb +167 -0
- data/lib/graphql/language/visitor.rb +188 -141
- data/lib/graphql/language.rb +61 -1
- data/lib/graphql/load_application_object_failed_error.rb +5 -1
- data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
- data/lib/graphql/pagination/array_connection.rb +6 -6
- data/lib/graphql/pagination/connection.rb +33 -6
- data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -2
- data/lib/graphql/query/context/scoped_context.rb +101 -0
- data/lib/graphql/query/context.rb +117 -112
- data/lib/graphql/query/null_context.rb +12 -25
- data/lib/graphql/query/validation_pipeline.rb +6 -5
- data/lib/graphql/query/variables.rb +3 -3
- data/lib/graphql/query.rb +86 -30
- data/lib/graphql/railtie.rb +9 -6
- data/lib/graphql/rake_task.rb +29 -11
- data/lib/graphql/rubocop/graphql/base_cop.rb +1 -1
- data/lib/graphql/schema/addition.rb +59 -23
- data/lib/graphql/schema/always_visible.rb +11 -0
- data/lib/graphql/schema/argument.rb +55 -26
- data/lib/graphql/schema/base_64_encoder.rb +3 -5
- data/lib/graphql/schema/build_from_definition.rb +56 -32
- data/lib/graphql/schema/directive/one_of.rb +24 -0
- data/lib/graphql/schema/directive/specified_by.rb +14 -0
- data/lib/graphql/schema/directive/transform.rb +1 -1
- data/lib/graphql/schema/directive.rb +15 -3
- data/lib/graphql/schema/enum.rb +35 -24
- data/lib/graphql/schema/enum_value.rb +2 -3
- data/lib/graphql/schema/field/connection_extension.rb +2 -16
- data/lib/graphql/schema/field/scope_extension.rb +8 -1
- data/lib/graphql/schema/field.rb +147 -107
- data/lib/graphql/schema/field_extension.rb +1 -4
- data/lib/graphql/schema/find_inherited_value.rb +2 -7
- data/lib/graphql/schema/has_single_input_argument.rb +158 -0
- data/lib/graphql/schema/input_object.rb +47 -11
- data/lib/graphql/schema/interface.rb +15 -21
- data/lib/graphql/schema/introspection_system.rb +7 -17
- data/lib/graphql/schema/late_bound_type.rb +10 -0
- data/lib/graphql/schema/list.rb +2 -2
- data/lib/graphql/schema/loader.rb +2 -3
- data/lib/graphql/schema/member/base_dsl_methods.rb +18 -14
- data/lib/graphql/schema/member/build_type.rb +11 -3
- data/lib/graphql/schema/member/has_arguments.rb +170 -130
- 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 +100 -38
- data/lib/graphql/schema/member/has_interfaces.rb +65 -10
- 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 +19 -0
- 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 +3 -3
- data/lib/graphql/schema/mutation.rb +7 -0
- data/lib/graphql/schema/object.rb +16 -5
- data/lib/graphql/schema/printer.rb +11 -8
- data/lib/graphql/schema/relay_classic_mutation.rb +7 -129
- data/lib/graphql/schema/resolver/has_payload_type.rb +9 -9
- data/lib/graphql/schema/resolver.rb +47 -32
- data/lib/graphql/schema/scalar.rb +3 -3
- data/lib/graphql/schema/subscription.rb +11 -4
- data/lib/graphql/schema/subset.rb +397 -0
- data/lib/graphql/schema/timeout.rb +25 -29
- data/lib/graphql/schema/type_expression.rb +2 -2
- data/lib/graphql/schema/type_membership.rb +3 -0
- data/lib/graphql/schema/union.rb +11 -2
- data/lib/graphql/schema/unique_within_type.rb +1 -1
- data/lib/graphql/schema/validator/all_validator.rb +60 -0
- data/lib/graphql/schema/validator.rb +4 -2
- data/lib/graphql/schema/warden.rb +238 -93
- data/lib/graphql/schema.rb +498 -103
- data/lib/graphql/static_validation/all_rules.rb +2 -1
- data/lib/graphql/static_validation/base_visitor.rb +7 -6
- data/lib/graphql/static_validation/definition_dependencies.rb +7 -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/arguments_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -2
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +10 -10
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -1
- 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/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 +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +4 -4
- 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/variable_default_values_are_correctly_typed.rb +18 -27
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/validation_context.rb +5 -5
- data/lib/graphql/static_validation/validator.rb +4 -1
- data/lib/graphql/static_validation.rb +0 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +11 -4
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
- data/lib/graphql/subscriptions/event.rb +11 -10
- data/lib/graphql/subscriptions/serialize.rb +2 -0
- data/lib/graphql/subscriptions.rb +20 -13
- data/lib/graphql/testing/helpers.rb +151 -0
- data/lib/graphql/testing.rb +2 -0
- data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
- 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/data_dog_trace.rb +183 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +9 -21
- 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/platform_trace.rb +118 -0
- data/lib/graphql/tracing/platform_tracing.rb +17 -3
- 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 -40
- data/lib/graphql/type_kinds.rb +7 -4
- data/lib/graphql/types/iso_8601_duration.rb +77 -0
- data/lib/graphql/types/relay/base_connection.rb +1 -1
- data/lib/graphql/types/relay/connection_behaviors.rb +68 -6
- data/lib/graphql/types/relay/edge_behaviors.rb +33 -5
- data/lib/graphql/types/relay/node_behaviors.rb +8 -2
- data/lib/graphql/types/relay/page_info_behaviors.rb +11 -2
- data/lib/graphql/types/relay.rb +0 -1
- data/lib/graphql/types/string.rb +1 -1
- data/lib/graphql/types.rb +1 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +27 -20
- data/readme.md +13 -3
- metadata +96 -47
- data/lib/graphql/analysis/ast/analyzer.rb +0 -84
- data/lib/graphql/analysis/ast/field_usage.rb +0 -57
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -22
- data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
- data/lib/graphql/analysis/ast/query_complexity.rb +0 -230
- data/lib/graphql/analysis/ast/query_depth.rb +0 -55
- data/lib/graphql/analysis/ast/visitor.rb +0 -269
- data/lib/graphql/analysis/ast.rb +0 -81
- data/lib/graphql/deprecation.rb +0 -9
- data/lib/graphql/filter.rb +0 -53
- data/lib/graphql/language/lexer.rl +0 -280
- data/lib/graphql/language/parser.y +0 -554
- data/lib/graphql/language/token.rb +0 -34
- data/lib/graphql/schema/base_64_bp.rb +0 -26
- data/lib/graphql/schema/invalid_type_error.rb +0 -7
- data/lib/graphql/static_validation/type_stack.rb +0 -216
- data/lib/graphql/subscriptions/instrumentation.rb +0 -28
- data/lib/graphql/types/relay/default_relay.rb +0 -21
@@ -21,6 +21,10 @@ module GraphQL
|
|
21
21
|
# @see {GraphQL::Schema::Mutation} for an example, it's basically the same.
|
22
22
|
#
|
23
23
|
class RelayClassicMutation < GraphQL::Schema::Mutation
|
24
|
+
include GraphQL::Schema::HasSingleInputArgument
|
25
|
+
|
26
|
+
argument :client_mutation_id, String, "A unique identifier for the client performing the mutation.", required: false
|
27
|
+
|
24
28
|
# The payload should always include this field
|
25
29
|
field(:client_mutation_id, String, "A unique identifier for the client performing the mutation.")
|
26
30
|
# Relay classic default:
|
@@ -31,36 +35,16 @@ module GraphQL
|
|
31
35
|
def resolve_with_support(**inputs)
|
32
36
|
input = inputs[:input].to_kwargs
|
33
37
|
|
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]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
38
|
if input
|
48
39
|
# This is handled by Relay::Mutation::Resolve, a bit hacky, but here we are.
|
49
40
|
input_kwargs = input.to_h
|
50
41
|
client_mutation_id = input_kwargs.delete(:client_mutation_id)
|
51
|
-
|
52
|
-
# Relay Classic Mutations with no `argument`s
|
53
|
-
# don't require `input:`
|
54
|
-
input_kwargs = {}
|
42
|
+
inputs[:input] = input_kwargs
|
55
43
|
end
|
56
44
|
|
57
|
-
return_value =
|
58
|
-
super(**input_kwargs)
|
59
|
-
else
|
60
|
-
super()
|
61
|
-
end
|
45
|
+
return_value = super(**inputs)
|
62
46
|
|
63
|
-
context.
|
47
|
+
context.query.after_lazy(return_value) do |return_hash|
|
64
48
|
# It might be an error
|
65
49
|
if return_hash.is_a?(Hash)
|
66
50
|
return_hash[:client_mutation_id] = client_mutation_id
|
@@ -68,112 +52,6 @@ module GraphQL
|
|
68
52
|
return_hash
|
69
53
|
end
|
70
54
|
end
|
71
|
-
|
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
|
98
|
-
|
99
|
-
# Also apply this argument to the input type:
|
100
|
-
def argument(*args, own_argument: false, **kwargs, &block)
|
101
|
-
it = input_type # make sure any inherited arguments are already added to it
|
102
|
-
arg = super(*args, **kwargs, &block)
|
103
|
-
|
104
|
-
# This definition might be overriding something inherited;
|
105
|
-
# if it is, remove the inherited definition so it's not confused at runtime as having multiple definitions
|
106
|
-
prev_args = it.own_arguments[arg.graphql_name]
|
107
|
-
case prev_args
|
108
|
-
when GraphQL::Schema::Argument
|
109
|
-
if prev_args.owner != self
|
110
|
-
it.own_arguments.delete(arg.graphql_name)
|
111
|
-
end
|
112
|
-
when Array
|
113
|
-
prev_args.reject! { |a| a.owner != self }
|
114
|
-
if prev_args.empty?
|
115
|
-
it.own_arguments.delete(arg.graphql_name)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
it.add_argument(arg)
|
120
|
-
arg
|
121
|
-
end
|
122
|
-
|
123
|
-
# The base class for generated input object types
|
124
|
-
# @param new_class [Class] The base class to use for generating input object definitions
|
125
|
-
# @return [Class] The base class for this mutation's generated input object (default is {GraphQL::Schema::InputObject})
|
126
|
-
def input_object_class(new_class = nil)
|
127
|
-
if new_class
|
128
|
-
@input_object_class = new_class
|
129
|
-
end
|
130
|
-
@input_object_class || (superclass.respond_to?(:input_object_class) ? superclass.input_object_class : GraphQL::Schema::InputObject)
|
131
|
-
end
|
132
|
-
|
133
|
-
# @param new_input_type [Class, nil] If provided, it configures this mutation to accept `new_input_type` instead of generating an input type
|
134
|
-
# @return [Class] The generated {Schema::InputObject} class for this mutation's `input`
|
135
|
-
def input_type(new_input_type = nil)
|
136
|
-
if new_input_type
|
137
|
-
@input_type = new_input_type
|
138
|
-
end
|
139
|
-
@input_type ||= generate_input_type
|
140
|
-
end
|
141
|
-
|
142
|
-
private
|
143
|
-
|
144
|
-
# Generate the input type for the `input:` argument
|
145
|
-
# To customize how input objects are generated, override this method
|
146
|
-
# @return [Class] a subclass of {.input_object_class}
|
147
|
-
def generate_input_type
|
148
|
-
mutation_args = all_argument_definitions
|
149
|
-
mutation_class = self
|
150
|
-
Class.new(input_object_class) do
|
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
|
160
|
-
mutation(mutation_class)
|
161
|
-
# these might be inherited:
|
162
|
-
mutation_args.each do |arg|
|
163
|
-
add_argument(arg)
|
164
|
-
end
|
165
|
-
argument :client_mutation_id, String, "A unique identifier for the client performing the mutation.", required: false
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
private
|
171
|
-
|
172
|
-
def authorize_arguments(args, values)
|
173
|
-
# remove the `input` wrapper to match values
|
174
|
-
input_args = args["input"].type.unwrap.arguments(context)
|
175
|
-
super(input_args, values)
|
176
|
-
end
|
177
55
|
end
|
178
56
|
end
|
179
57
|
end
|
@@ -89,16 +89,16 @@ module GraphQL
|
|
89
89
|
def generate_payload_type
|
90
90
|
resolver_name = graphql_name
|
91
91
|
resolver_fields = all_field_definitions
|
92
|
-
Class.new(object_class)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
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)
|
101
100
|
end
|
101
|
+
pt
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
@@ -25,6 +25,7 @@ module GraphQL
|
|
25
25
|
extend GraphQL::Schema::Member::HasValidators
|
26
26
|
include Schema::Member::HasPath
|
27
27
|
extend Schema::Member::HasPath
|
28
|
+
extend Schema::Member::HasDirectives
|
28
29
|
|
29
30
|
# @param object [Object] The application object that this field is being resolved on
|
30
31
|
# @param context [GraphQL::Query::Context]
|
@@ -35,7 +36,7 @@ module GraphQL
|
|
35
36
|
@field = field
|
36
37
|
# Since this hash is constantly rebuilt, cache it for this call
|
37
38
|
@arguments_by_keyword = {}
|
38
|
-
|
39
|
+
context.types.arguments(self.class).each do |arg|
|
39
40
|
@arguments_by_keyword[arg.keyword] = arg
|
40
41
|
end
|
41
42
|
@prepared_arguments = nil
|
@@ -65,47 +66,45 @@ module GraphQL
|
|
65
66
|
# @api private
|
66
67
|
def resolve_with_support(**args)
|
67
68
|
# First call the ready? hook which may raise
|
68
|
-
|
69
|
+
raw_ready_val = if args.any?
|
69
70
|
ready?(**args)
|
70
71
|
else
|
71
72
|
ready?
|
72
73
|
end
|
73
|
-
context.
|
74
|
-
if
|
74
|
+
context.query.after_lazy(raw_ready_val) do |ready_val|
|
75
|
+
if ready_val.is_a?(Array)
|
76
|
+
is_ready, ready_early_return = ready_val
|
75
77
|
if is_ready != false
|
76
78
|
raise "Unexpected result from #ready? (expected `true`, `false` or `[false, {...}]`): [#{is_ready.inspect}, #{ready_early_return.inspect}]"
|
77
79
|
else
|
78
80
|
ready_early_return
|
79
81
|
end
|
80
|
-
elsif
|
82
|
+
elsif ready_val
|
81
83
|
# Then call each prepare hook, which may return a different value
|
82
84
|
# for that argument, or may return a lazy object
|
83
85
|
load_arguments_val = load_arguments(args)
|
84
|
-
context.
|
86
|
+
context.query.after_lazy(load_arguments_val) do |loaded_args|
|
85
87
|
@prepared_arguments = loaded_args
|
86
88
|
Schema::Validator.validate!(self.class.validators, object, context, loaded_args, as: @field)
|
87
89
|
# Then call `authorized?`, which may raise or may return a lazy object
|
88
|
-
|
90
|
+
raw_authorized_val = if loaded_args.any?
|
89
91
|
authorized?(**loaded_args)
|
90
92
|
else
|
91
93
|
authorized?
|
92
94
|
end
|
93
|
-
context.
|
95
|
+
context.query.after_lazy(raw_authorized_val) do |authorized_val|
|
94
96
|
# If the `authorized?` returned two values, `false, early_return`,
|
95
97
|
# then use the early return value instead of continuing
|
96
|
-
if
|
98
|
+
if authorized_val.is_a?(Array)
|
99
|
+
authorized_result, early_return = authorized_val
|
97
100
|
if authorized_result == false
|
98
101
|
early_return
|
99
102
|
else
|
100
103
|
raise "Unexpected result from #authorized? (expected `true`, `false` or `[false, {...}]`): [#{authorized_result.inspect}, #{early_return.inspect}]"
|
101
104
|
end
|
102
|
-
elsif
|
105
|
+
elsif authorized_val
|
103
106
|
# Finally, all the hooks have passed, so resolve it
|
104
|
-
|
105
|
-
public_send(self.class.resolve_method, **loaded_args)
|
106
|
-
else
|
107
|
-
public_send(self.class.resolve_method)
|
108
|
-
end
|
107
|
+
call_resolve(loaded_args)
|
109
108
|
else
|
110
109
|
raise GraphQL::UnauthorizedFieldError.new(context: context, object: object, type: field.owner, field: field)
|
111
110
|
end
|
@@ -115,6 +114,15 @@ module GraphQL
|
|
115
114
|
end
|
116
115
|
end
|
117
116
|
|
117
|
+
# @api private {GraphQL::Schema::Mutation} uses this to clear the dataloader cache
|
118
|
+
def call_resolve(args_hash)
|
119
|
+
if args_hash.any?
|
120
|
+
public_send(self.class.resolve_method, **args_hash)
|
121
|
+
else
|
122
|
+
public_send(self.class.resolve_method)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
118
126
|
# Do the work. Everything happens here.
|
119
127
|
# @return [Object] An object corresponding to the return type
|
120
128
|
def resolve(**args)
|
@@ -144,7 +152,7 @@ module GraphQL
|
|
144
152
|
# @return [Boolean, early_return_data] If `false`, execution will stop (and `early_return_data` will be returned instead, if present.)
|
145
153
|
def authorized?(**inputs)
|
146
154
|
arg_owner = @field # || self.class
|
147
|
-
args =
|
155
|
+
args = context.types.arguments(arg_owner)
|
148
156
|
authorize_arguments(args, inputs)
|
149
157
|
end
|
150
158
|
|
@@ -161,19 +169,22 @@ module GraphQL
|
|
161
169
|
private
|
162
170
|
|
163
171
|
def authorize_arguments(args, inputs)
|
164
|
-
args.
|
172
|
+
args.each do |argument|
|
165
173
|
arg_keyword = argument.keyword
|
166
174
|
if inputs.key?(arg_keyword) && !(arg_value = inputs[arg_keyword]).nil? && (arg_value != argument.default_value)
|
167
|
-
|
168
|
-
if
|
169
|
-
return
|
170
|
-
|
171
|
-
|
175
|
+
auth_result = argument.authorized?(self, arg_value, context)
|
176
|
+
if auth_result.is_a?(Array)
|
177
|
+
# only return this second value if the application returned a second value
|
178
|
+
arg_auth, err = auth_result
|
179
|
+
if !arg_auth
|
180
|
+
return arg_auth, err
|
181
|
+
end
|
182
|
+
elsif auth_result == false
|
183
|
+
return auth_result
|
172
184
|
end
|
173
|
-
else
|
174
|
-
true
|
175
185
|
end
|
176
186
|
end
|
187
|
+
true
|
177
188
|
end
|
178
189
|
|
179
190
|
def load_arguments(args)
|
@@ -185,7 +196,7 @@ module GraphQL
|
|
185
196
|
if arg_defn
|
186
197
|
prepped_value = prepared_args[key] = arg_defn.load_and_authorize_value(self, value, context)
|
187
198
|
if context.schema.lazy?(prepped_value)
|
188
|
-
prepare_lazies << context.
|
199
|
+
prepare_lazies << context.query.after_lazy(prepped_value) do |finished_prepped_value|
|
189
200
|
prepared_args[key] = finished_prepped_value
|
190
201
|
end
|
191
202
|
end
|
@@ -203,16 +214,20 @@ module GraphQL
|
|
203
214
|
end
|
204
215
|
end
|
205
216
|
|
206
|
-
def get_argument(name, context = GraphQL::Query::NullContext)
|
217
|
+
def get_argument(name, context = GraphQL::Query::NullContext.instance)
|
207
218
|
self.class.get_argument(name, context)
|
208
219
|
end
|
209
220
|
|
210
221
|
class << self
|
211
|
-
def field_arguments(context = GraphQL::Query::NullContext)
|
222
|
+
def field_arguments(context = GraphQL::Query::NullContext.instance)
|
212
223
|
arguments(context)
|
213
224
|
end
|
214
225
|
|
215
|
-
def
|
226
|
+
def any_field_arguments?
|
227
|
+
any_arguments?
|
228
|
+
end
|
229
|
+
|
230
|
+
def get_field_argument(name, context = GraphQL::Query::NullContext.instance)
|
216
231
|
get_argument(name, context)
|
217
232
|
end
|
218
233
|
|
@@ -311,8 +326,8 @@ module GraphQL
|
|
311
326
|
# (`nil` means "unlimited max page size".)
|
312
327
|
# @param max_page_size [Integer, nil] Set a new value
|
313
328
|
# @return [Integer, nil] The `max_page_size` assigned to fields that use this resolver
|
314
|
-
def max_page_size(new_max_page_size =
|
315
|
-
if new_max_page_size !=
|
329
|
+
def max_page_size(new_max_page_size = NOT_CONFIGURED)
|
330
|
+
if new_max_page_size != NOT_CONFIGURED
|
316
331
|
@max_page_size = new_max_page_size
|
317
332
|
elsif defined?(@max_page_size)
|
318
333
|
@max_page_size
|
@@ -332,8 +347,8 @@ module GraphQL
|
|
332
347
|
# (`nil` means "unlimited default page size".)
|
333
348
|
# @param default_page_size [Integer, nil] Set a new value
|
334
349
|
# @return [Integer, nil] The `default_page_size` assigned to fields that use this resolver
|
335
|
-
def default_page_size(new_default_page_size =
|
336
|
-
if new_default_page_size !=
|
350
|
+
def default_page_size(new_default_page_size = NOT_CONFIGURED)
|
351
|
+
if new_default_page_size != NOT_CONFIGURED
|
337
352
|
@default_page_size = new_default_page_size
|
338
353
|
elsif defined?(@default_page_size)
|
339
354
|
@default_page_size
|
@@ -19,9 +19,9 @@ module GraphQL
|
|
19
19
|
|
20
20
|
def specified_by_url(new_url = nil)
|
21
21
|
if new_url
|
22
|
-
|
23
|
-
elsif
|
24
|
-
|
22
|
+
directive(GraphQL::Schema::Directive::SpecifiedBy, url: new_url)
|
23
|
+
elsif (directive = directives.find { |dir| dir.graphql_name == "specifiedBy" })
|
24
|
+
directive.arguments[:url] # rubocop:disable Development/ContextIsPassedCop
|
25
25
|
elsif superclass.respond_to?(:specified_by_url)
|
26
26
|
superclass.specified_by_url
|
27
27
|
else
|
@@ -28,14 +28,19 @@ module GraphQL
|
|
28
28
|
def resolve_with_support(**args)
|
29
29
|
result = nil
|
30
30
|
unsubscribed = true
|
31
|
-
catch :graphql_subscription_unsubscribed do
|
31
|
+
unsubscribed_result = catch :graphql_subscription_unsubscribed do
|
32
32
|
result = super
|
33
33
|
unsubscribed = false
|
34
34
|
end
|
35
35
|
|
36
36
|
|
37
37
|
if unsubscribed
|
38
|
-
|
38
|
+
if unsubscribed_result
|
39
|
+
context.namespace(:subscriptions)[:final_update] = true
|
40
|
+
unsubscribed_result
|
41
|
+
else
|
42
|
+
context.skip
|
43
|
+
end
|
39
44
|
else
|
40
45
|
result
|
41
46
|
end
|
@@ -94,9 +99,11 @@ module GraphQL
|
|
94
99
|
end
|
95
100
|
|
96
101
|
# Call this to halt execution and remove this subscription from the system
|
97
|
-
|
102
|
+
# @param update_value [Object] if present, deliver this update before unsubscribing
|
103
|
+
# @return [void]
|
104
|
+
def unsubscribe(update_value = nil)
|
98
105
|
context.namespace(:subscriptions)[:unsubscribed] = true
|
99
|
-
throw :graphql_subscription_unsubscribed
|
106
|
+
throw :graphql_subscription_unsubscribed, update_value
|
100
107
|
end
|
101
108
|
|
102
109
|
READING_SCOPE = ::Object.new
|