graphql 1.9.21 → 1.10.0.pre1
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 +0 -1
- data/lib/generators/graphql/install_generator.rb +0 -1
- data/lib/generators/graphql/mutation_generator.rb +1 -1
- data/lib/generators/graphql/templates/base_field.erb +4 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +0 -5
- data/lib/generators/graphql/templates/mutation.erb +1 -1
- data/lib/generators/graphql/templates/schema.erb +1 -1
- data/lib/graphql.rb +1 -11
- data/lib/graphql/analysis/ast.rb +2 -2
- data/lib/graphql/analysis/ast/analyzer.rb +4 -23
- data/lib/graphql/analysis/ast/max_query_complexity.rb +3 -3
- data/lib/graphql/analysis/ast/max_query_depth.rb +3 -7
- data/lib/graphql/analysis/ast/query_complexity.rb +2 -2
- data/lib/graphql/argument.rb +6 -2
- data/lib/graphql/backtrace/table.rb +10 -2
- data/lib/graphql/base_type.rb +5 -1
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +5 -9
- data/lib/graphql/define/assign_object_field.rb +2 -2
- data/lib/graphql/define/defined_object_proxy.rb +0 -3
- data/lib/graphql/define/instance_definable.rb +3 -14
- data/lib/graphql/enum_type.rb +4 -0
- data/lib/graphql/execution/directive_checks.rb +2 -2
- data/lib/graphql/execution/errors.rb +14 -15
- data/lib/graphql/execution/execute.rb +1 -1
- data/lib/graphql/execution/interpreter/runtime.rb +17 -39
- data/lib/graphql/execution/multiplex.rb +3 -3
- data/lib/graphql/field.rb +8 -0
- data/lib/graphql/filter.rb +1 -1
- data/lib/graphql/function.rb +1 -1
- data/lib/graphql/input_object_type.rb +1 -2
- data/lib/graphql/introspection/entry_points.rb +1 -2
- data/lib/graphql/introspection/input_value_type.rb +27 -9
- data/lib/graphql/introspection/schema_type.rb +1 -2
- data/lib/graphql/language/block_string.rb +2 -2
- data/lib/graphql/language/document_from_schema_definition.rb +5 -11
- data/lib/graphql/language/lexer.rb +48 -49
- data/lib/graphql/language/lexer.rl +48 -49
- data/lib/graphql/language/nodes.rb +11 -14
- data/lib/graphql/language/parser.rb +645 -650
- data/lib/graphql/language/parser.y +7 -8
- data/lib/graphql/language/token.rb +1 -1
- data/lib/graphql/non_null_type.rb +0 -10
- data/lib/graphql/pagination.rb +6 -0
- data/lib/graphql/pagination/active_record_relation_connection.rb +35 -0
- data/lib/graphql/pagination/array_connection.rb +78 -0
- data/lib/graphql/pagination/connection.rb +150 -0
- data/lib/graphql/pagination/connections.rb +103 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +157 -0
- data/lib/graphql/pagination/sequel_dataset_connection.rb +28 -0
- data/lib/graphql/query.rb +1 -7
- data/lib/graphql/query/arguments.rb +3 -9
- data/lib/graphql/query/context.rb +9 -31
- data/lib/graphql/query/literal_input.rb +29 -10
- data/lib/graphql/query/null_context.rb +0 -4
- data/lib/graphql/query/variable_validation_error.rb +1 -1
- data/lib/graphql/query/variables.rb +2 -4
- data/lib/graphql/relay/base_connection.rb +7 -3
- data/lib/graphql/relay/edges_instrumentation.rb +1 -1
- data/lib/graphql/relay/node.rb +2 -2
- data/lib/graphql/relay/relation_connection.rb +5 -9
- data/lib/graphql/schema.rb +27 -68
- data/lib/graphql/schema/argument.rb +31 -5
- data/lib/graphql/schema/base_64_bp.rb +2 -3
- data/lib/graphql/schema/build_from_definition.rb +113 -179
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +10 -4
- data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +1 -1
- data/lib/graphql/schema/directive.rb +6 -7
- data/lib/graphql/schema/directive/feature.rb +1 -1
- data/lib/graphql/schema/enum.rb +1 -0
- data/lib/graphql/schema/enum_value.rb +4 -1
- data/lib/graphql/schema/field.rb +37 -39
- data/lib/graphql/schema/field/connection_extension.rb +11 -1
- data/lib/graphql/schema/input_object.rb +2 -5
- data/lib/graphql/schema/interface.rb +2 -0
- data/lib/graphql/schema/introspection_system.rb +1 -4
- data/lib/graphql/schema/loader.rb +6 -12
- data/lib/graphql/schema/member.rb +2 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +2 -2
- data/lib/graphql/schema/member/build_type.rb +4 -0
- data/lib/graphql/schema/member/cached_graphql_definition.rb +5 -0
- data/lib/graphql/schema/member/has_ast_node.rb +17 -0
- data/lib/graphql/schema/member/has_fields.rb +10 -16
- data/lib/graphql/schema/member/instrumentation.rb +1 -6
- data/lib/graphql/schema/member/type_system_helpers.rb +1 -1
- data/lib/graphql/schema/mutation.rb +1 -1
- data/lib/graphql/schema/object.rb +5 -6
- data/lib/graphql/schema/possible_types.rb +3 -3
- data/lib/graphql/schema/printer.rb +1 -3
- data/lib/graphql/schema/relay_classic_mutation.rb +2 -6
- data/lib/graphql/schema/resolver.rb +5 -35
- data/lib/graphql/schema/scalar.rb +1 -0
- data/lib/graphql/schema/subscription.rb +6 -6
- data/lib/graphql/schema/timeout_middleware.rb +2 -3
- data/lib/graphql/schema/type_expression.rb +27 -17
- data/lib/graphql/schema/union.rb +7 -26
- data/lib/graphql/schema/validation.rb +1 -17
- data/lib/graphql/schema/warden.rb +3 -77
- data/lib/graphql/schema/wrapper.rb +1 -1
- data/lib/graphql/static_validation/definition_dependencies.rb +12 -21
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +9 -4
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +10 -7
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +5 -5
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +4 -4
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +3 -3
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +3 -3
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +5 -6
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +1 -1
- data/lib/graphql/subscriptions.rb +7 -7
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +2 -2
- data/lib/graphql/subscriptions/event.rb +5 -19
- data/lib/graphql/subscriptions/instrumentation.rb +9 -4
- data/lib/graphql/subscriptions/subscription_root.rb +2 -10
- data/lib/graphql/tracing/skylight_tracing.rb +0 -1
- data/lib/graphql/types/int.rb +1 -1
- data/lib/graphql/types/relay/base_connection.rb +3 -1
- data/lib/graphql/union_type.rb +23 -58
- data/lib/graphql/upgrader/member.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- metadata +20 -13
- data/lib/generators/graphql/templates/base_mutation.erb +0 -8
- data/lib/graphql/schema/type_membership.rb +0 -34
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/pagination/relation_connection"
|
3
|
+
|
4
|
+
module GraphQL
|
5
|
+
module Pagination
|
6
|
+
class MongoidRelationConnection < Pagination::RelationConnection
|
7
|
+
def relation_offset(relation)
|
8
|
+
relation.options.skip
|
9
|
+
end
|
10
|
+
|
11
|
+
def relation_limit(relation)
|
12
|
+
relation.options.limit
|
13
|
+
end
|
14
|
+
|
15
|
+
def relation_count(relation)
|
16
|
+
# Mongo's `.count` doesn't apply limit or skip, which we need. So we have to load _everything_!
|
17
|
+
relation.to_a.count
|
18
|
+
end
|
19
|
+
|
20
|
+
def null_relation(relation)
|
21
|
+
relation.without_options.none
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/pagination/connection"
|
3
|
+
|
4
|
+
module GraphQL
|
5
|
+
module Pagination
|
6
|
+
# A generic class for working with database query objects.
|
7
|
+
class RelationConnection < Pagination::Connection
|
8
|
+
def nodes
|
9
|
+
load_nodes
|
10
|
+
@nodes
|
11
|
+
end
|
12
|
+
|
13
|
+
def has_previous_page
|
14
|
+
load_nodes
|
15
|
+
@has_previous_page
|
16
|
+
end
|
17
|
+
|
18
|
+
def has_next_page
|
19
|
+
load_nodes
|
20
|
+
@has_next_page
|
21
|
+
end
|
22
|
+
|
23
|
+
def cursor_for(item)
|
24
|
+
load_nodes
|
25
|
+
# index in nodes + existing offset + 1 (because it's offset, not index)
|
26
|
+
offset = nodes.index(item) + 1 + (@paged_nodes_offset || 0) + (relation_offset(items) || 0)
|
27
|
+
context.schema.cursor_encoder.encode(offset.to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# @param relation [Object] A database query object
|
33
|
+
# @return [Integer, nil] The offset value, or nil if there isn't one
|
34
|
+
def relation_offset(relation)
|
35
|
+
raise "#{self.class}#relation_offset(relation) must return the offset value for a #{relation.class} (#{relation.inspect})"
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param relation [Object] A database query object
|
39
|
+
# @return [Integer, nil] The limit value, or nil if there isn't one
|
40
|
+
def relation_limit(relation)
|
41
|
+
raise "#{self.class}#relation_limit(relation) must return the limit value for a #{relation.class} (#{relation.inspect})"
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param relation [Object] A database query object
|
45
|
+
# @return [Integer, nil] The number of items in this relation (hopefully determined without loading all records into memory!)
|
46
|
+
def relation_count(relation)
|
47
|
+
raise "#{self.class}#relation_count(relation) must return the count of records for a #{relation.class} (#{relation.inspect})"
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param relation [Object] A database query object
|
51
|
+
# @return [Object] A modified query object which will return no records
|
52
|
+
def null_relation(relation)
|
53
|
+
raise "#{self.class}#null_relation(relation) must return an empty relation for a #{relation.class} (#{relation.inspect})"
|
54
|
+
end
|
55
|
+
|
56
|
+
def offset_from_cursor(cursor)
|
57
|
+
decode(cursor).to_i
|
58
|
+
end
|
59
|
+
|
60
|
+
# Abstract this operation so we can always ignore inputs less than zero.
|
61
|
+
# (Sequel doesn't like it, understandably.)
|
62
|
+
def set_offset(relation, offset_value)
|
63
|
+
if offset_value >= 0
|
64
|
+
relation.offset(offset_value)
|
65
|
+
else
|
66
|
+
relation.offset(0)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Abstract this operation so we can always ignore inputs less than zero.
|
71
|
+
# (Sequel doesn't like it, understandably.)
|
72
|
+
def set_limit(relation, limit_value)
|
73
|
+
if limit_value > 0
|
74
|
+
relation.limit(limit_value)
|
75
|
+
elsif limit_value == 0
|
76
|
+
null_relation(relation)
|
77
|
+
else
|
78
|
+
relation
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Populate all the pagination info _once_,
|
83
|
+
# It doesn't do anything on subsequent calls.
|
84
|
+
def load_nodes
|
85
|
+
@nodes ||= begin
|
86
|
+
paginated_nodes = items
|
87
|
+
after_offset = after && offset_from_cursor(after)
|
88
|
+
before_offset = before && offset_from_cursor(before)
|
89
|
+
|
90
|
+
if after_offset
|
91
|
+
previous_offset = relation_offset(items) || 0
|
92
|
+
paginated_nodes = set_offset(paginated_nodes, previous_offset + after_offset)
|
93
|
+
end
|
94
|
+
|
95
|
+
if before_offset && after_offset
|
96
|
+
if after_offset < before_offset
|
97
|
+
# Get the number of items between the two cursors
|
98
|
+
space_between = before_offset - after_offset - 1
|
99
|
+
paginated_nodes = set_limit(paginated_nodes, space_between)
|
100
|
+
else
|
101
|
+
# TODO I think this is untested
|
102
|
+
# The cursors overextend one another to an empty set
|
103
|
+
paginated_nodes = null_relation(paginated_nodes)
|
104
|
+
end
|
105
|
+
elsif before_offset
|
106
|
+
# Use limit to cut off the tail of the relation
|
107
|
+
paginated_nodes = set_limit(paginated_nodes, before_offset - 1)
|
108
|
+
end
|
109
|
+
|
110
|
+
sliced_nodes_count = relation_count(paginated_nodes)
|
111
|
+
|
112
|
+
if first && (relation_limit(paginated_nodes).nil? || relation_limit(paginated_nodes) > first)
|
113
|
+
# `first` would create a stricter limit that the one already applied, so add it
|
114
|
+
paginated_nodes = set_limit(paginated_nodes, first)
|
115
|
+
end
|
116
|
+
|
117
|
+
if last
|
118
|
+
if (lv = relation_limit(paginated_nodes))
|
119
|
+
if last <= lv
|
120
|
+
# `last` is a smaller slice than the current limit, so apply it
|
121
|
+
offset = (relation_offset(paginated_nodes) || 0) + (lv - last)
|
122
|
+
paginated_nodes = set_offset(paginated_nodes, offset)
|
123
|
+
paginated_nodes = set_limit(paginated_nodes, last)
|
124
|
+
end
|
125
|
+
else
|
126
|
+
# No limit, so get the last items
|
127
|
+
offset = (relation_offset(paginated_nodes) || 0) + sliced_nodes_count - [last, sliced_nodes_count].min
|
128
|
+
paginated_nodes = set_offset(paginated_nodes, offset)
|
129
|
+
paginated_nodes = set_limit(paginated_nodes, last)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Apply max page size if nothing else was applied
|
134
|
+
if max_page_size && !first && !last
|
135
|
+
if relation_limit(paginated_nodes).nil? || relation_limit(paginated_nodes) > max_page_size
|
136
|
+
paginated_nodes = set_limit(paginated_nodes, max_page_size)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
@has_next_page = !!(
|
141
|
+
(before_offset && before_offset > 0) ||
|
142
|
+
(first && sliced_nodes_count > first)
|
143
|
+
)
|
144
|
+
|
145
|
+
@has_previous_page = !!(
|
146
|
+
(after_offset && after_offset > 0) ||
|
147
|
+
(last && sliced_nodes_count > last)
|
148
|
+
)
|
149
|
+
|
150
|
+
@paged_nodes_offset = relation_offset(paginated_nodes)
|
151
|
+
# Return an array so we can consistently use `.index(node)` on it
|
152
|
+
paginated_nodes.to_a
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/pagination/relation_connection"
|
3
|
+
|
4
|
+
module GraphQL
|
5
|
+
module Pagination
|
6
|
+
# Customizes `RelationConnection` to work with `Sequel::Dataset`s.
|
7
|
+
class SequelDatasetConnection < Pagination::RelationConnection
|
8
|
+
private
|
9
|
+
|
10
|
+
def relation_offset(relation)
|
11
|
+
relation.opts[:offset]
|
12
|
+
end
|
13
|
+
|
14
|
+
def relation_limit(relation)
|
15
|
+
relation.opts[:limit]
|
16
|
+
end
|
17
|
+
|
18
|
+
def relation_count(relation)
|
19
|
+
# Remove order to make it faster
|
20
|
+
relation.order(nil).count
|
21
|
+
end
|
22
|
+
|
23
|
+
def null_relation(relation)
|
24
|
+
relation.where(false)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/graphql/query.rb
CHANGED
@@ -134,6 +134,7 @@ module GraphQL
|
|
134
134
|
@executed = false
|
135
135
|
|
136
136
|
# TODO add a general way to define schema-level filters
|
137
|
+
# TODO also add this to schema dumps
|
137
138
|
if @schema.respond_to?(:visible?)
|
138
139
|
merge_filters(only: @schema.method(:visible?))
|
139
140
|
end
|
@@ -299,13 +300,6 @@ module GraphQL
|
|
299
300
|
with_prepared_ast { @subscription }
|
300
301
|
end
|
301
302
|
|
302
|
-
# @api private
|
303
|
-
def with_error_handling
|
304
|
-
schema.error_handler.with_error_handling(context) do
|
305
|
-
yield
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
303
|
private
|
310
304
|
|
311
305
|
def find_operation(operations, operation_name)
|
@@ -11,6 +11,7 @@ module GraphQL
|
|
11
11
|
def self.construct_arguments_class(argument_owner)
|
12
12
|
argument_definitions = argument_owner.arguments
|
13
13
|
argument_owner.arguments_class = Class.new(self) do
|
14
|
+
self.argument_owner = argument_owner
|
14
15
|
self.argument_definitions = argument_definitions
|
15
16
|
|
16
17
|
argument_definitions.each do |_arg_name, arg_definition|
|
@@ -87,10 +88,6 @@ module GraphQL
|
|
87
88
|
|
88
89
|
def_delegators :to_h, :keys, :values, :each, :any?
|
89
90
|
|
90
|
-
def prepare
|
91
|
-
self
|
92
|
-
end
|
93
|
-
|
94
91
|
# Access each key, value and type for the arguments in this set.
|
95
92
|
# @yield [argument_value] The {ArgumentValue} for each argument
|
96
93
|
# @yieldparam argument_value [ArgumentValue]
|
@@ -101,7 +98,7 @@ module GraphQL
|
|
101
98
|
end
|
102
99
|
|
103
100
|
class << self
|
104
|
-
attr_accessor :argument_definitions
|
101
|
+
attr_accessor :argument_definitions, :argument_owner
|
105
102
|
end
|
106
103
|
|
107
104
|
NoArguments = Class.new(self) do
|
@@ -122,8 +119,6 @@ module GraphQL
|
|
122
119
|
ruby_kwargs
|
123
120
|
end
|
124
121
|
|
125
|
-
alias :to_hash :to_kwargs
|
126
|
-
|
127
122
|
private
|
128
123
|
|
129
124
|
class ArgumentValue
|
@@ -156,8 +151,7 @@ module GraphQL
|
|
156
151
|
wrap_value(value, arg_defn_type.of_type, context)
|
157
152
|
when GraphQL::InputObjectType
|
158
153
|
if value.is_a?(Hash)
|
159
|
-
|
160
|
-
result.prepare
|
154
|
+
arg_defn_type.arguments_class.new(value, context: context, defaults_used: Set.new)
|
161
155
|
else
|
162
156
|
value
|
163
157
|
end
|
@@ -143,9 +143,9 @@ module GraphQL
|
|
143
143
|
# Make a new context which delegates key lookup to `values`
|
144
144
|
# @param query [GraphQL::Query] the query who owns this context
|
145
145
|
# @param values [Hash] A hash of arbitrary values which will be accessible at query-time
|
146
|
-
def initialize(query:,
|
146
|
+
def initialize(query:, values: , object:)
|
147
147
|
@query = query
|
148
|
-
@schema = schema
|
148
|
+
@schema = query.schema
|
149
149
|
@provided_values = values || {}
|
150
150
|
@object = object
|
151
151
|
# Namespaced storage, where user-provided values are in `nil` namespace:
|
@@ -155,7 +155,6 @@ module GraphQL
|
|
155
155
|
@path = []
|
156
156
|
@value = nil
|
157
157
|
@context = self # for SharedMethods
|
158
|
-
@scoped_context = {}
|
159
158
|
end
|
160
159
|
|
161
160
|
# @api private
|
@@ -164,30 +163,15 @@ module GraphQL
|
|
164
163
|
# @api private
|
165
164
|
attr_writer :value
|
166
165
|
|
167
|
-
|
168
|
-
attr_accessor :scoped_context
|
169
|
-
|
170
|
-
def_delegators :@provided_values, :[]=
|
171
|
-
def_delegators :to_h, :fetch, :dig
|
166
|
+
def_delegators :@provided_values, :[], :[]=, :to_h, :to_hash, :key?, :fetch, :dig
|
172
167
|
def_delegators :@query, :trace, :interpreter?
|
173
168
|
|
169
|
+
# @!method [](key)
|
170
|
+
# Lookup `key` from the hash passed to {Schema#execute} as `context:`
|
171
|
+
|
174
172
|
# @!method []=(key, value)
|
175
173
|
# Reassign `key` to the hash passed to {Schema#execute} as `context:`
|
176
174
|
|
177
|
-
# Lookup `key` from the hash passed to {Schema#execute} as `context:`
|
178
|
-
def [](key)
|
179
|
-
return @scoped_context[key] if @scoped_context.key?(key)
|
180
|
-
@provided_values[key]
|
181
|
-
end
|
182
|
-
|
183
|
-
def to_h
|
184
|
-
@provided_values.merge(@scoped_context)
|
185
|
-
end
|
186
|
-
alias :to_hash :to_h
|
187
|
-
|
188
|
-
def key?(key)
|
189
|
-
@scoped_context.key?(key) || @provided_values.key?(key)
|
190
|
-
end
|
191
175
|
|
192
176
|
# @return [GraphQL::Schema::Warden]
|
193
177
|
def warden
|
@@ -211,15 +195,6 @@ module GraphQL
|
|
211
195
|
@value = nil
|
212
196
|
end
|
213
197
|
|
214
|
-
def scoped_merge!(hash)
|
215
|
-
@scoped_context = @scoped_context.merge(hash)
|
216
|
-
end
|
217
|
-
|
218
|
-
def scoped_set!(key, value)
|
219
|
-
scoped_merge!(key => value)
|
220
|
-
nil
|
221
|
-
end
|
222
|
-
|
223
198
|
class FieldResolutionContext
|
224
199
|
include SharedMethods
|
225
200
|
include Tracing::Traceable
|
@@ -334,3 +309,6 @@ module GraphQL
|
|
334
309
|
end
|
335
310
|
end
|
336
311
|
end
|
312
|
+
|
313
|
+
|
314
|
+
GraphQL::Schema::Context = GraphQL::Query::Context
|
@@ -12,8 +12,8 @@ module GraphQL
|
|
12
12
|
when Language::Nodes::VariableIdentifier
|
13
13
|
variables[ast_node.name]
|
14
14
|
else
|
15
|
-
case type
|
16
|
-
when
|
15
|
+
case type.kind.name
|
16
|
+
when "SCALAR"
|
17
17
|
# TODO smell
|
18
18
|
# This gets used for plain values during subscriber.trigger
|
19
19
|
if variables
|
@@ -21,7 +21,7 @@ module GraphQL
|
|
21
21
|
else
|
22
22
|
type.coerce_isolated_input(ast_node)
|
23
23
|
end
|
24
|
-
when
|
24
|
+
when "ENUM"
|
25
25
|
# TODO smell
|
26
26
|
# This gets used for plain values sometimes
|
27
27
|
v = ast_node.is_a?(GraphQL::Language::Nodes::Enum) ? ast_node.name : ast_node
|
@@ -30,18 +30,20 @@ module GraphQL
|
|
30
30
|
else
|
31
31
|
type.coerce_isolated_input(v)
|
32
32
|
end
|
33
|
-
when
|
33
|
+
when "NON_NULL"
|
34
34
|
LiteralInput.coerce(type.of_type, ast_node, variables)
|
35
|
-
when
|
35
|
+
when "LIST"
|
36
36
|
if ast_node.is_a?(Array)
|
37
37
|
ast_node.map { |element_ast| LiteralInput.coerce(type.of_type, element_ast, variables) }
|
38
38
|
else
|
39
39
|
[LiteralInput.coerce(type.of_type, ast_node, variables)]
|
40
40
|
end
|
41
|
-
when
|
41
|
+
when "INPUT_OBJECT"
|
42
42
|
# TODO smell: handling AST vs handling plain Ruby
|
43
43
|
next_args = ast_node.is_a?(Hash) ? ast_node : ast_node.arguments
|
44
44
|
from_arguments(next_args, type, variables)
|
45
|
+
else
|
46
|
+
raise "Invariant: unexpected type to coerce to: #{type}"
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -78,7 +80,10 @@ module GraphQL
|
|
78
80
|
if (!value_is_a_variable || (value_is_a_variable && variables.key?(arg_value.name)))
|
79
81
|
|
80
82
|
value = coerce(arg_defn.type, arg_value, variables)
|
81
|
-
|
83
|
+
# Legacy `prepare` application
|
84
|
+
if arg_defn.is_a?(GraphQL::Argument)
|
85
|
+
value = arg_defn.prepare(value, context)
|
86
|
+
end
|
82
87
|
|
83
88
|
if value.is_a?(GraphQL::ExecutionError)
|
84
89
|
value.ast_node = ast_arg
|
@@ -98,7 +103,9 @@ module GraphQL
|
|
98
103
|
defaults_used << arg_name
|
99
104
|
# `context` isn't present when pre-calculating defaults
|
100
105
|
if context
|
101
|
-
|
106
|
+
if arg_defn.is_a?(GraphQL::Argument)
|
107
|
+
value = arg_defn.prepare(value, context)
|
108
|
+
end
|
102
109
|
if value.is_a?(GraphQL::ExecutionError)
|
103
110
|
value.ast_node = ast_arg
|
104
111
|
raise value
|
@@ -108,8 +115,20 @@ module GraphQL
|
|
108
115
|
end
|
109
116
|
end
|
110
117
|
|
111
|
-
|
112
|
-
|
118
|
+
if argument_owner.is_a?(Class) || argument_owner.is_a?(GraphQL::Schema::Field)
|
119
|
+
# A Schema::InputObject, Schema::GraphQL::Field, Schema::Directive, logic from Query::Arguments#to_kwargs
|
120
|
+
ruby_kwargs = {}
|
121
|
+
values_hash.each do |key, value|
|
122
|
+
ruby_kwargs[Schema::Member::BuildType.underscore(key).to_sym] = value
|
123
|
+
end
|
124
|
+
if argument_owner.is_a?(Class) && argument_owner < GraphQL::Schema::InputObject
|
125
|
+
argument_owner.new(ruby_kwargs: ruby_kwargs, context: context, defaults_used: defaults_used)
|
126
|
+
else
|
127
|
+
ruby_kwargs
|
128
|
+
end
|
129
|
+
else
|
130
|
+
argument_owner.arguments_class.new(values_hash, context: context, defaults_used: defaults_used)
|
131
|
+
end
|
113
132
|
end
|
114
133
|
end
|
115
134
|
end
|