graphql 2.6.13 → 2.6.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.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/templates/graphql_controller.erb +7 -1
  3. data/lib/graphql/analysis/max_query_complexity.rb +3 -2
  4. data/lib/graphql/analysis/max_query_depth.rb +2 -1
  5. data/lib/graphql/analysis/query_complexity.rb +2 -1
  6. data/lib/graphql/analysis/query_depth.rb +1 -1
  7. data/lib/graphql/analysis/visitor.rb +14 -2
  8. data/lib/graphql/analysis.rb +4 -5
  9. data/lib/graphql/analysis_error.rb +1 -1
  10. data/lib/graphql/coercion_error.rb +1 -1
  11. data/lib/graphql/current.rb +5 -1
  12. data/lib/graphql/dashboard.rb +1 -1
  13. data/lib/graphql/date_encoding_error.rb +3 -1
  14. data/lib/graphql/duration_encoding_error.rb +3 -1
  15. data/lib/graphql/execution/directive_checks.rb +2 -1
  16. data/lib/graphql/execution/errors.rb +18 -7
  17. data/lib/graphql/execution/field_resolve_step.rb +245 -159
  18. data/lib/graphql/execution/input_values.rb +162 -120
  19. data/lib/graphql/execution/interpreter/runtime.rb +9 -5
  20. data/lib/graphql/execution/lookahead.rb +19 -8
  21. data/lib/graphql/execution/next.rb +1 -0
  22. data/lib/graphql/execution/prepare_object_step.rb +37 -13
  23. data/lib/graphql/execution/runner.rb +19 -12
  24. data/lib/graphql/execution/selections_step.rb +1 -1
  25. data/lib/graphql/execution/variable_values.rb +248 -0
  26. data/lib/graphql/float_decoding_error.rb +3 -1
  27. data/lib/graphql/integer_decoding_error.rb +3 -1
  28. data/lib/graphql/introspection/base_object.rb +1 -1
  29. data/lib/graphql/introspection/directive_location_enum.rb +1 -1
  30. data/lib/graphql/introspection/directive_type.rb +3 -1
  31. data/lib/graphql/introspection/dynamic_fields.rb +3 -1
  32. data/lib/graphql/introspection/enum_value_type.rb +3 -1
  33. data/lib/graphql/introspection/field_type.rb +5 -1
  34. data/lib/graphql/introspection/type_kind_enum.rb +1 -1
  35. data/lib/graphql/introspection.rb +2 -1
  36. data/lib/graphql/language/comment.rb +2 -1
  37. data/lib/graphql/language/generation.rb +2 -1
  38. data/lib/graphql/language/lexer.rb +30 -22
  39. data/lib/graphql/language/parser.rb +15 -8
  40. data/lib/graphql/language.rb +1 -1
  41. data/lib/graphql/name_validator.rb +2 -1
  42. data/lib/graphql/pagination/relation_connection.rb +21 -10
  43. data/lib/graphql/pagination.rb +1 -1
  44. data/lib/graphql/query/fingerprint.rb +2 -1
  45. data/lib/graphql/query/partial.rb +5 -2
  46. data/lib/graphql/query.rb +8 -12
  47. data/lib/graphql/railtie.rb +1 -1
  48. data/lib/graphql/relay.rb +1 -1
  49. data/lib/graphql/rubocop.rb +1 -1
  50. data/lib/graphql/runtime_error.rb +1 -1
  51. data/lib/graphql/runtime_type_error.rb +1 -1
  52. data/lib/graphql/schema/addition.rb +55 -48
  53. data/lib/graphql/schema/always_visible.rb +3 -1
  54. data/lib/graphql/schema/argument.rb +14 -3
  55. data/lib/graphql/schema/base_64_encoder.rb +3 -1
  56. data/lib/graphql/schema/build_from_definition.rb +435 -173
  57. data/lib/graphql/schema/built_in_types.rb +2 -2
  58. data/lib/graphql/schema/directive/deprecated.rb +1 -1
  59. data/lib/graphql/schema/directive/include.rb +2 -1
  60. data/lib/graphql/schema/directive/skip.rb +2 -1
  61. data/lib/graphql/schema/directive/specified_by.rb +1 -1
  62. data/lib/graphql/schema/directive.rb +16 -0
  63. data/lib/graphql/schema/field/connection_extension.rb +1 -1
  64. data/lib/graphql/schema/field/scope_extension.rb +2 -1
  65. data/lib/graphql/schema/field.rb +4 -1
  66. data/lib/graphql/schema/find_inherited_value.rb +5 -1
  67. data/lib/graphql/schema/member/build_type.rb +5 -2
  68. data/lib/graphql/schema/member/graphql_type_names.rb +1 -1
  69. data/lib/graphql/schema/member/has_arguments.rb +0 -4
  70. data/lib/graphql/schema/member/has_directives.rb +27 -23
  71. data/lib/graphql/schema/member/has_interfaces.rb +0 -2
  72. data/lib/graphql/schema/member/has_path.rb +2 -1
  73. data/lib/graphql/schema/member/has_unresolved_type_error.rb +2 -1
  74. data/lib/graphql/schema/member.rb +3 -2
  75. data/lib/graphql/schema/mutation.rb +6 -1
  76. data/lib/graphql/schema/object.rb +11 -3
  77. data/lib/graphql/schema/resolver.rb +2 -2
  78. data/lib/graphql/schema/type_expression.rb +3 -1
  79. data/lib/graphql/schema/validator/all_validator.rb +6 -3
  80. data/lib/graphql/schema.rb +4 -2
  81. data/lib/graphql/static_validation/all_rules.rb +1 -1
  82. data/lib/graphql/static_validation/base_visitor.rb +125 -53
  83. data/lib/graphql/static_validation/definition_dependencies.rb +14 -2
  84. data/lib/graphql/static_validation/interpreter_visitor.rb +1 -1
  85. data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +4 -1
  86. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +2 -0
  87. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +8 -4
  88. data/lib/graphql/static_validation/rules/fragments_are_finite.rb +2 -1
  89. data/lib/graphql/static_validation/rules/fragments_are_named.rb +2 -1
  90. data/lib/graphql/static_validation/rules/fragments_are_named_error.rb +4 -1
  91. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +6 -3
  92. data/lib/graphql/static_validation/rules/fragments_are_used.rb +2 -1
  93. data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +3 -1
  94. data/lib/graphql/static_validation/rules/mutation_root_exists.rb +3 -2
  95. data/lib/graphql/static_validation/rules/mutation_root_exists_error.rb +4 -1
  96. data/lib/graphql/static_validation/rules/no_definitions_are_present_error.rb +4 -1
  97. data/lib/graphql/static_validation/rules/not_single_subscription_error.rb +4 -1
  98. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +9 -2
  99. data/lib/graphql/static_validation/rules/query_root_exists.rb +3 -2
  100. data/lib/graphql/static_validation/rules/query_root_exists_error.rb +4 -1
  101. data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present_error.rb +10 -4
  102. data/lib/graphql/static_validation/rules/subscription_root_exists_and_single_subscription_selection.rb +8 -6
  103. data/lib/graphql/static_validation/rules/subscription_root_exists_error.rb +4 -1
  104. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +5 -4
  105. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +2 -1
  106. data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +2 -1
  107. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
  108. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
  109. data/lib/graphql/static_validation/validation_context.rb +49 -14
  110. data/lib/graphql/static_validation/validation_timeout_error.rb +4 -1
  111. data/lib/graphql/static_validation.rb +1 -2
  112. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +14 -13
  113. data/lib/graphql/testing.rb +1 -1
  114. data/lib/graphql/tracing/legacy_trace.rb +1 -1
  115. data/lib/graphql/tracing/null_trace.rb +1 -1
  116. data/lib/graphql/types/big_int.rb +4 -1
  117. data/lib/graphql/types/boolean.rb +3 -1
  118. data/lib/graphql/types/id.rb +3 -1
  119. data/lib/graphql/types/iso_8601_date.rb +1 -0
  120. data/lib/graphql/types/iso_8601_date_time.rb +6 -2
  121. data/lib/graphql/types/iso_8601_duration.rb +3 -0
  122. data/lib/graphql/types/relay/base_connection.rb +1 -1
  123. data/lib/graphql/types/relay/base_edge.rb +1 -1
  124. data/lib/graphql/types/relay/node.rb +1 -1
  125. data/lib/graphql/types/relay/page_info.rb +1 -1
  126. data/lib/graphql/types/relay/page_info_behaviors.rb +4 -1
  127. data/lib/graphql/types/relay.rb +1 -1
  128. data/lib/graphql/types/string.rb +1 -0
  129. data/lib/graphql/types.rb +1 -1
  130. data/lib/graphql/version.rb +2 -2
  131. metadata +3 -4
  132. data/lib/graphql/query/variables.rb +0 -99
  133. data/lib/graphql/static_validation/literal_validator.rb +0 -157
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
  module GraphQL
4
4
  class Schema
5
5
  BUILT_IN_TYPES = {
@@ -8,6 +8,6 @@ module GraphQL
8
8
  "Float" => GraphQL::Types::Float,
9
9
  "Boolean" => GraphQL::Types::Boolean,
10
10
  "ID" => GraphQL::Types::ID,
11
- }
11
+ } #: Hash[String, GraphQL::Schema::Member::type_definition]
12
12
  end
13
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
  module GraphQL
4
4
  class Schema
5
5
  class Directive < GraphQL::Schema::Member
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
  module GraphQL
4
4
  class Schema
5
5
  class Directive < GraphQL::Schema::Member
@@ -17,6 +17,7 @@ module GraphQL
17
17
 
18
18
  default_directive true
19
19
 
20
+ #: (Hash[Symbol, untyped] args, GraphQL::Query::Context ctx) -> bool
20
21
  def self.static_include?(args, ctx)
21
22
  !!args[:if]
22
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
  module GraphQL
4
4
  class Schema
5
5
  class Directive < GraphQL::Schema::Member
@@ -17,6 +17,7 @@ module GraphQL
17
17
 
18
18
  default_directive true
19
19
 
20
+ #: (Hash[Symbol, untyped] args, GraphQL::Query::Context ctx) -> bool
20
21
  def self.static_include?(args, ctx)
21
22
  !args[:if]
22
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
  module GraphQL
4
4
  class Schema
5
5
  class Directive < GraphQL::Schema::Member
@@ -114,6 +114,10 @@ module GraphQL
114
114
  @repeatable = new_value
115
115
  end
116
116
 
117
+ # When this is a Hash, instances with equal, statically coercible arguments reuse the first instance's coerced arguments.
118
+ # BuildFromDefinition uses this while it builds a schema, then removes it.
119
+ attr_accessor :coerced_arguments_cache # :nodoc:
120
+
117
121
  private
118
122
 
119
123
  def inherited(subclass)
@@ -124,6 +128,7 @@ module GraphQL
124
128
  @locations = parent_class.locations
125
129
  @is_runtime = parent_class.runtime?
126
130
  @repeatable = false
131
+ @coerced_arguments_cache = nil
127
132
  end
128
133
  end
129
134
  end
@@ -144,6 +149,14 @@ module GraphQL
144
149
  def initialize(owner, **arguments)
145
150
  @owner = owner
146
151
  assert_valid_owner
152
+ if (arguments_cache = self.class.coerced_arguments_cache)
153
+ if !self.class.arguments_statically_coercible?
154
+ arguments_cache = nil
155
+ elsif (cached_arguments = arguments_cache[arguments])
156
+ @arguments = cached_arguments
157
+ return
158
+ end
159
+ end
147
160
  # It's be nice if we had the real context here, but we don't. What we _would_ get is:
148
161
  # - error handling
149
162
  # - lazy resolution
@@ -195,6 +208,9 @@ module GraphQL
195
208
  if @arguments.is_a?(GraphQL::ExecutionError)
196
209
  raise @arguments
197
210
  end
211
+ if arguments_cache
212
+ arguments_cache[arguments] = @arguments
213
+ end
198
214
  end
199
215
 
200
216
  def graphql_name
@@ -31,7 +31,7 @@ module GraphQL
31
31
  lookahead = arguments[:lookahead]
32
32
  context.query.after_lazy(value) do |resolved_value|
33
33
  connection = context.schema.connections.populate_connection(field, object.object, resolved_value, original_arguments, context)
34
- connection.lookahead ||= lookahead if connection
34
+ connection.lookahead ||= lookahead if connection.is_a?(GraphQL::Pagination::Connection)
35
35
  connection
36
36
  end
37
37
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
 
4
4
  module GraphQL
5
5
  class Schema
6
6
  class Field
7
7
  class ScopeExtension < GraphQL::Schema::FieldExtension
8
+ #: (object: untyped, arguments: Hash[Symbol, untyped], context: GraphQL::Query::Context, value: untyped, memo: untyped) -> untyped
8
9
  def after_resolve(object:, arguments:, context:, value:, memo:)
9
10
  if object.is_a?(GraphQL::Schema::Object)
10
11
  if value.nil?
@@ -982,11 +982,14 @@ module GraphQL
982
982
  max_possible_page_size = arguments[:last]
983
983
  end
984
984
  elsif arguments.is_a?(GraphQL::ExecutionError) || arguments.is_a?(GraphQL::UnauthorizedError)
985
- raise arguments
985
+ return child_complexity
986
986
  end
987
987
 
988
988
  if max_possible_page_size.nil?
989
989
  max_possible_page_size = default_page_size || query.schema.default_page_size || max_page_size || query.schema.default_max_page_size
990
+ elsif max_possible_page_size < 0
991
+ # Pagination returns no items for a negative `first:` or `last:`, so it mustn't subtract from the total.
992
+ max_possible_page_size = 0
990
993
  end
991
994
 
992
995
  if max_possible_page_size.nil?
@@ -1,20 +1,24 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
  module GraphQL
4
4
  class Schema
5
5
  #--
6
6
  # @requires_ancestor: Module
7
7
  module FindInheritedValue
8
+ #: (Module[untyped] child_cls) -> void
8
9
  def self.extended(child_cls)
9
10
  child_cls.singleton_class.include(GraphQL::EmptyObjects)
10
11
  end
11
12
 
13
+ #: (Module[untyped] child_cls) -> void
12
14
  def self.included(child_cls)
13
15
  child_cls.include(GraphQL::EmptyObjects)
14
16
  end
15
17
 
16
18
  private
17
19
 
20
+ # Returns whatever the inherited configuration method returns, so the result is `untyped`.
21
+ #: (Symbol method_name, ?untyped default_value) -> untyped
18
22
  def find_inherited_value(method_name, default_value = nil)
19
23
  if self.is_a?(Class)
20
24
  superclass.respond_to?(method_name, true) ? superclass.send(method_name) : default_value
@@ -185,12 +185,15 @@ module GraphQL
185
185
  end
186
186
  string2 = string.dup
187
187
 
188
- string2.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') # URLDecoder -> URL_Decoder
189
- string2.gsub!(/([a-z\d])([A-Z])/,'\1_\2') # someThing -> some_Thing
188
+ # URLDecoder -> URL_Decoder, someThing -> some_Thing
189
+ string2.gsub!(UNDERSCORE_BOUNDARY, "_")
190
190
  string2.downcase!
191
191
 
192
192
  string2
193
193
  end
194
+
195
+ UNDERSCORE_BOUNDARY = /(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/
196
+ private_constant :UNDERSCORE_BOUNDARY
194
197
  end
195
198
  end
196
199
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
 
4
4
  module GraphQL
5
5
  class Schema
@@ -150,8 +150,6 @@ module GraphQL
150
150
  child_class.extend(InheritedArguments)
151
151
  end
152
152
 
153
- #--
154
- # @requires_ancestor: singleton(Object)
155
153
  module InheritedArguments
156
154
  def arguments(context = GraphQL::Query::NullContext.instance, require_defined_arguments = true)
157
155
  own_arguments = super(context, require_defined_arguments)
@@ -382,8 +380,6 @@ module GraphQL
382
380
  end
383
381
  end
384
382
 
385
- #--
386
- # @requires_ancestor: singleton(Object)
387
383
  module ArgumentClassAccessor
388
384
  def argument_class(new_arg_class = nil)
389
385
  if new_arg_class
@@ -69,7 +69,13 @@ module GraphQL
69
69
  case schema_member
70
70
  when Class
71
71
  inherited_directives = if schema_member.superclass.respond_to?(directives_method)
72
- get_directives(schema_member.superclass, schema_member.superclass.public_send(directives_method), directives_method)
72
+ superclass_directives = schema_member.superclass.public_send(directives_method)
73
+ if superclass_directives.empty?
74
+ # `superclass_directives` includes inherited ones, so there's nothing to merge
75
+ GraphQL::EmptyObjects::EMPTY_ARRAY
76
+ else
77
+ get_directives(schema_member.superclass, superclass_directives, directives_method)
78
+ end
73
79
  else
74
80
  GraphQL::EmptyObjects::EMPTY_ARRAY
75
81
  end
@@ -85,32 +91,18 @@ module GraphQL
85
91
  else
86
92
  GraphQL::EmptyObjects::EMPTY_ARRAY
87
93
  end
88
- when Module
89
- dirs = nil #: Array[GraphQL::Schema::Directive]?
90
- ancestors = schema_member.ancestors #: Array[untyped]
91
- ancestors.reverse_each do |ancestor|
92
- if ancestor.respond_to?(:own_directives) &&
93
- !(anc_dirs = ancestor.own_directives).empty?
94
- dirs ||= []
95
- merge_directives(dirs, anc_dirs)
96
- end
97
- end
98
- if directives
99
- dirs ||= []
100
- merge_directives(dirs, directives)
101
- end
102
- dirs || GraphQL::EmptyObjects::EMPTY_ARRAY
103
94
  when HasDirectives
104
95
  directives || GraphQL::EmptyObjects::EMPTY_ARRAY
105
96
  else
106
- raise "Invariant: how could #{schema_member} not be a Class, Module, or instance of HasDirectives?"
97
+ raise "Invariant: how could #{schema_member} not be a Class or instance of HasDirectives?"
107
98
  end
108
99
  end
109
100
 
110
101
  private
111
102
 
112
103
  # Modify `target` by adding items from `dirs` such that:
113
- # - Any name conflict is overridden by the incoming member of `dirs`
104
+ # - Any name conflict is overridden by the incoming member(s) of `dirs`.
105
+ # (Repeatable directives replace _all_ same-named directives in `target`, and all incoming ones are kept.)
114
106
  # - Any other member of `dirs` is appended
115
107
  #
116
108
  # **Parameters**
@@ -125,14 +117,26 @@ module GraphQL
125
117
  # :call-seq:
126
118
  # merge_directives(Array[GraphQL::Schema::Directive] target, Array[GraphQL::Schema::Directive] dirs) -> void
127
119
  def merge_directives(target, dirs)
128
- dirs.each do |dir|
129
- if (idx = target.find_index { |d| d.graphql_name == dir.graphql_name })
130
- target.slice!(idx)
131
- target.insert(idx, dir)
120
+ incoming = dirs.group_by(&:graphql_name)
121
+ merged = [] #: Array[GraphQL::Schema::Directive]
122
+ target.each do |d|
123
+ name = d.graphql_name
124
+ if incoming.key?(name)
125
+ # Put the incoming directive(s) where the first overridden one was
126
+ if (replacements = incoming[name])
127
+ merged.concat(replacements)
128
+ incoming[name] = nil
129
+ end
132
130
  else
133
- target << dir
131
+ merged << d
132
+ end
133
+ end
134
+ dirs.each do |dir|
135
+ if incoming[dir.graphql_name]
136
+ merged << dir
134
137
  end
135
138
  end
139
+ target.replace(merged)
136
140
  nil
137
141
  end
138
142
  end
@@ -75,8 +75,6 @@ module GraphQL
75
75
  child_class.extend(InheritedInterfaces)
76
76
  end
77
77
 
78
- #--
79
- # @requires_ancestor: singleton(Object)
80
78
  module InheritedInterfaces
81
79
  def interfaces(context = GraphQL::Query::NullContext.instance)
82
80
  visible_interfaces = super
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
 
4
4
  module GraphQL
5
5
  class Schema
@@ -13,6 +13,7 @@ module GraphQL
13
13
  #
14
14
  # :call-seq:
15
15
  # path() -> String
16
+ #: -> String?
16
17
  def path
17
18
  member = self #: untyped
18
19
  path_str = if member.respond_to?(:graphql_name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
 
4
4
  module GraphQL
5
5
  class Schema
@@ -7,6 +7,7 @@ module GraphQL
7
7
  # Set up a type-specific error to make debugging & bug tracker integration better
8
8
  module HasUnresolvedTypeError
9
9
  private
10
+ #: (Module[untyped] child_class) -> void
10
11
  def add_unresolved_type_error(child_class)
11
12
  if child_class.name # Don't set this for anonymous classes
12
13
  child_class.const_set(:UnresolvedTypeError, Class.new(GraphQL::UnresolvedTypeError))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
  require 'graphql/schema/member/base_dsl_methods'
4
4
  require 'graphql/schema/member/graphql_type_names'
5
5
  require 'graphql/schema/member/has_ast_node'
@@ -23,7 +23,7 @@ module GraphQL
23
23
  #
24
24
  class Member # :nodoc:
25
25
  # A module that defines a GraphQL interface type (it includes `GraphQL::Schema::Interface`).
26
- #: type interface_definition = GraphQL::Schema::Interface::DefinitionMethods & Module
26
+ #: type interface_definition = GraphQL::Schema::Interface::DefinitionMethods & Module[untyped]
27
27
 
28
28
  # A class or module that defines a GraphQL type:
29
29
  # an object, union, enum, scalar or input object class, or an interface module.
@@ -40,6 +40,7 @@ module GraphQL
40
40
  extend HasAstNode
41
41
  extend HasDirectives
42
42
 
43
+ #: (GraphQL::Query::Context _ctx) -> bool
43
44
  def self.authorizes?(_ctx)
44
45
  false
45
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
 
4
4
  module GraphQL
5
5
  class Schema
@@ -67,6 +67,8 @@ module GraphQL
67
67
  extend GraphQL::Schema::Member::HasFields
68
68
  extend GraphQL::Schema::Resolver::HasPayloadType
69
69
 
70
+ # Returns the application's resolved value.
71
+ #: (Hash[Symbol, untyped] _args_hash) -> untyped
70
72
  def call_resolve(_args_hash) # :nodoc:
71
73
  # Clear any cached values from `loads` or authorization:
72
74
  dataloader.clear_cache
@@ -74,17 +76,20 @@ module GraphQL
74
76
  end
75
77
 
76
78
  class << self
79
+ #: (GraphQL::Query::Context context) -> bool
77
80
  def visible?(context)
78
81
  true
79
82
  end
80
83
 
81
84
  private
82
85
 
86
+ #: (GraphQL::Schema::Field field_defn) -> String
83
87
  def conflict_field_name_warning(field_defn)
84
88
  "#{self.graphql_name}'s `field :#{field_defn.name}` conflicts with a built-in method, use `hash_key:` or `method:` to pick a different resolve behavior for this field (for example, `hash_key: :#{field_defn.resolver_method}_value`, and modify the return hash). Or use `method_conflict_warning: false` to suppress this warning."
85
89
  end
86
90
 
87
91
  # Override this to attach self as `mutation`
92
+ #: () -> singleton(GraphQL::Schema::Object)
88
93
  def generate_payload_type
89
94
  payload_class = super
90
95
  payload_class.mutation(self)
@@ -89,12 +89,15 @@ module GraphQL
89
89
  # authorized_new(Object object, GraphQL::Query::Context context) -> GraphQL::Schema::Object | GraphQL::Execution::Lazy | GraphQL::UnauthorizedError
90
90
  def authorized_new(object, context)
91
91
  context.query.current_trace.begin_authorized(self, object, context)
92
+ raised_auth_err = nil #: GraphQL::UnauthorizedError?
92
93
  begin
93
94
  maybe_lazy_auth_val = context.query.current_trace.authorized(query: context.query, type: self, object: object) do
94
95
  begin
95
96
  authorized?(object, context)
96
97
  rescue GraphQL::UnauthorizedError => err
97
- context.schema.unauthorized_object(err)
98
+ # Raising is equivalent to returning `false`; `unauthorized_object` is called below
99
+ raised_auth_err = err
100
+ false
98
101
  rescue StandardError => err
99
102
  context.query.handle_or_reraise(err)
100
103
  end
@@ -107,7 +110,12 @@ module GraphQL
107
110
  GraphQL::Execution::Lazy.new do
108
111
  context.query.current_trace.begin_authorized(self, object, context)
109
112
  context.query.current_trace.authorized_lazy(query: context.query, type: self, object: object) do
110
- res = context.schema.sync_lazy(maybe_lazy_auth_val)
113
+ res = begin
114
+ context.schema.sync_lazy(maybe_lazy_auth_val)
115
+ rescue GraphQL::UnauthorizedError => err
116
+ raised_auth_err = err
117
+ false
118
+ end
111
119
  context.query.current_trace.end_authorized(self, object, context, res)
112
120
  res
113
121
  end
@@ -121,7 +129,7 @@ module GraphQL
121
129
  self.new(object, context)
122
130
  else
123
131
  # It failed the authorization check, so go to the schema's authorized object hook
124
- err = GraphQL::UnauthorizedError.new(object: object, type: self, context: context)
132
+ err = raised_auth_err || GraphQL::UnauthorizedError.new(object: object, type: self, context: context)
125
133
  # If a new value was returned, wrap that instead of the original value
126
134
  begin
127
135
  new_obj = context.schema.unauthorized_object(err)
@@ -125,7 +125,7 @@ module GraphQL
125
125
  exec_result[exec_index] = err
126
126
  rescue StandardError => stderr
127
127
  exec_result[exec_index] = begin
128
- context.query.handle_or_reraise(stderr)
128
+ context.query.handle_or_reraise(stderr, field: @field, arguments: @prepared_arguments, object: object)
129
129
  rescue GraphQL::ExecutionError => ex_err
130
130
  ex_err
131
131
  end
@@ -265,7 +265,7 @@ module GraphQL
265
265
  end
266
266
 
267
267
  def self.authorizes?(context)
268
- self.instance_method(:authorized?).owner != GraphQL::Schema::Resolver
268
+ self.instance_method(:authorized?).owner != GraphQL::Schema::Resolver || super
269
269
  end
270
270
 
271
271
  # Called when an object loaded by `loads:` fails the `.authorized?` check for its resolved GraphQL object type.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
  module GraphQL
4
4
  class Schema
5
5
  module TypeExpression # :nodoc:
@@ -17,6 +17,7 @@ module GraphQL
17
17
  #
18
18
  # :call-seq:
19
19
  # build_type(#type type_owner, GraphQL::Language::Nodes::AbstractNode ast_node) -> Class | GraphQL::Schema::NonNull | GraphQL::Schema:List
20
+ #: (GraphQL::Schema::Visibility::Profile | GraphQL::Schema::Warden::VisibilityProfile type_owner, GraphQL::Language::Nodes::AbstractNode ast_node) -> (GraphQL::Schema::Member::type_definition | GraphQL::Schema::NonNull | GraphQL::Schema::List | nil)
20
21
  def self.build_type(type_owner, ast_node)
21
22
  case ast_node
22
23
  when GraphQL::Language::Nodes::TypeName
@@ -37,6 +38,7 @@ module GraphQL
37
38
  class << self
38
39
  private
39
40
 
41
+ #: (GraphQL::Schema::Member::type_definition | GraphQL::Schema::NonNull | GraphQL::Schema::List | nil type, Symbol wrapper_method) -> (GraphQL::Schema::NonNull | GraphQL::Schema::List | nil)
40
42
  def wrap_type(type, wrapper_method)
41
43
  if type.nil?
42
44
  nil
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
 
4
4
  module GraphQL
5
5
  class Schema
@@ -29,16 +29,19 @@ module GraphQL
29
29
  # validates: { all: { inclusion: { in: 1..12 } } }
30
30
  # ```
31
31
  class AllValidator < Validator
32
+ # `validators` is configuration for other validators, for example `{ format: { with: /.../ } }`.
33
+ #: (validated: GraphQL::Schema::Argument | GraphQL::Schema::Field | singleton(GraphQL::Schema::Resolver) | singleton(GraphQL::Schema::InputObject), ?allow_blank: bool, ?allow_null: bool, **untyped validators) -> void
32
34
  def initialize(validated:, allow_blank: false, allow_null: false, **validators)
33
35
  super(validated: validated, allow_blank: allow_blank, allow_null: allow_null)
34
36
 
35
- @validators = Validator.from_config(validated, validators)
37
+ @validators = Validator.from_config(validated, validators) #: Array[GraphQL::Schema::Validator]
36
38
  end
37
39
 
40
+ #: (untyped object, GraphQL::Query::Context context, untyped value) -> Array[String]
38
41
  def validate(object, context, value)
39
42
  return EMPTY_ARRAY if permitted_empty_value?(value)
40
43
 
41
- all_errors = EMPTY_ARRAY
44
+ all_errors = EMPTY_ARRAY #: Array[String]
42
45
 
43
46
  value.each do |subvalue|
44
47
  @validators.each do |validator|
@@ -2735,8 +2735,10 @@ module GraphQL
2735
2735
  own_union_memberships.merge!(addition.union_memberships)
2736
2736
 
2737
2737
  addition.references.each { |thing, pointers|
2738
- prev_refs = own_references_to[thing] || []
2739
- own_references_to[thing] = prev_refs | pointers.to_a
2738
+ new_refs = pointers.keys
2739
+ prev_refs = own_references_to[thing]
2740
+ # Same as `prev_refs | new_refs`, but faster when `prev_refs` is small and `new_refs` is big
2741
+ own_references_to[thing] = prev_refs ? (prev_refs + (new_refs - prev_refs)) : new_refs
2740
2742
  }
2741
2743
 
2742
2744
  addition.directives.each { |dir_class| own_directives[dir_class.graphql_name] = dir_class }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
  module GraphQL
4
4
  module StaticValidation
5
5
  # Default rules for [GraphQL::StaticValidation::Validator](rdoc-ref:GraphQL::StaticValidation::Validator)