graphql 2.4.4 → 2.4.6

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.

Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/analysis/visitor.rb +1 -1
  3. data/lib/graphql/analysis.rb +3 -3
  4. data/lib/graphql/autoload.rb +37 -0
  5. data/lib/graphql/current.rb +1 -1
  6. data/lib/graphql/dataloader/async_dataloader.rb +4 -4
  7. data/lib/graphql/dataloader/source.rb +1 -1
  8. data/lib/graphql/dataloader.rb +6 -9
  9. data/lib/graphql/execution/interpreter/resolve.rb +3 -3
  10. data/lib/graphql/execution/interpreter/runtime.rb +7 -7
  11. data/lib/graphql/execution/interpreter.rb +4 -4
  12. data/lib/graphql/language/cache.rb +13 -0
  13. data/lib/graphql/language/document_from_schema_definition.rb +8 -7
  14. data/lib/graphql/language/lexer.rb +4 -1
  15. data/lib/graphql/language/printer.rb +8 -8
  16. data/lib/graphql/pagination/connection.rb +1 -1
  17. data/lib/graphql/query/context/scoped_context.rb +1 -1
  18. data/lib/graphql/query/context.rb +6 -5
  19. data/lib/graphql/query/variable_validation_error.rb +1 -1
  20. data/lib/graphql/query.rb +12 -10
  21. data/lib/graphql/railtie.rb +9 -0
  22. data/lib/graphql/schema/addition.rb +1 -1
  23. data/lib/graphql/schema/directive/flagged.rb +1 -1
  24. data/lib/graphql/schema/directive.rb +1 -1
  25. data/lib/graphql/schema/field/scope_extension.rb +1 -1
  26. data/lib/graphql/schema/field.rb +10 -10
  27. data/lib/graphql/schema/field_extension.rb +1 -1
  28. data/lib/graphql/schema/has_single_input_argument.rb +3 -1
  29. data/lib/graphql/schema/input_object.rb +64 -27
  30. data/lib/graphql/schema/interface.rb +1 -1
  31. data/lib/graphql/schema/loader.rb +1 -1
  32. data/lib/graphql/schema/member/has_arguments.rb +25 -17
  33. data/lib/graphql/schema/member/has_directives.rb +3 -3
  34. data/lib/graphql/schema/member/has_fields.rb +18 -0
  35. data/lib/graphql/schema/member/has_interfaces.rb +4 -4
  36. data/lib/graphql/schema/member/has_validators.rb +1 -1
  37. data/lib/graphql/schema/object.rb +8 -0
  38. data/lib/graphql/schema/relay_classic_mutation.rb +0 -1
  39. data/lib/graphql/schema/resolver.rb +5 -5
  40. data/lib/graphql/schema/subscription.rb +2 -2
  41. data/lib/graphql/schema/union.rb +1 -1
  42. data/lib/graphql/schema/validator.rb +1 -1
  43. data/lib/graphql/schema/visibility/migration.rb +1 -0
  44. data/lib/graphql/schema/visibility/profile.rb +10 -2
  45. data/lib/graphql/schema/visibility/visit.rb +2 -2
  46. data/lib/graphql/schema/visibility.rb +33 -19
  47. data/lib/graphql/schema/warden.rb +18 -5
  48. data/lib/graphql/schema.rb +17 -9
  49. data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +1 -1
  50. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -1
  51. data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +1 -1
  52. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +1 -1
  53. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +1 -1
  54. data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +1 -1
  55. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
  56. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +1 -1
  57. data/lib/graphql/subscriptions.rb +1 -1
  58. data/lib/graphql/testing/helpers.rb +2 -2
  59. data/lib/graphql/types/relay/connection_behaviors.rb +2 -2
  60. data/lib/graphql/types/relay/edge_behaviors.rb +1 -1
  61. data/lib/graphql/types.rb +18 -11
  62. data/lib/graphql/version.rb +1 -1
  63. data/lib/graphql.rb +81 -47
  64. metadata +3 -2
@@ -37,7 +37,7 @@ module GraphQL
37
37
  @interface_type_memberships = nil
38
38
  @directives = nil
39
39
  @types = nil
40
- @references = nil
40
+ @all_references = nil
41
41
  @loaded_all = false
42
42
  end
43
43
 
@@ -53,7 +53,7 @@ module GraphQL
53
53
 
54
54
  def all_references
55
55
  load_all
56
- @references
56
+ @all_references
57
57
  end
58
58
 
59
59
  def get_type(type_name)
@@ -146,7 +146,7 @@ module GraphQL
146
146
  attr_reader :cached_profiles
147
147
 
148
148
  def profile_for(context, visibility_profile)
149
- if @profiles.any?
149
+ if !@profiles.empty?
150
150
  if visibility_profile.nil?
151
151
  if @dynamic
152
152
  if context.is_a?(Query::NullContext)
@@ -154,7 +154,7 @@ module GraphQL
154
154
  else
155
155
  @schema.visibility_profile_class.new(context: context, schema: @schema)
156
156
  end
157
- elsif @profiles.any?
157
+ elsif !@profiles.empty?
158
158
  raise ArgumentError, "#{@schema} expects a visibility profile, but `visibility_profile:` wasn't passed. Provide a `visibility_profile:` value or add `dynamic: true` to your visibility configuration."
159
159
  end
160
160
  elsif !@profiles.include?(visibility_profile)
@@ -202,7 +202,7 @@ module GraphQL
202
202
  @interface_type_memberships = Hash.new { |h, interface_type| h[interface_type] = [] }.compare_by_identity
203
203
  @directives = []
204
204
  @types = {} # String => Module
205
- @references = Hash.new { |h, member| h[member] = [] }.compare_by_identity
205
+ @all_references = Hash.new { |h, member| h[member] = Set.new.compare_by_identity }.compare_by_identity
206
206
  @unions_for_references = Set.new
207
207
  @visit = Visibility::Visit.new(@schema) do |member|
208
208
  if member.is_a?(Module)
@@ -216,11 +216,12 @@ module GraphQL
216
216
  else
217
217
  @types[member.graphql_name] = member
218
218
  end
219
+ member.directives.each { |dir| @all_references[dir.class] << member }
219
220
  if member < GraphQL::Schema::Directive
220
221
  @directives << member
221
222
  elsif member.respond_to?(:interface_type_memberships)
222
223
  member.interface_type_memberships.each do |itm|
223
- @references[itm.abstract_type] << member
224
+ @all_references[itm.abstract_type] << member
224
225
  @interface_type_memberships[itm.abstract_type] << itm
225
226
  end
226
227
  elsif member < GraphQL::Schema::Union
@@ -228,20 +229,33 @@ module GraphQL
228
229
  end
229
230
  elsif member.is_a?(GraphQL::Schema::Argument)
230
231
  member.validate_default_value
231
- @references[member.type.unwrap] << member
232
+ @all_references[member.type.unwrap] << member
233
+ if !(dirs = member.directives).empty?
234
+ dir_owner = member.owner
235
+ if dir_owner.respond_to?(:owner)
236
+ dir_owner = dir_owner.owner
237
+ end
238
+ dirs.each { |dir| @all_references[dir.class] << dir_owner }
239
+ end
232
240
  elsif member.is_a?(GraphQL::Schema::Field)
233
- @references[member.type.unwrap] << member
241
+ @all_references[member.type.unwrap] << member
242
+ if !(dirs = member.directives).empty?
243
+ dir_owner = member.owner
244
+ dirs.each { |dir| @all_references[dir.class] << dir_owner }
245
+ end
246
+ elsif member.is_a?(GraphQL::Schema::EnumValue)
247
+ if !(dirs = member.directives).empty?
248
+ dir_owner = member.owner
249
+ dirs.each { |dir| @all_references[dir.class] << dir_owner }
250
+ end
234
251
  end
235
252
  true
236
253
  end
237
254
 
238
- @schema.root_types.each do |t|
239
- @references[t] << true
240
- end
255
+ @schema.root_types.each { |t| @all_references[t] << true }
256
+ @schema.introspection_system.types.each_value { |t| @all_references[t] << true }
257
+ @schema.directives.each_value { |dir_class| @all_references[dir_class] << true }
241
258
 
242
- @schema.introspection_system.types.each_value do |t|
243
- @references[t] << true
244
- end
245
259
  @visit.visit_each(types: []) # visit default directives
246
260
  end
247
261
 
@@ -258,20 +272,20 @@ module GraphQL
258
272
  # TODO: somehow don't iterate over all these,
259
273
  # only the ones that may have been modified
260
274
  @interface_type_memberships.each do |int_type, type_memberships|
261
- referers = @references[int_type].select { |r| r.is_a?(GraphQL::Schema::Field) }
262
- if referers.any?
275
+ referers = @all_references[int_type].select { |r| r.is_a?(GraphQL::Schema::Field) }
276
+ if !referers.empty?
263
277
  type_memberships.each do |type_membership|
264
278
  implementor_type = type_membership.object_type
265
279
  # Add new items only:
266
- @references[implementor_type] |= referers
280
+ @all_references[implementor_type] |= referers
267
281
  end
268
282
  end
269
283
  end
270
284
 
271
285
  @unions_for_references.each do |union_type|
272
- refs = @references[union_type]
286
+ refs = @all_references[union_type]
273
287
  union_type.all_possible_types.each do |object_type|
274
- @references[object_type] |= refs # Add new items
288
+ @all_references[object_type] |= refs # Add new items
275
289
  end
276
290
  end
277
291
  end
@@ -72,6 +72,7 @@ module GraphQL
72
72
  def interface_type_memberships(obj_t, ctx); obj_t.interface_type_memberships; end
73
73
  def arguments(owner, ctx); owner.arguments(ctx); end
74
74
  def loadable?(type, ctx); type.visible?(ctx); end
75
+ def loadable_possible_types(type, ctx); type.possible_types(ctx); end
75
76
  def visibility_profile
76
77
  @visibility_profile ||= Warden::VisibilityProfile.new(self)
77
78
  end
@@ -106,6 +107,7 @@ module GraphQL
106
107
  def get_field(parent_type, field_name); @schema.get_field(parent_type, field_name); end
107
108
  def reachable_type?(type_name); true; end
108
109
  def loadable?(type, _ctx); true; end
110
+ def loadable_possible_types(union_type, _ctx); union_type.possible_types; end
109
111
  def reachable_types; @schema.types.values; end # rubocop:disable Development/ContextIsPassedCop
110
112
  def possible_types(type_defn); @schema.possible_types(type_defn, Query::NullContext.instance, false); end
111
113
  def interfaces(obj_type); obj_type.interfaces; end
@@ -180,6 +182,10 @@ module GraphQL
180
182
  @warden.loadable?(t, ctx)
181
183
  end
182
184
 
185
+ def loadable_possible_types(t, ctx)
186
+ @warden.loadable_possible_types(t, ctx)
187
+ end
188
+
183
189
  def reachable_type?(type_name)
184
190
  !!@warden.reachable_type?(type_name)
185
191
  end
@@ -204,7 +210,7 @@ module GraphQL
204
210
  @visible_possible_types = @visible_fields = @visible_arguments = @visible_enum_arrays =
205
211
  @visible_enum_values = @visible_interfaces = @type_visibility = @type_memberships =
206
212
  @visible_and_reachable_type = @unions = @unfiltered_interfaces =
207
- @reachable_type_set = @visibility_profile =
213
+ @reachable_type_set = @visibility_profile = @loadable_possible_types =
208
214
  nil
209
215
  @skip_warning = schema.plugins.any? { |(plugin, _opts)| plugin == GraphQL::Schema::Warden }
210
216
  end
@@ -229,6 +235,13 @@ module GraphQL
229
235
  !reachable_type_set.include?(type) && visible_type?(type)
230
236
  end
231
237
 
238
+ def loadable_possible_types(union_type, _ctx)
239
+ @loadable_possible_types ||= read_through do |t|
240
+ t.possible_types # unfiltered
241
+ end
242
+ @loadable_possible_types[union_type]
243
+ end
244
+
232
245
  # @return [GraphQL::BaseType, nil] The type named `type_name`, if it exists (else `nil`)
233
246
  def get_type(type_name)
234
247
  @visible_types ||= read_through do |name|
@@ -297,7 +310,7 @@ module GraphQL
297
310
  def arguments(argument_owner, ctx = nil)
298
311
  @visible_arguments ||= read_through { |o|
299
312
  args = o.arguments(@context)
300
- if args.any?
313
+ if !args.empty?
301
314
  args = args.values
302
315
  args.select! { |a| visible_argument?(a, @context) }
303
316
  args
@@ -329,7 +342,7 @@ module GraphQL
329
342
  def interfaces(obj_type)
330
343
  @visible_interfaces ||= read_through { |t|
331
344
  ints = t.interfaces(@context)
332
- if ints.any?
345
+ if !ints.empty?
333
346
  ints.select! { |i| visible_type?(i) }
334
347
  end
335
348
  ints
@@ -389,9 +402,9 @@ module GraphQL
389
402
  next true if root_type?(type_defn) || type_defn.introspection?
390
403
 
391
404
  if type_defn.kind.union?
392
- possible_types(type_defn).any? && (referenced?(type_defn) || orphan_type?(type_defn))
405
+ !possible_types(type_defn).empty? && (referenced?(type_defn) || orphan_type?(type_defn))
393
406
  elsif type_defn.kind.interface?
394
- if possible_types(type_defn).any?
407
+ if !possible_types(type_defn).empty?
395
408
  true
396
409
  else
397
410
  if @context.respond_to?(:logger) && (logger = @context.logger)
@@ -47,6 +47,8 @@ require "graphql/schema/relay_classic_mutation"
47
47
  require "graphql/schema/subscription"
48
48
  require "graphql/schema/visibility"
49
49
 
50
+ GraphQL.ensure_eager_load!
51
+
50
52
  module GraphQL
51
53
  # A GraphQL schema which may be queried with {GraphQL::Query}.
52
54
  #
@@ -73,6 +75,9 @@ module GraphQL
73
75
  class Schema
74
76
  extend GraphQL::Schema::Member::HasAstNode
75
77
  extend GraphQL::Schema::FindInheritedValue
78
+ extend Autoload
79
+
80
+ autoload :BUILT_IN_TYPES, "graphql/schema/built_in_types"
76
81
 
77
82
  class DuplicateNamesError < GraphQL::Error
78
83
  attr_reader :duplicated_name
@@ -233,7 +238,7 @@ module GraphQL
233
238
  add_trace_options_for(mode, default_options)
234
239
 
235
240
  Class.new(base_class) do
236
- mods.any? && include(*mods)
241
+ !mods.empty? && include(*mods)
237
242
  end
238
243
  end
239
244
  end
@@ -321,7 +326,7 @@ module GraphQL
321
326
  # @param plugin [#use] A Schema plugin
322
327
  # @return void
323
328
  def use(plugin, **kwargs)
324
- if kwargs.any?
329
+ if !kwargs.empty?
325
330
  plugin.use(self, **kwargs)
326
331
  else
327
332
  plugin.use(self)
@@ -691,7 +696,7 @@ module GraphQL
691
696
  # and generally speaking, we won't inherit any values.
692
697
  # So optimize the most common case -- don't create a duplicate Hash.
693
698
  inherited_value = find_inherited_value(:references_to, EMPTY_HASH)
694
- if inherited_value.any?
699
+ if !inherited_value.empty?
695
700
  inherited_value.merge(own_references_to)
696
701
  else
697
702
  own_references_to
@@ -977,7 +982,7 @@ module GraphQL
977
982
  # @param new_extra_types [Module] Type definitions to include in printing and introspection, even though they aren't referenced in the schema
978
983
  # @return [Array<Module>] Type definitions added to this schema
979
984
  def extra_types(*new_extra_types)
980
- if new_extra_types.any?
985
+ if !new_extra_types.empty?
981
986
  new_extra_types = new_extra_types.flatten
982
987
  @own_extra_types ||= []
983
988
  @own_extra_types.concat(new_extra_types)
@@ -1002,10 +1007,10 @@ module GraphQL
1002
1007
  # @param new_orphan_types [Array<Class<GraphQL::Schema::Object>>] Object types to register as implementations of interfaces in the schema.
1003
1008
  # @return [Array<Class<GraphQL::Schema::Object>>] All previously-registered orphan types for this schema
1004
1009
  def orphan_types(*new_orphan_types)
1005
- if new_orphan_types.any?
1010
+ if !new_orphan_types.empty?
1006
1011
  new_orphan_types = new_orphan_types.flatten
1007
1012
  non_object_types = new_orphan_types.reject { |ot| ot.is_a?(Class) && ot < GraphQL::Schema::Object }
1008
- if non_object_types.any?
1013
+ if !non_object_types.empty?
1009
1014
  raise ArgumentError, <<~ERR
1010
1015
  Only object type classes should be added as `orphan_types(...)`.
1011
1016
 
@@ -1022,7 +1027,7 @@ module GraphQL
1022
1027
 
1023
1028
  inherited_ot = find_inherited_value(:orphan_types, nil)
1024
1029
  if inherited_ot
1025
- if own_orphan_types.any?
1030
+ if !own_orphan_types.empty?
1026
1031
  inherited_ot + own_orphan_types
1027
1032
  else
1028
1033
  inherited_ot
@@ -1332,12 +1337,12 @@ module GraphQL
1332
1337
  # Add several directives at once
1333
1338
  # @param new_directives [Class]
1334
1339
  def directives(*new_directives)
1335
- if new_directives.any?
1340
+ if !new_directives.empty?
1336
1341
  new_directives.flatten.each { |d| directive(d) }
1337
1342
  end
1338
1343
 
1339
1344
  inherited_dirs = find_inherited_value(:directives, default_directives)
1340
- if own_directives.any?
1345
+ if !own_directives.empty?
1341
1346
  inherited_dirs.merge(own_directives)
1342
1347
  else
1343
1348
  inherited_dirs
@@ -1802,3 +1807,6 @@ module GraphQL
1802
1807
  end
1803
1808
  end
1804
1809
  end
1810
+
1811
+ require "graphql/schema/loader"
1812
+ require "graphql/schema/printer"
@@ -16,7 +16,7 @@ module GraphQL
16
16
 
17
17
  def validate_arguments(node)
18
18
  argument_defns = node.arguments
19
- if argument_defns.any?
19
+ if !argument_defns.empty?
20
20
  args_by_name = Hash.new { |h, k| h[k] = [] }
21
21
  argument_defns.each { |a| args_by_name[a.name] << a }
22
22
  args_by_name.each do |name, defns|
@@ -25,7 +25,7 @@ module GraphQL
25
25
  def validate_field_selections(ast_node, resolved_type)
26
26
  msg = if resolved_type.nil?
27
27
  nil
28
- elsif ast_node.selections.any? && resolved_type.kind.leaf?
28
+ elsif !ast_node.selections.empty? && resolved_type.kind.leaf?
29
29
  selection_strs = ast_node.selections.map do |n|
30
30
  case n
31
31
  when GraphQL::Language::Nodes::InlineFragment
@@ -32,7 +32,7 @@ module GraphQL
32
32
 
33
33
  def on_document(node, parent)
34
34
  super
35
- if @schema_definition_nodes.any?
35
+ if !@schema_definition_nodes.empty?
36
36
  add_error(GraphQL::StaticValidation::NoDefinitionsArePresentError.new(%|Query cannot contain schema definitions|, nodes: @schema_definition_nodes))
37
37
  end
38
38
  end
@@ -24,7 +24,7 @@ module GraphQL
24
24
  .map!(&:name)
25
25
 
26
26
  missing_names = required_argument_names - present_argument_names
27
- if missing_names.any?
27
+ if !missing_names.empty?
28
28
  add_error(GraphQL::StaticValidation::RequiredArgumentsArePresentError.new(
29
29
  "#{ast_node.class.name.split("::").last} '#{ast_node.name}' is missing required arguments: #{missing_names.join(", ")}",
30
30
  nodes: ast_node,
@@ -21,7 +21,7 @@ module GraphQL
21
21
 
22
22
  DIRECTIVE_NODE_HOOKS.each do |method_name|
23
23
  define_method(method_name) do |node, parent|
24
- if node.directives.any?
24
+ if !node.directives.empty?
25
25
  validate_directive_location(node)
26
26
  end
27
27
  super(node, parent)
@@ -4,7 +4,7 @@ module GraphQL
4
4
  module VariableNamesAreUnique
5
5
  def on_operation_definition(node, parent)
6
6
  var_defns = node.variables
7
- if var_defns.any?
7
+ if !var_defns.empty?
8
8
  vars_by_name = Hash.new { |h, k| h[k] = [] }
9
9
  var_defns.each { |v| vars_by_name[v.name] << v }
10
10
  vars_by_name.each do |name, defns|
@@ -21,7 +21,7 @@ module GraphQL
21
21
  end
22
22
  node_values = node_values.select { |value| value.is_a? GraphQL::Language::Nodes::VariableIdentifier }
23
23
 
24
- if node_values.any?
24
+ if !node_values.empty?
25
25
  argument_owner = case parent
26
26
  when GraphQL::Language::Nodes::Field
27
27
  context.field_definition
@@ -171,7 +171,7 @@ module GraphQL
171
171
  events_by_fingerprint = @events[topic]
172
172
  object = nil
173
173
  events_by_fingerprint.each do |_fingerprint, events|
174
- if events.any? && events.first == initial_event
174
+ if !events.empty? && events.first == initial_event
175
175
  # The fingerprint has told us that this response should be shared by all subscribers,
176
176
  # so just run it once, then deliver the result to every subscriber
177
177
  first_event = events.first
@@ -291,7 +291,7 @@ module GraphQL
291
291
  end
292
292
  end
293
293
 
294
- if missing_arg_names.any?
294
+ if !missing_arg_names.empty?
295
295
  arg_owner_name = if arg_owner.is_a?(GraphQL::Schema::Field)
296
296
  arg_owner.path
297
297
  elsif arg_owner.is_a?(Class)
@@ -58,7 +58,7 @@ module GraphQL
58
58
  query_context[:current_field] = visible_field
59
59
  field_args = visible_field.coerce_arguments(graphql_result, arguments, query_context)
60
60
  field_args = schema.sync_lazy(field_args)
61
- if visible_field.extras.any?
61
+ if !visible_field.extras.empty?
62
62
  extra_args = {}
63
63
  visible_field.extras.each do |extra|
64
64
  extra_args[extra] = case extra
@@ -92,7 +92,7 @@ module GraphQL
92
92
  end
93
93
  graphql_result
94
94
  else
95
- unfiltered_type = schema.use_visibility_profile? ? schema.visibility.get_type(type_name) : schema.get_type(type_name) # rubocop:disable ContextIsPassedCop
95
+ unfiltered_type = schema.use_visibility_profile? ? schema.visibility.get_type(type_name) : schema.get_type(type_name) # rubocop:disable Development/ContextIsPassedCop
96
96
  if unfiltered_type
97
97
  raise TypeNotVisibleError.new(type_name: type_name)
98
98
  else
@@ -196,7 +196,7 @@ module GraphQL
196
196
  def edges
197
197
  # Assume that whatever authorization needed to happen
198
198
  # already happened at the connection level.
199
- current_runtime_state = Thread.current[:__graphql_runtime_info]
199
+ current_runtime_state = Fiber[:__graphql_runtime_info]
200
200
  query_runtime_state = current_runtime_state[context.query]
201
201
  query_runtime_state.was_authorized_by_scope_items = @object.was_authorized_by_scope_items?
202
202
  @object.edges
@@ -205,7 +205,7 @@ module GraphQL
205
205
  def nodes
206
206
  # Assume that whatever authorization needed to happen
207
207
  # already happened at the connection level.
208
- current_runtime_state = Thread.current[:__graphql_runtime_info]
208
+ current_runtime_state = Fiber[:__graphql_runtime_info]
209
209
  query_runtime_state = current_runtime_state[context.query]
210
210
  query_runtime_state.was_authorized_by_scope_items = @object.was_authorized_by_scope_items?
211
211
  @object.nodes
@@ -14,7 +14,7 @@ module GraphQL
14
14
  end
15
15
 
16
16
  def node
17
- current_runtime_state = Thread.current[:__graphql_runtime_info]
17
+ current_runtime_state = Fiber[:__graphql_runtime_info]
18
18
  query_runtime_state = current_runtime_state[context.query]
19
19
  query_runtime_state.was_authorized_by_scope_items = @object.was_authorized_by_scope_items?
20
20
  @object.node
data/lib/graphql/types.rb CHANGED
@@ -1,12 +1,19 @@
1
1
  # frozen_string_literal: true
2
- require "graphql/types/boolean"
3
- require "graphql/types/big_int"
4
- require "graphql/types/float"
5
- require "graphql/types/id"
6
- require "graphql/types/int"
7
- require "graphql/types/iso_8601_date"
8
- require "graphql/types/iso_8601_date_time"
9
- require "graphql/types/iso_8601_duration"
10
- require "graphql/types/json"
11
- require "graphql/types/string"
12
- require "graphql/types/relay"
2
+
3
+ module GraphQL
4
+ module Types
5
+ extend Autoload
6
+
7
+ autoload :Boolean, "graphql/types/boolean"
8
+ autoload :BigInt, "graphql/types/big_int"
9
+ autoload :Float, "graphql/types/float"
10
+ autoload :ID, "graphql/types/id"
11
+ autoload :Int, "graphql/types/int"
12
+ autoload :JSON, "graphql/types/json"
13
+ autoload :String, "graphql/types/string"
14
+ autoload :ISO8601Date, "graphql/types/iso_8601_date"
15
+ autoload :ISO8601DateTime, "graphql/types/iso_8601_date_time"
16
+ autoload :ISO8601Duration, "graphql/types/iso_8601_duration"
17
+ autoload :Relay, "graphql/types/relay"
18
+ end
19
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "2.4.4"
3
+ VERSION = "2.4.6"
4
4
  end
data/lib/graphql.rb CHANGED
@@ -5,8 +5,19 @@ require "set"
5
5
  require "singleton"
6
6
  require "forwardable"
7
7
  require "fiber/storage"
8
+ require "graphql/autoload"
8
9
 
9
10
  module GraphQL
11
+ extend Autoload
12
+
13
+ # Load all `autoload`-configured classes, and also eager-load dependents who have autoloads of their own.
14
+ def self.eager_load!
15
+ super
16
+ Query.eager_load!
17
+ Types.eager_load!
18
+ Schema.eager_load!
19
+ end
20
+
10
21
  class Error < StandardError
11
22
  end
12
23
 
@@ -71,56 +82,79 @@ This is probably a bug in GraphQL-Ruby, please report this error on GitHub: http
71
82
  class << self
72
83
  # If true, the parser should raise when an integer or float is followed immediately by an identifier (instead of a space or punctuation)
73
84
  attr_accessor :reject_numbers_followed_by_names
85
+
86
+ # If `production?` is detected but `eager_load!` wasn't called, emit a warning.
87
+ # @return [void]
88
+ def ensure_eager_load!
89
+ if production? && !eager_loading?
90
+ warn <<~WARNING
91
+ GraphQL-Ruby thinks this is a production deployment but didn't eager-load its constants. Address this by:
92
+
93
+ - Calling `GraphQL.eager_load!` in a production-only initializer or setup hook
94
+ - Assign `GraphQL.env = "..."` to something _other_ than `"production"` (for example, `GraphQL.env = "development"`)
95
+
96
+ More details: https://graphql-ruby.org/schema/definition#production-considerations
97
+ WARNING
98
+ end
99
+ end
100
+
101
+ attr_accessor :env
102
+
103
+ private
104
+
105
+ # Detect whether this is a production deployment or not
106
+ def production?
107
+ if env
108
+ # Manually assigned to production?
109
+ env == "production"
110
+ else
111
+ (detected_env = ENV["RACK_ENV"] || ENV["RAILS_ENV"] || ENV["HANAMI_ENV"] || ENV["APP_ENV"]) && detected_env.to_s.downcase == "production"
112
+ end
113
+ end
74
114
  end
75
115
 
76
116
  self.reject_numbers_followed_by_names = false
77
- end
78
117
 
79
- # Order matters for these:
80
-
81
- require "graphql/execution_error"
82
- require "graphql/runtime_type_error"
83
- require "graphql/unresolved_type_error"
84
- require "graphql/invalid_null_error"
85
- require "graphql/analysis_error"
86
- require "graphql/coercion_error"
87
- require "graphql/invalid_name_error"
88
- require "graphql/integer_decoding_error"
89
- require "graphql/integer_encoding_error"
90
- require "graphql/string_encoding_error"
91
- require "graphql/date_encoding_error"
92
- require "graphql/duration_encoding_error"
93
- require "graphql/type_kinds"
94
- require "graphql/name_validator"
95
- require "graphql/language"
96
-
97
- require_relative "./graphql/railtie" if defined? Rails::Railtie
98
-
99
- require "graphql/analysis"
100
- require "graphql/tracing"
101
- require "graphql/dig"
102
- require "graphql/execution"
103
- require "graphql/pagination"
104
- require "graphql/schema"
105
- require "graphql/query"
106
- require "graphql/dataloader"
107
- require "graphql/types"
108
- require "graphql/static_validation"
109
- require "graphql/execution"
110
- require "graphql/schema/built_in_types"
111
- require "graphql/schema/loader"
112
- require "graphql/schema/printer"
113
- require "graphql/introspection"
114
- require "graphql/relay"
118
+ autoload :ExecutionError, "graphql/execution_error"
119
+ autoload :RuntimeTypeError, "graphql/runtime_type_error"
120
+ autoload :UnresolvedTypeError, "graphql/unresolved_type_error"
121
+ autoload :InvalidNullError, "graphql/invalid_null_error"
122
+ autoload :AnalysisError, "graphql/analysis_error"
123
+ autoload :CoercionError, "graphql/coercion_error"
124
+ autoload :InvalidNameError, "graphql/invalid_name_error"
125
+ autoload :IntegerDecodingError, "graphql/integer_decoding_error"
126
+ autoload :IntegerEncodingError, "graphql/integer_encoding_error"
127
+ autoload :StringEncodingError, "graphql/string_encoding_error"
128
+ autoload :DateEncodingError, "graphql/date_encoding_error"
129
+ autoload :DurationEncodingError, "graphql/duration_encoding_error"
130
+ autoload :TypeKinds, "graphql/type_kinds"
131
+ autoload :NameValidator, "graphql/name_validator"
132
+ autoload :Language, "graphql/language"
133
+
134
+ autoload :Analysis, "graphql/analysis"
135
+ autoload :Tracing, "graphql/tracing"
136
+ autoload :Dig, "graphql/dig"
137
+ autoload :Execution, "graphql/execution"
138
+ autoload :Pagination, "graphql/pagination"
139
+ autoload :Schema, "graphql/schema"
140
+ autoload :Query, "graphql/query"
141
+ autoload :Dataloader, "graphql/dataloader"
142
+ autoload :Types, "graphql/types"
143
+ autoload :StaticValidation, "graphql/static_validation"
144
+ autoload :Execution, "graphql/execution"
145
+ autoload :Introspection, "graphql/introspection"
146
+ autoload :Relay, "graphql/relay"
147
+ autoload :Subscriptions, "graphql/subscriptions"
148
+ autoload :ParseError, "graphql/parse_error"
149
+ autoload :Backtrace, "graphql/backtrace"
150
+
151
+ autoload :UnauthorizedError, "graphql/unauthorized_error"
152
+ autoload :UnauthorizedEnumValueError, "graphql/unauthorized_enum_value_error"
153
+ autoload :UnauthorizedFieldError, "graphql/unauthorized_field_error"
154
+ autoload :LoadApplicationObjectFailedError, "graphql/load_application_object_failed_error"
155
+ autoload :Testing, "graphql/testing"
156
+ autoload :Current, "graphql/current"
157
+ end
115
158
 
116
159
  require "graphql/version"
117
- require "graphql/subscriptions"
118
- require "graphql/parse_error"
119
- require "graphql/backtrace"
120
-
121
- require "graphql/unauthorized_error"
122
- require "graphql/unauthorized_enum_value_error"
123
- require "graphql/unauthorized_field_error"
124
- require "graphql/load_application_object_failed_error"
125
- require "graphql/testing"
126
- require "graphql/current"
160
+ require "graphql/railtie" if defined? Rails::Railtie
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: 2.4.4
4
+ version: 2.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-18 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -328,6 +328,7 @@ files:
328
328
  - lib/graphql/analysis/query_depth.rb
329
329
  - lib/graphql/analysis/visitor.rb
330
330
  - lib/graphql/analysis_error.rb
331
+ - lib/graphql/autoload.rb
331
332
  - lib/graphql/backtrace.rb
332
333
  - lib/graphql/backtrace/inspect_result.rb
333
334
  - lib/graphql/backtrace/table.rb