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
@@ -48,15 +48,15 @@ module GraphQL
|
|
48
48
|
raise InvalidDocumentError.new('Must provide only one schema definition.') if schema_definition
|
49
49
|
schema_definition = definition
|
50
50
|
when GraphQL::Language::Nodes::EnumTypeDefinition
|
51
|
-
types[definition.name] = build_enum_type(definition, type_resolver)
|
51
|
+
types[definition.name] = build_enum_type(definition, type_resolver).graphql_definition
|
52
52
|
when GraphQL::Language::Nodes::ObjectTypeDefinition
|
53
|
-
types[definition.name] = build_object_type(definition, type_resolver, default_resolve: default_resolve)
|
53
|
+
types[definition.name] = build_object_type(definition, type_resolver, default_resolve: default_resolve).graphql_definition
|
54
54
|
when GraphQL::Language::Nodes::InterfaceTypeDefinition
|
55
|
-
types[definition.name] = build_interface_type(definition, type_resolver)
|
55
|
+
types[definition.name] = build_interface_type(definition, type_resolver).graphql_definition
|
56
56
|
when GraphQL::Language::Nodes::UnionTypeDefinition
|
57
|
-
types[definition.name] = build_union_type(definition, type_resolver)
|
57
|
+
types[definition.name] = build_union_type(definition, type_resolver).graphql_definition
|
58
58
|
when GraphQL::Language::Nodes::ScalarTypeDefinition
|
59
|
-
types[definition.name] = build_scalar_type(definition, type_resolver, default_resolve: default_resolve)
|
59
|
+
types[definition.name] = build_scalar_type(definition, type_resolver, default_resolve: default_resolve).graphql_definition
|
60
60
|
when GraphQL::Language::Nodes::InputObjectTypeDefinition
|
61
61
|
types[definition.name] = build_input_object_type(definition, type_resolver)
|
62
62
|
when GraphQL::Language::Nodes::DirectiveDefinition
|
@@ -89,54 +89,51 @@ module GraphQL
|
|
89
89
|
|
90
90
|
raise InvalidDocumentError.new('Must provide schema definition with query type or a type named Query.') unless query_root_type
|
91
91
|
|
92
|
-
|
93
|
-
raise_definition_error true
|
94
|
-
|
92
|
+
Class.new(GraphQL::Schema) do
|
95
93
|
query query_root_type
|
96
94
|
mutation mutation_root_type
|
97
95
|
subscription subscription_root_type
|
98
96
|
orphan_types types.values
|
99
97
|
if default_resolve.respond_to?(:resolve_type)
|
100
|
-
|
98
|
+
define_singleton_method(:resolve_type) do |*args|
|
99
|
+
default_resolve.resolve_type(*args)
|
100
|
+
end
|
101
101
|
else
|
102
|
-
resolve_type
|
102
|
+
define_singleton_method(:resolve_type) do |*args|
|
103
|
+
NullResolveType.call(*args)
|
104
|
+
end
|
103
105
|
end
|
104
106
|
|
105
107
|
directives directives.values
|
106
|
-
end
|
107
108
|
|
108
|
-
|
109
|
+
if schema_definition
|
110
|
+
ast_node(schema_definition)
|
111
|
+
end
|
109
112
|
|
110
|
-
|
113
|
+
# Load caches, check for errors
|
114
|
+
graphql_definition
|
115
|
+
end
|
111
116
|
end
|
112
117
|
|
113
118
|
NullResolveType = ->(type, obj, ctx) {
|
114
|
-
raise(
|
119
|
+
raise(NotImplementedError, "Generated Schema cannot use Interface or Union types for execution. Implement resolve_type on your resolver.")
|
115
120
|
}
|
116
121
|
|
117
|
-
NullScalarCoerce = ->(val, _ctx) { val }
|
118
|
-
|
119
122
|
def build_enum_type(enum_type_definition, type_resolver)
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
builder = self
|
124
|
+
Class.new(GraphQL::Schema::Enum) do
|
125
|
+
graphql_name(enum_type_definition.name)
|
126
|
+
description(enum_type_definition.description)
|
127
|
+
ast_node(enum_type_definition)
|
128
|
+
enum_type_definition.values.each do |enum_value_definition|
|
129
|
+
value(enum_value_definition.name,
|
126
130
|
value: enum_value_definition.name,
|
127
|
-
deprecation_reason: build_deprecation_reason(enum_value_definition.directives),
|
131
|
+
deprecation_reason: builder.build_deprecation_reason(enum_value_definition.directives),
|
128
132
|
description: enum_value_definition.description,
|
133
|
+
ast_node: enum_value_definition,
|
129
134
|
)
|
130
|
-
|
131
|
-
value.ast_node = enum_value_definition
|
132
|
-
|
133
|
-
value
|
134
135
|
end
|
135
|
-
|
136
|
-
|
137
|
-
enum.ast_node = enum_type_definition
|
138
|
-
|
139
|
-
enum
|
136
|
+
end
|
140
137
|
end
|
141
138
|
|
142
139
|
def build_deprecation_reason(directives)
|
@@ -150,63 +147,59 @@ module GraphQL
|
|
150
147
|
end
|
151
148
|
|
152
149
|
def build_scalar_type(scalar_type_definition, type_resolver, default_resolve:)
|
153
|
-
|
154
|
-
|
155
|
-
description
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
scalar_type = scalar_type.redefine(
|
163
|
-
coerce_input: ->(val, ctx) { default_resolve.coerce_input(scalar_type, val, ctx) },
|
164
|
-
coerce_result: ->(val, ctx) { default_resolve.coerce_result(scalar_type, val, ctx) },
|
165
|
-
)
|
166
|
-
end
|
150
|
+
Class.new(GraphQL::Schema::Scalar) do
|
151
|
+
graphql_name(scalar_type_definition.name)
|
152
|
+
description(scalar_type_definition.description)
|
153
|
+
ast_node(scalar_type_definition)
|
154
|
+
|
155
|
+
if default_resolve.respond_to?(:coerce_input)
|
156
|
+
define_singleton_method(:coerce_input) do |val, ctx|
|
157
|
+
default_resolve.coerce_input(self, val, ctx)
|
158
|
+
end
|
167
159
|
|
168
|
-
|
160
|
+
define_singleton_method(:coerce_result) do |val, ctx|
|
161
|
+
default_resolve.coerce_result(self, val, ctx)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
169
165
|
end
|
170
166
|
|
171
167
|
def build_union_type(union_type_definition, type_resolver)
|
172
|
-
|
173
|
-
|
174
|
-
description
|
175
|
-
possible_types
|
176
|
-
|
177
|
-
|
178
|
-
union.ast_node = union_type_definition
|
179
|
-
|
180
|
-
union
|
168
|
+
Class.new(GraphQL::Schema::Union) do
|
169
|
+
graphql_name(union_type_definition.name)
|
170
|
+
description(union_type_definition.description)
|
171
|
+
possible_types(*union_type_definition.types.map { |type_name| type_resolver.call(type_name) })
|
172
|
+
ast_node(union_type_definition)
|
173
|
+
end
|
181
174
|
end
|
182
175
|
|
183
176
|
def build_object_type(object_type_definition, type_resolver, default_resolve:)
|
177
|
+
builder = self
|
184
178
|
type_def = nil
|
185
|
-
typed_resolve_fn = ->(field, obj, args, ctx) { default_resolve.call(type_def, field, obj, args, ctx) }
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
179
|
+
typed_resolve_fn = ->(field, obj, args, ctx) { default_resolve.call(type_def.graphql_definition, field, obj, args, ctx) }
|
180
|
+
Class.new(GraphQL::Schema::Object) do
|
181
|
+
type_def = self
|
182
|
+
graphql_name(object_type_definition.name)
|
183
|
+
description(object_type_definition.description)
|
184
|
+
ast_node(object_type_definition)
|
185
|
+
|
186
|
+
object_type_definition.interfaces.each do |interface_name|
|
187
|
+
interface_defn = type_resolver.call(interface_name)
|
188
|
+
implements(interface_defn)
|
189
|
+
end
|
190
|
+
|
191
|
+
builder.build_fields(self, object_type_definition.fields, type_resolver, default_resolve: typed_resolve_fn)
|
194
192
|
end
|
195
|
-
type_def = GraphQL::ObjectType.define(**defns)
|
196
|
-
type_def.ast_node = object_type_definition
|
197
|
-
type_def
|
198
193
|
end
|
199
194
|
|
200
195
|
def build_input_object_type(input_object_type_definition, type_resolver)
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
input
|
196
|
+
builder = self
|
197
|
+
Class.new(GraphQL::Schema::InputObject) do
|
198
|
+
graphql_name(input_object_type_definition.name)
|
199
|
+
description(input_object_type_definition.description)
|
200
|
+
ast_node(input_object_type_definition)
|
201
|
+
builder.build_arguments(self, input_object_type_definition.fields, type_resolver)
|
202
|
+
end
|
210
203
|
end
|
211
204
|
|
212
205
|
def build_default_value(default_value)
|
@@ -224,130 +217,71 @@ module GraphQL
|
|
224
217
|
end
|
225
218
|
end
|
226
219
|
|
227
|
-
def
|
228
|
-
|
229
|
-
kwargs = {}
|
220
|
+
def build_arguments(type_class, arguments, type_resolver)
|
221
|
+
builder = self
|
230
222
|
|
231
|
-
|
232
|
-
|
223
|
+
arguments.each do |argument_defn|
|
224
|
+
default_value_kwargs = {}
|
225
|
+
if !argument_defn.default_value.nil?
|
226
|
+
default_value_kwargs[:default_value] = builder.build_default_value(argument_defn.default_value)
|
233
227
|
end
|
234
228
|
|
235
|
-
argument
|
236
|
-
|
237
|
-
type: type_resolver.call(
|
238
|
-
|
229
|
+
type_class.argument(
|
230
|
+
argument_defn.name,
|
231
|
+
type: type_resolver.call(argument_defn.type),
|
232
|
+
required: false,
|
233
|
+
description: argument_defn.description,
|
234
|
+
ast_node: argument_defn,
|
235
|
+
camelize: false,
|
239
236
|
method_access: false,
|
240
|
-
**
|
237
|
+
**default_value_kwargs
|
241
238
|
)
|
242
|
-
|
243
|
-
argument.ast_node = input_argument
|
244
|
-
|
245
|
-
[
|
246
|
-
input_argument.name,
|
247
|
-
argument
|
248
|
-
]
|
249
239
|
end
|
250
240
|
end
|
251
241
|
|
252
242
|
def build_directive(directive_definition, type_resolver)
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
if directive_args.any?
|
262
|
-
defn[:arguments] = directive_args
|
243
|
+
builder = self
|
244
|
+
Class.new(GraphQL::Schema::Directive) do
|
245
|
+
graphql_name(directive_definition.name)
|
246
|
+
description(directive_definition.description)
|
247
|
+
locations(*directive_definition.locations.map { |location| location.name.to_sym })
|
248
|
+
ast_node(directive_definition)
|
249
|
+
builder.build_arguments(self, directive_definition.arguments, type_resolver)
|
263
250
|
end
|
264
|
-
|
265
|
-
directive = GraphQL::Directive.define(**defn)
|
266
|
-
directive.ast_node = directive_definition
|
267
|
-
|
268
|
-
directive
|
269
251
|
end
|
270
252
|
|
271
|
-
def
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
name: directive_argument.name,
|
281
|
-
type: type_resolver.call(directive_argument.type),
|
282
|
-
description: directive_argument.description,
|
283
|
-
method_access: false,
|
284
|
-
**kwargs,
|
285
|
-
)
|
286
|
-
|
287
|
-
argument.ast_node = directive_argument
|
288
|
-
|
289
|
-
[
|
290
|
-
directive_argument.name,
|
291
|
-
argument
|
292
|
-
]
|
253
|
+
def build_interface_type(interface_type_definition, type_resolver)
|
254
|
+
builder = self
|
255
|
+
Module.new do
|
256
|
+
include GraphQL::Schema::Interface
|
257
|
+
graphql_name(interface_type_definition.name)
|
258
|
+
description(interface_type_definition.description)
|
259
|
+
ast_node(interface_type_definition)
|
260
|
+
|
261
|
+
builder.build_fields(self, interface_type_definition.fields, type_resolver, default_resolve: nil)
|
293
262
|
end
|
294
263
|
end
|
295
264
|
|
296
|
-
def
|
297
|
-
|
298
|
-
name: interface_type_definition.name,
|
299
|
-
description: interface_type_definition.description,
|
300
|
-
fields: Hash[build_fields(interface_type_definition.fields, type_resolver, default_resolve: nil)],
|
301
|
-
)
|
302
|
-
|
303
|
-
interface.ast_node = interface_type_definition
|
304
|
-
|
305
|
-
interface
|
306
|
-
end
|
265
|
+
def build_fields(owner, field_definitions, type_resolver, default_resolve:)
|
266
|
+
builder = self
|
307
267
|
|
308
|
-
def build_fields(field_definitions, type_resolver, default_resolve:)
|
309
268
|
field_definitions.map do |field_definition|
|
310
|
-
|
311
|
-
kwargs = {}
|
312
|
-
|
313
|
-
if !argument.default_value.nil?
|
314
|
-
kwargs[:default_value] = build_default_value(argument.default_value)
|
315
|
-
end
|
316
|
-
|
317
|
-
arg = GraphQL::Argument.define(
|
318
|
-
name: argument.name,
|
319
|
-
description: argument.description,
|
320
|
-
type: type_resolver.call(argument.type),
|
321
|
-
method_access: false,
|
322
|
-
**kwargs,
|
323
|
-
)
|
324
|
-
|
325
|
-
arg.ast_node = argument
|
326
|
-
|
327
|
-
[argument.name, arg]
|
328
|
-
end]
|
329
|
-
|
330
|
-
field = nil
|
269
|
+
type_name = resolve_type_name(field_definition.type)
|
331
270
|
|
332
|
-
|
333
|
-
|
271
|
+
field = owner.field(
|
272
|
+
field_definition.name,
|
334
273
|
description: field_definition.description,
|
335
274
|
type: type_resolver.call(field_definition.type),
|
336
|
-
|
275
|
+
null: true,
|
276
|
+
connection: type_name.end_with?("Connection"),
|
277
|
+
resolve: ->(obj, args, ctx) { default_resolve.call(field.graphql_definition, obj, args, ctx) },
|
337
278
|
deprecation_reason: build_deprecation_reason(field_definition.directives),
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
279
|
+
ast_node: field_definition,
|
280
|
+
method_conflict_warning: false,
|
281
|
+
camelize: false,
|
282
|
+
) do
|
283
|
+
builder.build_arguments(self, field_definition.arguments, type_resolver)
|
342
284
|
end
|
343
|
-
|
344
|
-
field = GraphQL::Field.define(**defns)
|
345
|
-
|
346
|
-
field.ast_node = field_definition
|
347
|
-
|
348
|
-
type_name = resolve_type_name(field_definition.type)
|
349
|
-
field.connection = type_name.end_with?("Connection")
|
350
|
-
[field_definition.name, field]
|
351
285
|
end
|
352
286
|
end
|
353
287
|
|
@@ -14,6 +14,12 @@ module GraphQL
|
|
14
14
|
#
|
15
15
|
# @api private
|
16
16
|
class ResolveMap
|
17
|
+
module NullScalarCoerce
|
18
|
+
def self.call(val, _ctx)
|
19
|
+
val
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
17
23
|
def initialize(user_resolve_hash)
|
18
24
|
@resolve_hash = Hash.new do |h, k|
|
19
25
|
# For each type name, provide a new hash if one wasn't given:
|
@@ -21,7 +27,7 @@ module GraphQL
|
|
21
27
|
if k2 == "coerce_input" || k2 == "coerce_result"
|
22
28
|
# This isn't an object field, it's a scalar coerce function.
|
23
29
|
# Use a passthrough
|
24
|
-
|
30
|
+
NullScalarCoerce
|
25
31
|
else
|
26
32
|
# For each field, provide a resolver that will
|
27
33
|
# make runtime checks & replace itself
|
@@ -53,16 +59,16 @@ module GraphQL
|
|
53
59
|
end
|
54
60
|
|
55
61
|
def call(type, field, obj, args, ctx)
|
56
|
-
resolver = @resolve_hash[type.
|
62
|
+
resolver = @resolve_hash[type.graphql_name][field.graphql_name]
|
57
63
|
resolver.call(obj, args, ctx)
|
58
64
|
end
|
59
65
|
|
60
66
|
def coerce_input(type, value, ctx)
|
61
|
-
@resolve_hash[type.
|
67
|
+
@resolve_hash[type.graphql_name]["coerce_input"].call(value, ctx)
|
62
68
|
end
|
63
69
|
|
64
70
|
def coerce_result(type, value, ctx)
|
65
|
-
@resolve_hash[type.
|
71
|
+
@resolve_hash[type.graphql_name]["coerce_result"].call(value, ctx)
|
66
72
|
end
|
67
73
|
end
|
68
74
|
end
|
@@ -20,7 +20,7 @@ module GraphQL
|
|
20
20
|
def call(obj, args, ctx)
|
21
21
|
method_name = @field_name
|
22
22
|
if !obj.respond_to?(method_name)
|
23
|
-
raise KeyError, "Can't resolve field #{method_name} on #{obj}"
|
23
|
+
raise KeyError, "Can't resolve field #{method_name} on #{obj.inspect}"
|
24
24
|
else
|
25
25
|
method_arity = obj.method(method_name).arity
|
26
26
|
resolver = case method_arity
|
@@ -9,14 +9,8 @@ module GraphQL
|
|
9
9
|
class Directive < GraphQL::Schema::Member
|
10
10
|
extend GraphQL::Schema::Member::HasArguments
|
11
11
|
class << self
|
12
|
-
# Return a name based on the class name,
|
13
|
-
# but downcase the first letter.
|
14
12
|
def default_graphql_name
|
15
|
-
|
16
|
-
camelized_name = super
|
17
|
-
camelized_name[0] = camelized_name[0].downcase
|
18
|
-
camelized_name
|
19
|
-
end
|
13
|
+
super.downcase
|
20
14
|
end
|
21
15
|
|
22
16
|
def locations(*new_locations)
|
@@ -37,12 +31,17 @@ module GraphQL
|
|
37
31
|
end
|
38
32
|
end
|
39
33
|
|
34
|
+
def default_directive?
|
35
|
+
default_directive
|
36
|
+
end
|
37
|
+
|
40
38
|
def to_graphql
|
41
39
|
defn = GraphQL::Directive.new
|
42
40
|
defn.name = self.graphql_name
|
43
41
|
defn.description = self.description
|
44
42
|
defn.locations = self.locations
|
45
43
|
defn.default_directive = self.default_directive
|
44
|
+
defn.ast_node = ast_node
|
46
45
|
defn.metadata[:type_class] = self
|
47
46
|
arguments.each do |name, arg_defn|
|
48
47
|
arg_graphql = arg_defn.to_graphql
|