graphql 1.12.10 → 1.12.11

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.

@@ -240,62 +240,79 @@ module GraphQL
240
240
  def coerce_into_values(parent_object, values, context, argument_values)
241
241
  arg_name = graphql_name
242
242
  arg_key = keyword
243
- has_value = false
244
243
  default_used = false
244
+
245
245
  if values.key?(arg_name)
246
- has_value = true
247
246
  value = values[arg_name]
248
247
  elsif values.key?(arg_key)
249
- has_value = true
250
248
  value = values[arg_key]
251
249
  elsif default_value?
252
- has_value = true
253
250
  value = default_value
254
251
  default_used = true
252
+ else
253
+ # no value at all
254
+ owner.validate_directive_argument(self, nil)
255
+ return
255
256
  end
256
257
 
257
- if has_value
258
- loaded_value = nil
259
- coerced_value = context.schema.error_handler.with_error_handling(context) do
260
- type.coerce_input(value, context)
261
- end
258
+ loaded_value = nil
259
+ coerced_value = context.schema.error_handler.with_error_handling(context) do
260
+ type.coerce_input(value, context)
261
+ end
262
262
 
263
- # TODO this should probably be inside after_lazy
264
- if loads && !from_resolver?
265
- loaded_value = if type.list?
266
- loaded_values = coerced_value.map { |val| owner.load_application_object(self, loads, val, context) }
267
- context.schema.after_any_lazies(loaded_values) { |result| result }
268
- else
269
- context.query.with_error_handling do
270
- owner.load_application_object(self, loads, coerced_value, context)
271
- end
263
+ # TODO this should probably be inside after_lazy
264
+ if loads && !from_resolver?
265
+ loaded_value = if type.list?
266
+ loaded_values = coerced_value.map { |val| owner.load_application_object(self, loads, val, context) }
267
+ context.schema.after_any_lazies(loaded_values) { |result| result }
268
+ else
269
+ context.query.with_error_handling do
270
+ owner.load_application_object(self, loads, coerced_value, context)
272
271
  end
273
272
  end
273
+ end
274
274
 
275
- coerced_value = if loaded_value
276
- loaded_value
277
- else
278
- coerced_value
275
+ coerced_value = if loaded_value
276
+ loaded_value
277
+ else
278
+ coerced_value
279
+ end
280
+
281
+ # If this isn't lazy, then the block returns eagerly and assigns the result here
282
+ # If it _is_ lazy, then we write the lazy to the hash, then update it later
283
+ argument_values[arg_key] = context.schema.after_lazy(coerced_value) do |coerced_value|
284
+ owner.validate_directive_argument(self, coerced_value)
285
+ prepared_value = context.schema.error_handler.with_error_handling(context) do
286
+ prepare_value(parent_object, coerced_value, context: context)
279
287
  end
280
288
 
281
- # If this isn't lazy, then the block returns eagerly and assigns the result here
282
- # If it _is_ lazy, then we write the lazy to the hash, then update it later
283
- argument_values[arg_key] = context.schema.after_lazy(coerced_value) do |coerced_value|
284
- owner.validate_directive_argument(self, coerced_value)
285
- prepared_value = context.schema.error_handler.with_error_handling(context) do
286
- prepare_value(parent_object, coerced_value, context: context)
287
- end
289
+ # TODO code smell to access such a deeply-nested constant in a distant module
290
+ argument_values[arg_key] = GraphQL::Execution::Interpreter::ArgumentValue.new(
291
+ value: prepared_value,
292
+ definition: self,
293
+ default_used: default_used,
294
+ )
295
+ end
296
+ end
288
297
 
289
- # TODO code smell to access such a deeply-nested constant in a distant module
290
- argument_values[arg_key] = GraphQL::Execution::Interpreter::ArgumentValue.new(
291
- value: prepared_value,
292
- definition: self,
293
- default_used: default_used,
294
- )
295
- end
296
- else
297
- # has_value is false
298
- owner.validate_directive_argument(self, nil)
298
+ # @api private
299
+ def validate_default_value
300
+ coerced_default_value = begin
301
+ type.coerce_isolated_result(default_value) unless default_value.nil?
302
+ rescue GraphQL::Schema::Enum::UnresolvedValueError
303
+ # It raises this, which is helpful at runtime, but not here...
304
+ default_value
305
+ end
306
+ res = type.valid_isolated_input?(coerced_default_value)
307
+ if !res
308
+ raise InvalidDefaultValueError.new(self)
309
+ end
310
+ end
311
+
312
+ class InvalidDefaultValueError < GraphQL::Error
313
+ def initialize(argument)
314
+ message = "`#{argument.path}` has an invalid default value: `#{argument.default_value.inspect}` isn't accepted by `#{argument.type.to_type_signature}`; update the default value or the argument type."
315
+ super(message)
299
316
  end
300
317
  end
301
318
 
@@ -39,7 +39,19 @@ module GraphQL
39
39
  transform_name = arguments[:by]
40
40
  if TRANSFORMS.include?(transform_name) && return_value.respond_to?(transform_name)
41
41
  return_value = return_value.public_send(transform_name)
42
- context.namespace(:interpreter)[:runtime].write_in_response(path, return_value)
42
+ response = context.namespace(:interpreter)[:runtime].response
43
+ *keys, last = path
44
+ keys.each do |key|
45
+ if response && (response = response[key])
46
+ next
47
+ else
48
+ break
49
+ end
50
+ end
51
+ if response
52
+ response[last] = return_value
53
+ end
54
+ nil
43
55
  end
44
56
  end
45
57
  end
@@ -374,16 +374,36 @@ module GraphQL
374
374
  # @param extension [Class] Extension class
375
375
  # @param options [Hash] Optional extension options
376
376
  def extension(extension, **options)
377
- extensions << {extension => options}
377
+ @own_extensions ||= []
378
+ @own_extensions << {extension => options}
378
379
  end
379
380
 
380
381
  # @api private
381
382
  def extensions
382
- @extensions ||= []
383
+ own_exts = @own_extensions
384
+ # Jump through some hoops to avoid creating arrays when we don't actually need them
385
+ if superclass.respond_to?(:extensions)
386
+ s_exts = superclass.extensions
387
+ if own_exts
388
+ if s_exts.any?
389
+ own_exts + s_exts
390
+ else
391
+ own_exts
392
+ end
393
+ else
394
+ s_exts
395
+ end
396
+ else
397
+ own_exts || EMPTY_ARRAY
398
+ end
383
399
  end
384
400
 
385
401
  private
386
402
 
403
+ def own_extensions
404
+ @own_extensions
405
+ end
406
+
387
407
  def own_arguments_loads_as_type
388
408
  @own_arguments_loads_as_type ||= {}
389
409
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "1.12.10"
3
+ VERSION = "1.12.11"
4
4
  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.12.10
4
+ version: 1.12.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-18 00:00:00.000000000 Z
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -369,7 +369,6 @@ files:
369
369
  - lib/graphql/execution/interpreter/arguments_cache.rb
370
370
  - lib/graphql/execution/interpreter/execution_errors.rb
371
371
  - lib/graphql/execution/interpreter/handles_raw_value.rb
372
- - lib/graphql/execution/interpreter/hash_response.rb
373
372
  - lib/graphql/execution/interpreter/resolve.rb
374
373
  - lib/graphql/execution/interpreter/runtime.rb
375
374
  - lib/graphql/execution/lazy.rb
@@ -485,6 +484,7 @@ files:
485
484
  - lib/graphql/runtime_type_error.rb
486
485
  - lib/graphql/scalar_type.rb
487
486
  - lib/graphql/schema.rb
487
+ - lib/graphql/schema/addition.rb
488
488
  - lib/graphql/schema/argument.rb
489
489
  - lib/graphql/schema/base_64_bp.rb
490
490
  - lib/graphql/schema/base_64_encoder.rb
@@ -699,7 +699,7 @@ metadata:
699
699
  source_code_uri: https://github.com/rmosolgo/graphql-ruby
700
700
  bug_tracker_uri: https://github.com/rmosolgo/graphql-ruby/issues
701
701
  mailing_list_uri: https://tinyletter.com/graphql-ruby
702
- post_install_message:
702
+ post_install_message:
703
703
  rdoc_options: []
704
704
  require_paths:
705
705
  - lib
@@ -714,8 +714,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
714
714
  - !ruby/object:Gem::Version
715
715
  version: '0'
716
716
  requirements: []
717
- rubygems_version: 3.2.15
718
- signing_key:
717
+ rubygems_version: 3.1.4
718
+ signing_key:
719
719
  specification_version: 4
720
720
  summary: A GraphQL language and runtime for Ruby
721
721
  test_files: []
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GraphQL
4
- module Execution
5
- class Interpreter
6
- # This response class handles `#write` by accumulating
7
- # values into a Hash.
8
- class HashResponse
9
- def initialize
10
- @result = {}
11
- end
12
-
13
- def final_value
14
- @result
15
- end
16
-
17
- def inspect
18
- "#<#{self.class.name} result=#{@result.inspect}>"
19
- end
20
-
21
- # Add `value` at `path`.
22
- # @return [void]
23
- def write(path, value)
24
- if path.empty?
25
- @result = value
26
- elsif (write_target = @result)
27
- i = 0
28
- prefinal_steps = path.size - 1
29
- # Use `while` to avoid a closure
30
- while i < prefinal_steps
31
- path_part = path[i]
32
- i += 1
33
- write_target = write_target[path_part]
34
- end
35
- path_part = path[i]
36
- write_target[path_part] = value
37
- else
38
- # The response is completely nulled out
39
- end
40
-
41
- nil
42
- end
43
- end
44
- end
45
- end
46
- end