graphql 1.8.14 → 1.8.15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0b109c83a9f06148fa278726ab57bd844f1b225
4
- data.tar.gz: e0fa04d26e12feac797ff4a04ad34f1b792c3bea
3
+ metadata.gz: a2d518263838aebce2b708ac2ac6938e782a486c
4
+ data.tar.gz: 84fe5c02047ea67acf4a9950cbb14bcfd6d9fbfa
5
5
  SHA512:
6
- metadata.gz: 674fffbfd89b1b90910bb28965d6a8b0dfee83440c55c73a765edf4d1cd622c9e8090691b4dbc61c7c80fdaac59b04c66dc9ebc4c83e58dd4f4f6f29350473f2
7
- data.tar.gz: 405121d3f4ae2973eebc1059a0e6fcb3d577bf00dd9378929314fc1cd01c2f4b2a49ffcabfc66f6343d0f04d787b7cbabb5666c3d305936a416de6280b6ea15c
6
+ metadata.gz: 99fc75e928c224adf82a8658b9f8cd0a821f6909e2775bd58c401fb2192db43f440f4d1a7bb9f22fb4a5fdebd5f5a80235e566dd9b0e80df365b8a566893b994
7
+ data.tar.gz: d9ee1715ba8eac2d2b4cc788fe78d3383722a27f69966d140bc90e68a7564622f7e239653f2e9581471fa33c0339f822a3b415db9f2b0ce325fbebfa1c80f190
@@ -264,20 +264,22 @@ module GraphQL
264
264
  )
265
265
  when GraphQL::TypeKinds::UNION, GraphQL::TypeKinds::INTERFACE
266
266
  query = field_ctx.query
267
- resolved_type = field_type.resolve_type(value, field_ctx)
268
- possible_types = query.possible_types(field_type)
269
-
270
- if !possible_types.include?(resolved_type)
271
- parent_type = field_ctx.irep_node.owner_type
272
- type_error = GraphQL::UnresolvedTypeError.new(value, field_defn, parent_type, resolved_type, possible_types)
273
- field_ctx.schema.type_error(type_error, field_ctx)
274
- PROPAGATE_NULL
275
- else
276
- resolve_value(
277
- value,
278
- resolved_type,
279
- field_ctx,
280
- )
267
+ resolved_type_or_lazy = field_type.resolve_type(value, field_ctx)
268
+ query.schema.after_lazy(resolved_type_or_lazy) do |resolved_type|
269
+ possible_types = query.possible_types(field_type)
270
+
271
+ if !possible_types.include?(resolved_type)
272
+ parent_type = field_ctx.irep_node.owner_type
273
+ type_error = GraphQL::UnresolvedTypeError.new(value, field_defn, parent_type, resolved_type, possible_types)
274
+ field_ctx.schema.type_error(type_error, field_ctx)
275
+ PROPAGATE_NULL
276
+ else
277
+ resolve_value(
278
+ value,
279
+ resolved_type,
280
+ field_ctx,
281
+ )
282
+ end
281
283
  end
282
284
  else
283
285
  raise("Unknown type kind: #{field_type.kind}")
@@ -168,7 +168,7 @@ module GraphQL
168
168
  memo[key] = unwrap_value(value)
169
169
  memo
170
170
  end
171
- when GraphQL::Query::Arguments
171
+ when GraphQL::Query::Arguments, GraphQL::Schema::InputObject
172
172
  value.to_h
173
173
  else
174
174
  value
@@ -480,17 +480,20 @@ module GraphQL
480
480
  yield(type, object, ctx)
481
481
  end
482
482
 
483
- if type_result.respond_to?(:graphql_definition)
484
- type_result = type_result.graphql_definition
485
- end
486
-
487
483
  if type_result.nil?
488
484
  nil
489
- elsif !type_result.is_a?(GraphQL::BaseType)
490
- type_str = "#{type_result} (#{type_result.class.name})"
491
- raise "resolve_type(#{object}) returned #{type_str}, but it should return a GraphQL type"
492
485
  else
493
- type_result
486
+ after_lazy(type_result) do |resolved_type_result|
487
+ if resolved_type_result.respond_to?(:graphql_definition)
488
+ resolved_type_result = resolved_type_result.graphql_definition
489
+ end
490
+ if !resolved_type_result.is_a?(GraphQL::BaseType)
491
+ type_str = "#{resolved_type_result} (#{resolved_type_result.class.name})"
492
+ raise "resolve_type(#{object}) returned #{type_str}, but it should return a GraphQL type"
493
+ else
494
+ resolved_type_result
495
+ end
496
+ end
494
497
  end
495
498
  end
496
499
 
@@ -91,7 +91,7 @@ module GraphQL
91
91
  # For lists with nil, we need another nil check here
92
92
  nil
93
93
  else
94
- concrete_type = case @inner_return_type
94
+ concrete_type_or_lazy = case @inner_return_type
95
95
  when GraphQL::UnionType, GraphQL::InterfaceType
96
96
  ctx.query.resolve_type(@inner_return_type, inner_obj)
97
97
  when GraphQL::ObjectType
@@ -100,12 +100,15 @@ module GraphQL
100
100
  raise "unexpected proxying type #{@inner_return_type} for #{inner_obj} at #{ctx.owner_type}.#{ctx.field.name}"
101
101
  end
102
102
 
103
- if concrete_type && (object_class = concrete_type.metadata[:type_class])
104
- # use the query-level context here, since it won't be field-specific anyways
105
- query_ctx = ctx.query.context
106
- object_class.authorized_new(inner_obj, query_ctx)
107
- else
108
- inner_obj
103
+ # .resolve_type may have returned a lazy
104
+ ctx.schema.after_lazy(concrete_type_or_lazy) do |concrete_type|
105
+ if concrete_type && (object_class = concrete_type.metadata[:type_class])
106
+ # use the query-level context here, since it won't be field-specific anyways
107
+ query_ctx = ctx.query.context
108
+ object_class.authorized_new(inner_obj, query_ctx)
109
+ else
110
+ inner_obj
111
+ end
109
112
  end
110
113
  end
111
114
  end
@@ -199,13 +199,13 @@ module GraphQL
199
199
  # See if any object can be found for this ID
200
200
  loaded_application_object = object_from_id(lookup_as_type, id, context)
201
201
  context.schema.after_lazy(loaded_application_object) do |application_object|
202
- begin
203
- if application_object.nil?
204
- raise LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object)
205
- end
206
- # Double-check that the located object is actually of this type
207
- # (Don't want to allow arbitrary access to objects this way)
208
- application_object_type = context.schema.resolve_type(lookup_as_type, application_object, context)
202
+ if application_object.nil?
203
+ raise LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object)
204
+ end
205
+ # Double-check that the located object is actually of this type
206
+ # (Don't want to allow arbitrary access to objects this way)
207
+ resolved_application_object_type = context.schema.resolve_type(lookup_as_type, application_object, context)
208
+ context.schema.after_lazy(resolved_application_object_type) do |application_object_type|
209
209
  possible_object_types = context.schema.possible_types(lookup_as_type)
210
210
  if !possible_object_types.include?(application_object_type)
211
211
  raise LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object)
@@ -229,11 +229,11 @@ module GraphQL
229
229
  application_object
230
230
  end
231
231
  end
232
- rescue LoadApplicationObjectFailedError => err
233
- # pass it to a handler
234
- load_application_object_failed(err)
235
232
  end
236
233
  end
234
+ rescue LoadApplicationObjectFailedError => err
235
+ # pass it to a handler
236
+ load_application_object_failed(err)
237
237
  end
238
238
 
239
239
  def load_application_object_failed(err)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "1.8.14"
3
+ VERSION = "1.8.15"
4
4
  end
@@ -336,4 +336,52 @@ describe GraphQL::Relay::Mutation do
336
336
  assert_equal(expected, result)
337
337
  end
338
338
  end
339
+
340
+ describe 'supports new input object definition with old mutation definition' do
341
+ let(:some_attribute_type) do
342
+ Class.new(GraphQL::Schema::InputObject) do
343
+ graphql_name 'SomeAttribute'
344
+ argument :something, String, required: false
345
+ end
346
+ end
347
+
348
+ let(:do_something_mutation) do
349
+ some_attribute = some_attribute_type
350
+
351
+ GraphQL::Relay::Mutation.define do
352
+ name 'DoSomethingMutation'
353
+ input_field :someAttributes, types[some_attribute.graphql_definition]
354
+
355
+ return_field :anything, types.String
356
+
357
+ resolve ->(_obj, inputs, _ctx) {
358
+ {
359
+ anything: inputs.to_h['someAttributes'][0].class.to_s
360
+ }
361
+ }
362
+ end
363
+ end
364
+
365
+ let(:mutation_type) do
366
+ do_something = do_something_mutation
367
+
368
+ Class.new(GraphQL::Schema::Object) do
369
+ graphql_name 'Mutation'
370
+ field :doSomething, field: do_something.field
371
+ end
372
+ end
373
+
374
+ let(:schema) do
375
+ mutation = mutation_type
376
+
377
+ Class.new(GraphQL::Schema) do
378
+ mutation mutation
379
+ end
380
+ end
381
+
382
+ it 'converts to hash the whole input' do
383
+ result = schema.execute('mutation { doSomething(input: {someAttributes: [{something: "string"}]}) { anything } }')
384
+ assert_equal 'Hash', result['data']['doSomething']['anything']
385
+ end
386
+ end
339
387
  end
@@ -310,10 +310,12 @@ module Jazz
310
310
  possible_types Musician, Ensemble
311
311
 
312
312
  def self.resolve_type(object, context)
313
- if object.is_a?(Models::Ensemble)
314
- Ensemble
315
- else
316
- Musician
313
+ GraphQL::Execution::Lazy.new do
314
+ if object.is_a?(Models::Ensemble)
315
+ Ensemble
316
+ else
317
+ Musician
318
+ end
317
319
  end
318
320
  end
319
321
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.14
4
+ version: 1.8.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-09 00:00:00.000000000 Z
11
+ date: 2019-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips