graphql 2.4.5 → 2.4.7

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: 576505327425ece2720724b18acb06b712d9574f18bbde7f43242a3288046966
4
- data.tar.gz: 6b67a9aac34abf8e340c8fcdba329ff7e64357f9ade833d909244ec2683c4174
3
+ metadata.gz: 69f8b4084adf0530a973073bcacf76e536975b385e4927525504b648762e496e
4
+ data.tar.gz: ef8e532575d445e0e96c1e5cccb2f6518d4a8759127ba8f27fd4d2aca4ef877a
5
5
  SHA512:
6
- metadata.gz: 394b8ba06f32a1a983b5cb41cf322c361fb05fe68b9dd5946e5d0eb846923fc03edf9674935767a0a06737ccad300a790439a160e0499f82ed0f6ff5223a675d
7
- data.tar.gz: 0410a99ab8efe22a1d130b93d08a12d2a3e989974a50af65416ea4979023826bd829da64d1eeb6d4b9dd75d552547a80e26f100f14a7c107acc0740339044430
6
+ metadata.gz: c9522e680f06a1810e019c64656fba5dd7d7d95e098f136e2f656837c928829eab7a1be5656c7c4c9fd68bf8f262ca9b7ed415d87c12997dc613c9f600e8994b
7
+ data.tar.gz: 99a5a17272d80d555c98f8f091799e5b84656bfd42310e79d64b65140c7b2786e9f23f4759dfefb5b09c8ffc913349bfd0db3bcff5f6475087b350122aadd066
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphQL
4
+ # @see GraphQL::Railtie for automatic Rails integration
4
5
  module Autoload
5
6
  # Register a constant named `const_name` to be loaded from `path`.
6
7
  # This is like `Kernel#autoload` but it tracks the constants so they can be eager-loaded with {#eager_load!}
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphQL
4
- # Support {GraphQL::Parser::Cache}
4
+ # Support {GraphQL::Parser::Cache} and {GraphQL.eager_load!}
5
5
  #
6
6
  # @example Enable the parser cache with default directory
7
7
  #
@@ -359,7 +359,8 @@ module GraphQL
359
359
  if application_object.nil?
360
360
  nil
361
361
  else
362
- maybe_lazy_resolve_type = context.schema.resolve_type(argument.loads, application_object, context)
362
+ arg_loads_type = argument.loads
363
+ maybe_lazy_resolve_type = context.schema.resolve_type(arg_loads_type, application_object, context)
363
364
  context.query.after_lazy(maybe_lazy_resolve_type) do |resolve_type_result|
364
365
  if resolve_type_result.is_a?(Array) && resolve_type_result.size == 2
365
366
  application_object_type, application_object = resolve_type_result
@@ -368,10 +369,17 @@ module GraphQL
368
369
  # application_object is already assigned
369
370
  end
370
371
 
371
- if !(
372
- context.types.possible_types(argument.loads).include?(application_object_type) ||
373
- context.types.loadable?(argument.loads, context)
374
- )
372
+ passes_possible_types_check = if context.types.loadable?(arg_loads_type, context)
373
+ if arg_loads_type.kind.union?
374
+ # This union is used in `loads:` but not otherwise visible to this query
375
+ context.types.loadable_possible_types(arg_loads_type, context).include?(application_object_type)
376
+ else
377
+ true
378
+ end
379
+ else
380
+ context.types.possible_types(arg_loads_type).include?(application_object_type)
381
+ end
382
+ if !passes_possible_types_check
375
383
  err = GraphQL::LoadApplicationObjectFailedError.new(context: context, argument: argument, id: id, object: application_object)
376
384
  application_object = load_application_object_failed(err)
377
385
  end
@@ -112,6 +112,7 @@ module GraphQL
112
112
  :all_types_h,
113
113
  :fields,
114
114
  :loadable?,
115
+ :loadable_possible_types,
115
116
  :type,
116
117
  :arguments,
117
118
  :argument,
@@ -84,6 +84,8 @@ module GraphQL
84
84
  @cached_arguments = Hash.new do |h, owner|
85
85
  h[owner] = non_duplicate_items(owner.all_argument_definitions, @cached_visible_arguments)
86
86
  end.compare_by_identity
87
+
88
+ @loadable_possible_types = Hash.new { |h, union_type| h[union_type] = union_type.possible_types }.compare_by_identity
87
89
  end
88
90
 
89
91
  def field_on_visible_interface?(field, owner)
@@ -249,6 +251,10 @@ module GraphQL
249
251
  !@all_types[t.graphql_name] && @cached_visible[t]
250
252
  end
251
253
 
254
+ def loadable_possible_types(t, _ctx)
255
+ @loadable_possible_types[t]
256
+ end
257
+
252
258
  def loaded_types
253
259
  @all_types.values
254
260
  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|
@@ -47,8 +47,6 @@ 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
-
52
50
  module GraphQL
53
51
  # A GraphQL schema which may be queried with {GraphQL::Query}.
54
52
  #
@@ -75,6 +73,9 @@ module GraphQL
75
73
  class Schema
76
74
  extend GraphQL::Schema::Member::HasAstNode
77
75
  extend GraphQL::Schema::FindInheritedValue
76
+ extend Autoload
77
+
78
+ autoload :BUILT_IN_TYPES, "graphql/schema/built_in_types"
78
79
 
79
80
  class DuplicateNamesError < GraphQL::Error
80
81
  attr_reader :duplicated_name
@@ -1805,6 +1806,5 @@ module GraphQL
1805
1806
  end
1806
1807
  end
1807
1808
 
1808
- require "graphql/schema/built_in_types"
1809
1809
  require "graphql/schema/loader"
1810
1810
  require "graphql/schema/printer"
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require "set"
3
+ require "ostruct"
4
+
3
5
  module GraphQL
4
6
  class Subscriptions
5
7
  # Serialization helpers for passing subscription data around.
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "2.4.5"
3
+ VERSION = "2.4.7"
4
4
  end
data/lib/graphql.rb CHANGED
@@ -15,6 +15,7 @@ module GraphQL
15
15
  super
16
16
  Query.eager_load!
17
17
  Types.eager_load!
18
+ Schema.eager_load!
18
19
  end
19
20
 
20
21
  class Error < StandardError
@@ -81,35 +82,6 @@ This is probably a bug in GraphQL-Ruby, please report this error on GitHub: http
81
82
  class << self
82
83
  # If true, the parser should raise when an integer or float is followed immediately by an identifier (instead of a space or punctuation)
83
84
  attr_accessor :reject_numbers_followed_by_names
84
-
85
- # If `production?` is detected but `eager_load!` wasn't called, emit a warning.
86
- # @return [void]
87
- def ensure_eager_load!
88
- if production? && !eager_loading?
89
- warn <<~WARNING
90
- GraphQL-Ruby thinks this is a production deployment but didn't eager-load its constants. Address this by:
91
-
92
- - Calling `GraphQL.eager_load!` in a production-only initializer or setup hook
93
- - Assign `GraphQL.env = "..."` to something _other_ than `"production"` (for example, `GraphQL.env = "development"`)
94
-
95
- More details: https://graphql-ruby.org/schema/definition#production-considerations
96
- WARNING
97
- end
98
- end
99
-
100
- attr_accessor :env
101
-
102
- private
103
-
104
- # Detect whether this is a production deployment or not
105
- def production?
106
- if env
107
- # Manually assigned to production?
108
- env == "production"
109
- else
110
- (detected_env = ENV["RACK_ENV"] || ENV["RAILS_ENV"] || ENV["HANAMI_ENV"] || ENV["APP_ENV"]) && detected_env.to_s.downcase == "production"
111
- end
112
- end
113
85
  end
114
86
 
115
87
  self.reject_numbers_followed_by_names = false
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.5
4
+ version: 2.4.7
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-12-02 00:00:00.000000000 Z
11
+ date: 2024-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64