graphql 2.4.3 → 2.4.5

Sign up to get free protection for your applications and to get access to all the features.
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 +7 -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 +12 -12
  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/profile.rb +61 -235
  44. data/lib/graphql/schema/visibility/visit.rb +190 -0
  45. data/lib/graphql/schema/visibility.rb +162 -26
  46. data/lib/graphql/schema/warden.rb +4 -4
  47. data/lib/graphql/schema.rb +33 -12
  48. data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +1 -1
  49. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -1
  50. data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +1 -1
  51. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +1 -1
  52. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +1 -1
  53. data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +1 -1
  54. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
  55. data/lib/graphql/static_validation/validation_context.rb +1 -0
  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 +80 -47
  64. metadata +4 -2
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require "graphql/schema/visibility/profile"
3
3
  require "graphql/schema/visibility/migration"
4
+ require "graphql/schema/visibility/visit"
4
5
 
5
6
  module GraphQL
6
7
  class Schema
@@ -13,40 +14,76 @@ module GraphQL
13
14
  # @param migration_errors [Boolean] if `true`, raise an error when `Visibility` and `Warden` return different results
14
15
  def self.use(schema, dynamic: false, profiles: EmptyObjects::EMPTY_HASH, preload: (defined?(Rails) ? Rails.env.production? : nil), migration_errors: false)
15
16
  schema.visibility = self.new(schema, dynamic: dynamic, preload: preload, profiles: profiles, migration_errors: migration_errors)
17
+ if preload
18
+ schema.visibility.preload
19
+ end
16
20
  end
17
21
 
18
22
  def initialize(schema, dynamic:, preload:, profiles:, migration_errors:)
19
23
  @schema = schema
20
24
  schema.use_visibility_profile = true
21
- if migration_errors
22
- schema.visibility_profile_class = Migration
25
+ schema.visibility_profile_class = if migration_errors
26
+ Visibility::Migration
27
+ else
28
+ Visibility::Profile
23
29
  end
24
30
  @preload = preload
25
31
  @profiles = profiles
26
32
  @cached_profiles = {}
27
33
  @dynamic = dynamic
28
34
  @migration_errors = migration_errors
29
- if preload
30
- # Traverse the schema now (and in the *_configured hooks below)
31
- # To make sure things are loaded during boot
32
- @preloaded_types = Set.new
33
- types_to_visit = [
34
- @schema.query,
35
- @schema.mutation,
36
- @schema.subscription,
37
- *@schema.introspection_system.types.values,
38
- *@schema.introspection_system.entry_points.map { |ep| ep.type.unwrap },
39
- *@schema.orphan_types,
40
- ]
41
- # Root types may have been nil:
42
- types_to_visit.compact!
43
- ensure_all_loaded(types_to_visit)
44
-
45
- profiles.each do |profile_name, example_ctx|
46
- example_ctx[:visibility_profile] = profile_name
47
- prof = profile_for(example_ctx, profile_name)
48
- prof.all_types # force loading
49
- end
35
+ # Top-level type caches:
36
+ @visit = nil
37
+ @interface_type_memberships = nil
38
+ @directives = nil
39
+ @types = nil
40
+ @all_references = nil
41
+ @loaded_all = false
42
+ end
43
+
44
+ def all_directives
45
+ load_all
46
+ @directives
47
+ end
48
+
49
+ def all_interface_type_memberships
50
+ load_all
51
+ @interface_type_memberships
52
+ end
53
+
54
+ def all_references
55
+ load_all
56
+ @all_references
57
+ end
58
+
59
+ def get_type(type_name)
60
+ load_all
61
+ @types[type_name]
62
+ end
63
+
64
+ def preload?
65
+ @preload
66
+ end
67
+
68
+ def preload
69
+ # Traverse the schema now (and in the *_configured hooks below)
70
+ # To make sure things are loaded during boot
71
+ @preloaded_types = Set.new
72
+ types_to_visit = [
73
+ @schema.query,
74
+ @schema.mutation,
75
+ @schema.subscription,
76
+ *@schema.introspection_system.types.values,
77
+ *@schema.introspection_system.entry_points.map { |ep| ep.type.unwrap },
78
+ *@schema.orphan_types,
79
+ ]
80
+ # Root types may have been nil:
81
+ types_to_visit.compact!
82
+ ensure_all_loaded(types_to_visit)
83
+ @profiles.each do |profile_name, example_ctx|
84
+ example_ctx[:visibility_profile] = profile_name
85
+ prof = profile_for(example_ctx, profile_name)
86
+ prof.all_types # force loading
50
87
  end
51
88
  end
52
89
 
@@ -109,7 +146,7 @@ module GraphQL
109
146
  attr_reader :cached_profiles
110
147
 
111
148
  def profile_for(context, visibility_profile)
112
- if @profiles.any?
149
+ if !@profiles.empty?
113
150
  if visibility_profile.nil?
114
151
  if @dynamic
115
152
  if context.is_a?(Query::NullContext)
@@ -117,7 +154,7 @@ module GraphQL
117
154
  else
118
155
  @schema.visibility_profile_class.new(context: context, schema: @schema)
119
156
  end
120
- elsif @profiles.any?
157
+ elsif !@profiles.empty?
121
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."
122
159
  end
123
160
  elsif !@profiles.include?(visibility_profile)
@@ -132,7 +169,10 @@ module GraphQL
132
169
  end
133
170
  end
134
171
 
135
- private
172
+ attr_reader :top_level
173
+
174
+ # @api private
175
+ attr_reader :unfiltered_interface_type_memberships
136
176
 
137
177
  def top_level_profile(refresh: false)
138
178
  if refresh
@@ -141,6 +181,8 @@ module GraphQL
141
181
  @top_level_profile ||= @schema.visibility_profile_class.new(context: Query::NullContext.instance, schema: @schema)
142
182
  end
143
183
 
184
+ private
185
+
144
186
  def ensure_all_loaded(types_to_visit)
145
187
  while (type = types_to_visit.shift)
146
188
  if type.kind.fields? && @preloaded_types.add?(type)
@@ -153,6 +195,100 @@ module GraphQL
153
195
  top_level_profile(refresh: true)
154
196
  nil
155
197
  end
198
+
199
+ def load_all(types: nil)
200
+ if @visit.nil?
201
+ # Set up the visit system
202
+ @interface_type_memberships = Hash.new { |h, interface_type| h[interface_type] = [] }.compare_by_identity
203
+ @directives = []
204
+ @types = {} # String => Module
205
+ @all_references = Hash.new { |h, member| h[member] = Set.new.compare_by_identity }.compare_by_identity
206
+ @unions_for_references = Set.new
207
+ @visit = Visibility::Visit.new(@schema) do |member|
208
+ if member.is_a?(Module)
209
+ type_name = member.graphql_name
210
+ if (prev_t = @types[type_name])
211
+ if prev_t.is_a?(Array)
212
+ prev_t << member
213
+ else
214
+ @types[type_name] = [member, prev_t]
215
+ end
216
+ else
217
+ @types[member.graphql_name] = member
218
+ end
219
+ member.directives.each { |dir| @all_references[dir.class] << member }
220
+ if member < GraphQL::Schema::Directive
221
+ @directives << member
222
+ elsif member.respond_to?(:interface_type_memberships)
223
+ member.interface_type_memberships.each do |itm|
224
+ @all_references[itm.abstract_type] << member
225
+ @interface_type_memberships[itm.abstract_type] << itm
226
+ end
227
+ elsif member < GraphQL::Schema::Union
228
+ @unions_for_references << member
229
+ end
230
+ elsif member.is_a?(GraphQL::Schema::Argument)
231
+ member.validate_default_value
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
240
+ elsif member.is_a?(GraphQL::Schema::Field)
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
251
+ end
252
+ true
253
+ end
254
+
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 }
258
+
259
+ @visit.visit_each(types: []) # visit default directives
260
+ end
261
+
262
+ if types
263
+ @visit.visit_each(types: types, directives: [])
264
+ elsif @loaded_all == false
265
+ @loaded_all = true
266
+ @visit.visit_each
267
+ else
268
+ # already loaded all
269
+ return
270
+ end
271
+
272
+ # TODO: somehow don't iterate over all these,
273
+ # only the ones that may have been modified
274
+ @interface_type_memberships.each do |int_type, type_memberships|
275
+ referers = @all_references[int_type].select { |r| r.is_a?(GraphQL::Schema::Field) }
276
+ if !referers.empty?
277
+ type_memberships.each do |type_membership|
278
+ implementor_type = type_membership.object_type
279
+ # Add new items only:
280
+ @all_references[implementor_type] |= referers
281
+ end
282
+ end
283
+ end
284
+
285
+ @unions_for_references.each do |union_type|
286
+ refs = @all_references[union_type]
287
+ union_type.all_possible_types.each do |object_type|
288
+ @all_references[object_type] |= refs # Add new items
289
+ end
290
+ end
291
+ end
156
292
  end
157
293
  end
158
294
  end
@@ -297,7 +297,7 @@ module GraphQL
297
297
  def arguments(argument_owner, ctx = nil)
298
298
  @visible_arguments ||= read_through { |o|
299
299
  args = o.arguments(@context)
300
- if args.any?
300
+ if !args.empty?
301
301
  args = args.values
302
302
  args.select! { |a| visible_argument?(a, @context) }
303
303
  args
@@ -329,7 +329,7 @@ module GraphQL
329
329
  def interfaces(obj_type)
330
330
  @visible_interfaces ||= read_through { |t|
331
331
  ints = t.interfaces(@context)
332
- if ints.any?
332
+ if !ints.empty?
333
333
  ints.select! { |i| visible_type?(i) }
334
334
  end
335
335
  ints
@@ -389,9 +389,9 @@ module GraphQL
389
389
  next true if root_type?(type_defn) || type_defn.introspection?
390
390
 
391
391
  if type_defn.kind.union?
392
- possible_types(type_defn).any? && (referenced?(type_defn) || orphan_type?(type_defn))
392
+ !possible_types(type_defn).empty? && (referenced?(type_defn) || orphan_type?(type_defn))
393
393
  elsif type_defn.kind.interface?
394
- if possible_types(type_defn).any?
394
+ if !possible_types(type_defn).empty?
395
395
  true
396
396
  else
397
397
  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
  #
@@ -233,7 +235,7 @@ module GraphQL
233
235
  add_trace_options_for(mode, default_options)
234
236
 
235
237
  Class.new(base_class) do
236
- mods.any? && include(*mods)
238
+ !mods.empty? && include(*mods)
237
239
  end
238
240
  end
239
241
  end
@@ -321,7 +323,7 @@ module GraphQL
321
323
  # @param plugin [#use] A Schema plugin
322
324
  # @return void
323
325
  def use(plugin, **kwargs)
324
- if kwargs.any?
326
+ if !kwargs.empty?
325
327
  plugin.use(self, **kwargs)
326
328
  else
327
329
  plugin.use(self)
@@ -446,7 +448,12 @@ module GraphQL
446
448
  raise GraphQL::Error, "Second definition of `query(...)` (#{dup_defn.inspect}) is invalid, already configured with #{@query_object.inspect}"
447
449
  elsif use_visibility_profile?
448
450
  if block_given?
449
- @query_object = lazy_load_block
451
+ if visibility.preload?
452
+ @query_object = lazy_load_block.call
453
+ self.visibility.query_configured(@query_object)
454
+ else
455
+ @query_object = lazy_load_block
456
+ end
450
457
  else
451
458
  @query_object = new_query_object
452
459
  self.visibility.query_configured(@query_object)
@@ -480,7 +487,12 @@ module GraphQL
480
487
  raise GraphQL::Error, "Second definition of `mutation(...)` (#{dup_defn.inspect}) is invalid, already configured with #{@mutation_object.inspect}"
481
488
  elsif use_visibility_profile?
482
489
  if block_given?
483
- @mutation_object = lazy_load_block
490
+ if visibility.preload?
491
+ @mutation_object = lazy_load_block.call
492
+ self.visibility.mutation_configured(@mutation_object)
493
+ else
494
+ @mutation_object = lazy_load_block
495
+ end
484
496
  else
485
497
  @mutation_object = new_mutation_object
486
498
  self.visibility.mutation_configured(@mutation_object)
@@ -514,7 +526,12 @@ module GraphQL
514
526
  raise GraphQL::Error, "Second definition of `subscription(...)` (#{dup_defn.inspect}) is invalid, already configured with #{@subscription_object.inspect}"
515
527
  elsif use_visibility_profile?
516
528
  if block_given?
517
- @subscription_object = lazy_load_block
529
+ if visibility.preload?
530
+ @subscription_object = lazy_load_block.call
531
+ visibility.subscription_configured(@subscription_object)
532
+ else
533
+ @subscription_object = lazy_load_block
534
+ end
518
535
  else
519
536
  @subscription_object = new_subscription_object
520
537
  self.visibility.subscription_configured(@subscription_object)
@@ -676,7 +693,7 @@ module GraphQL
676
693
  # and generally speaking, we won't inherit any values.
677
694
  # So optimize the most common case -- don't create a duplicate Hash.
678
695
  inherited_value = find_inherited_value(:references_to, EMPTY_HASH)
679
- if inherited_value.any?
696
+ if !inherited_value.empty?
680
697
  inherited_value.merge(own_references_to)
681
698
  else
682
699
  own_references_to
@@ -962,7 +979,7 @@ module GraphQL
962
979
  # @param new_extra_types [Module] Type definitions to include in printing and introspection, even though they aren't referenced in the schema
963
980
  # @return [Array<Module>] Type definitions added to this schema
964
981
  def extra_types(*new_extra_types)
965
- if new_extra_types.any?
982
+ if !new_extra_types.empty?
966
983
  new_extra_types = new_extra_types.flatten
967
984
  @own_extra_types ||= []
968
985
  @own_extra_types.concat(new_extra_types)
@@ -987,10 +1004,10 @@ module GraphQL
987
1004
  # @param new_orphan_types [Array<Class<GraphQL::Schema::Object>>] Object types to register as implementations of interfaces in the schema.
988
1005
  # @return [Array<Class<GraphQL::Schema::Object>>] All previously-registered orphan types for this schema
989
1006
  def orphan_types(*new_orphan_types)
990
- if new_orphan_types.any?
1007
+ if !new_orphan_types.empty?
991
1008
  new_orphan_types = new_orphan_types.flatten
992
1009
  non_object_types = new_orphan_types.reject { |ot| ot.is_a?(Class) && ot < GraphQL::Schema::Object }
993
- if non_object_types.any?
1010
+ if !non_object_types.empty?
994
1011
  raise ArgumentError, <<~ERR
995
1012
  Only object type classes should be added as `orphan_types(...)`.
996
1013
 
@@ -1007,7 +1024,7 @@ module GraphQL
1007
1024
 
1008
1025
  inherited_ot = find_inherited_value(:orphan_types, nil)
1009
1026
  if inherited_ot
1010
- if own_orphan_types.any?
1027
+ if !own_orphan_types.empty?
1011
1028
  inherited_ot + own_orphan_types
1012
1029
  else
1013
1030
  inherited_ot
@@ -1317,12 +1334,12 @@ module GraphQL
1317
1334
  # Add several directives at once
1318
1335
  # @param new_directives [Class]
1319
1336
  def directives(*new_directives)
1320
- if new_directives.any?
1337
+ if !new_directives.empty?
1321
1338
  new_directives.flatten.each { |d| directive(d) }
1322
1339
  end
1323
1340
 
1324
1341
  inherited_dirs = find_inherited_value(:directives, default_directives)
1325
- if own_directives.any?
1342
+ if !own_directives.empty?
1326
1343
  inherited_dirs.merge(own_directives)
1327
1344
  else
1328
1345
  inherited_dirs
@@ -1787,3 +1804,7 @@ module GraphQL
1787
1804
  end
1788
1805
  end
1789
1806
  end
1807
+
1808
+ require "graphql/schema/built_in_types"
1809
+ require "graphql/schema/loader"
1810
+ 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
@@ -29,6 +29,7 @@ module GraphQL
29
29
  @visitor = visitor_class.new(document, self)
30
30
  end
31
31
 
32
+ # TODO stop using def_delegators because of Array allocations
32
33
  def_delegators :@visitor,
33
34
  :path, :type_definition, :field_definition, :argument_definition,
34
35
  :parent_type_definition, :directive_definition, :object_types, :dependencies
@@ -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::Visibility::Profile.null_profile(schema: schema, context: context).type(type_name)
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.3"
3
+ VERSION = "2.4.5"
4
4
  end