graphql 2.0.6 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c31ecaae04f8ea6bca65c031a2a41d124d8a1e1dade016decfb047cae3f900ae
4
- data.tar.gz: af77a6ac50b38ca0d23a08da8f63fea1ca8f14ef11ccda56de55e678518380c1
3
+ metadata.gz: 39d95cd85a336ff82b22df87f496df97db11ecae05dbf80d090d5bb51445a499
4
+ data.tar.gz: b50ecc9d63922cbe1e7cbbd7d9a049528625584fb0bd6991918e867f8d6e2e45
5
5
  SHA512:
6
- metadata.gz: a6038fd4fe140b2196011e14cc61ba8b0ad72008b3cbe9d317bc87996fe6b42f7f289e188cd0d8c22a9d5f08c558d9774fa3533690355a16258b8276ad885e53
7
- data.tar.gz: ff7c5db4532240f9c11d7f3008441f27c5b3a6948cfe942eaf337711436fe9c678de913a849a2e627689a15a08bb2f90f9a345185945308669447ec31dd61027
6
+ metadata.gz: b404ea0ca0c0a1b4206330514da8d38c5e5f31abd4c93ebc696c91c2177f25e7f40703016742aeb6f8857f1bd208b9012778a21643a7ae08709bd08c994b31eb
7
+ data.tar.gz: 5d41fa5df69f4722bf0bffaca89675b77ff7cb4b1af863550bb5908e03135f82214f516c092b83273c3ff367d20c845a000db9d5bbf5f8e43a3db0a0640a0095
@@ -33,27 +33,13 @@ module Graphql
33
33
  # Return a string UUID for `object`
34
34
  def self.id_from_object(object, type_definition, query_ctx)
35
35
  # For example, use Rails' GlobalID library (https://github.com/rails/globalid):
36
- object_id = object.to_global_id.to_s
37
- # Remove this redundant prefix to make IDs shorter:
38
- object_id = object_id.sub("gid://\#{GlobalID.app}/", "")
39
- encoded_id = Base64.urlsafe_encode64(object_id)
40
- # Remove the "=" padding
41
- encoded_id = encoded_id.sub(/=+/, "")
42
- # Add a type hint
43
- type_hint = type_definition.graphql_name.first
44
- "\#{type_hint}_\#{encoded_id}"
36
+ object.to_gid_param
45
37
  end
46
38
 
47
39
  # Given a string UUID, find the object
48
- def self.object_from_id(encoded_id_with_hint, query_ctx)
40
+ def self.object_from_id(global_id, query_ctx)
49
41
  # For example, use Rails' GlobalID library (https://github.com/rails/globalid):
50
- # Split off the type hint
51
- _type_hint, encoded_id = encoded_id_with_hint.split("_", 2)
52
- # Decode the ID
53
- id = Base64.urlsafe_decode64(encoded_id)
54
- # Rebuild it for Rails then find the object:
55
- full_global_id = "gid://\#{GlobalID.app}/\#{id}"
56
- GlobalID::Locator.locate(full_global_id)
42
+ GlobalID.find(global_id)
57
43
  end
58
44
  RUBY
59
45
  inject_into_file schema_file_path, schema_code, before: /^end\n/m, force: false
@@ -39,9 +39,11 @@ module GraphQL
39
39
  @used_deprecated_arguments << argument.definition.path
40
40
  end
41
41
 
42
+ next if argument.value.nil?
43
+
42
44
  if argument.definition.type.kind.input_object?
43
45
  extract_deprecated_arguments(argument.value.arguments.argument_values) # rubocop:disable Development/ContextIsPassedCop -- runtime args instance
44
- elsif argument.definition.type.list? && !argument.value.nil?
46
+ elsif argument.definition.type.list?
45
47
  argument
46
48
  .value
47
49
  .select { |value| value.respond_to?(:arguments) }
@@ -59,6 +59,13 @@ module GraphQL
59
59
  end
60
60
 
61
61
  if next_results.any?
62
+ # Any pending data loader jobs may populate the
63
+ # resutl arrays or result hashes accumulated in
64
+ # `next_results``. Run those **to completion**
65
+ # before continuing to resolve `next_results`.
66
+ # (Just `.append_job` doesn't work if any pending
67
+ # jobs require multiple passes.)
68
+ dataloader.run
62
69
  dataloader.append_job { resolve(next_results, dataloader) }
63
70
  end
64
71
 
@@ -754,11 +754,16 @@ module GraphQL
754
754
  response_list = GraphQLResultArray.new(result_name, selection_result)
755
755
  response_list.graphql_non_null_list_items = inner_type.non_null?
756
756
  set_result(selection_result, result_name, response_list)
757
-
757
+ result_was_set = false
758
758
  idx = 0
759
- begin
759
+ list_value = begin
760
760
  value.each do |inner_value|
761
761
  break if dead_result?(response_list)
762
+ if !result_was_set
763
+ # Don't set the result unless `.each` is successful
764
+ set_result(selection_result, result_name, response_list)
765
+ result_was_set = true
766
+ end
762
767
  next_path = path.dup
763
768
  next_path << idx
764
769
  this_idx = idx
@@ -772,6 +777,13 @@ module GraphQL
772
777
  resolve_list_item(inner_value, inner_type, next_path, ast_node, field, owner_object, arguments, this_idx, response_list, next_selections, owner_type)
773
778
  end
774
779
  end
780
+ # Maybe the list was empty and the block was never called.
781
+ if !result_was_set
782
+ set_result(selection_result, result_name, response_list)
783
+ result_was_set = true
784
+ end
785
+
786
+ response_list
775
787
  rescue NoMethodError => err
776
788
  # Ruby 2.2 doesn't have NoMethodError#receiver, can't check that one in this case. (It's been EOL since 2017.)
777
789
  if err.name == :each && (err.respond_to?(:receiver) ? err.receiver == value : true)
@@ -781,9 +793,17 @@ module GraphQL
781
793
  # This was some other NoMethodError -- let it bubble to reveal the real error.
782
794
  raise
783
795
  end
796
+ rescue GraphQL::ExecutionError, GraphQL::UnauthorizedError => ex_err
797
+ ex_err
798
+ rescue StandardError => err
799
+ begin
800
+ query.handle_or_reraise(err)
801
+ rescue GraphQL::ExecutionError => ex_err
802
+ ex_err
803
+ end
784
804
  end
785
805
 
786
- response_list
806
+ continue_value(path, list_value, owner_type, field, inner_type.non_null?, ast_node, result_name, selection_result)
787
807
  else
788
808
  raise "Invariant: Unhandled type kind #{current_type.kind} (#{current_type})"
789
809
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  require "graphql/execution/lazy/lazy_method_map"
3
- require "graphql/execution/lazy/resolve"
4
3
 
5
4
  module GraphQL
6
5
  module Execution