graphql 2.3.10 → 2.3.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,6 +46,7 @@ require "graphql/schema/has_single_input_argument"
46
46
  require "graphql/schema/relay_classic_mutation"
47
47
  require "graphql/schema/subscription"
48
48
  require "graphql/schema/subset"
49
+ require "graphql/schema/types_migration"
49
50
 
50
51
  module GraphQL
51
52
  # A GraphQL schema which may be queried with {GraphQL::Query}.
@@ -338,6 +339,9 @@ module GraphQL
338
339
  # @return [Hash<String => Class>] A dictionary of type classes by their GraphQL name
339
340
  # @see get_type Which is more efficient for finding _one type_ by name, because it doesn't merge hashes.
340
341
  def types(context = GraphQL::Query::NullContext.instance)
342
+ if use_schema_subset?
343
+ return Subset.from_context(context, self).all_types_h
344
+ end
341
345
  all_types = non_introspection_types.merge(introspection_system.types)
342
346
  visible_types = {}
343
347
  all_types.each do |k, v|
@@ -365,6 +369,9 @@ module GraphQL
365
369
  # @param type_name [String]
366
370
  # @return [Module, nil] A type, or nil if there's no type called `type_name`
367
371
  def get_type(type_name, context = GraphQL::Query::NullContext.instance)
372
+ if use_schema_subset?
373
+ return Subset.from_context(context, self).type(type_name)
374
+ end
368
375
  local_entry = own_types[type_name]
369
376
  type_defn = case local_entry
370
377
  when nil
@@ -423,17 +430,13 @@ module GraphQL
423
430
  end
424
431
  end
425
432
 
426
- def new_connections?
427
- !!connections
428
- end
429
-
430
433
  def query(new_query_object = nil)
431
434
  if new_query_object
432
435
  if @query_object
433
436
  raise GraphQL::Error, "Second definition of `query(...)` (#{new_query_object.inspect}) is invalid, already configured with #{@query_object.inspect}"
434
437
  else
435
438
  @query_object = new_query_object
436
- add_type_and_traverse(new_query_object, root: true)
439
+ add_type_and_traverse(new_query_object, root: true) unless use_schema_subset?
437
440
  nil
438
441
  end
439
442
  else
@@ -447,7 +450,7 @@ module GraphQL
447
450
  raise GraphQL::Error, "Second definition of `mutation(...)` (#{new_mutation_object.inspect}) is invalid, already configured with #{@mutation_object.inspect}"
448
451
  else
449
452
  @mutation_object = new_mutation_object
450
- add_type_and_traverse(new_mutation_object, root: true)
453
+ add_type_and_traverse(new_mutation_object, root: true) unless use_schema_subset?
451
454
  nil
452
455
  end
453
456
  else
@@ -462,7 +465,7 @@ module GraphQL
462
465
  else
463
466
  @subscription_object = new_subscription_object
464
467
  add_subscription_extension_if_necessary
465
- add_type_and_traverse(new_subscription_object, root: true)
468
+ add_type_and_traverse(new_subscription_object, root: true) unless use_schema_subset?
466
469
  nil
467
470
  end
468
471
  else
@@ -486,7 +489,11 @@ module GraphQL
486
489
  end
487
490
 
488
491
  def root_types
489
- @root_types
492
+ if use_schema_subset?
493
+ [query, mutation, subscription].compact
494
+ else
495
+ @root_types
496
+ end
490
497
  end
491
498
 
492
499
  def warden_class
@@ -527,6 +534,13 @@ module GraphQL
527
534
  # @return [Hash<String, Module>] All possible types, if no `type` is given.
528
535
  # @return [Array<Module>] Possible types for `type`, if it's given.
529
536
  def possible_types(type = nil, context = GraphQL::Query::NullContext.instance)
537
+ if use_schema_subset?
538
+ if type
539
+ return Subset.from_context(context, self).possible_types(type)
540
+ else
541
+ raise "Schema.possible_types is not implemented for `use_schema_subset?`"
542
+ end
543
+ end
530
544
  if type
531
545
  # TODO duck-typing `.possible_types` would probably be nicer here
532
546
  if type.kind.union?
@@ -794,16 +808,6 @@ module GraphQL
794
808
  @analysis_engine || find_inherited_value(:analysis_engine, self.default_analysis_engine)
795
809
  end
796
810
 
797
- def using_ast_analysis?
798
- true
799
- end
800
-
801
- def interpreter?
802
- true
803
- end
804
-
805
- attr_writer :interpreter
806
-
807
811
  def error_bubbling(new_error_bubbling = nil)
808
812
  if !new_error_bubbling.nil?
809
813
  warn("error_bubbling(#{new_error_bubbling.inspect}) is deprecated; the default value of `false` will be the only option in GraphQL-Ruby 3.0")
@@ -912,7 +916,7 @@ module GraphQL
912
916
  To add other types to your schema, you might want `extra_types`: https://graphql-ruby.org/schema/definition.html#extra-types
913
917
  ERR
914
918
  end
915
- add_type_and_traverse(new_orphan_types, root: false)
919
+ add_type_and_traverse(new_orphan_types, root: false) unless use_schema_subset?
916
920
  own_orphan_types.concat(new_orphan_types.flatten)
917
921
  end
918
922
 
@@ -1171,7 +1175,11 @@ module GraphQL
1171
1175
  # @param new_directive [Class]
1172
1176
  # @return void
1173
1177
  def directive(new_directive)
1174
- add_type_and_traverse(new_directive, root: false)
1178
+ if use_schema_subset?
1179
+ own_directives[new_directive.graphql_name] = new_directive
1180
+ else
1181
+ add_type_and_traverse(new_directive, root: false)
1182
+ end
1175
1183
  end
1176
1184
 
1177
1185
  def default_directives
@@ -1514,7 +1522,7 @@ module GraphQL
1514
1522
  end
1515
1523
 
1516
1524
  def own_references_to
1517
- @own_references_to ||= {}.tap(&:compare_by_identity)
1525
+ @own_references_to ||= {}.compare_by_identity
1518
1526
  end
1519
1527
 
1520
1528
  def non_introspection_types
@@ -1530,7 +1538,7 @@ module GraphQL
1530
1538
  end
1531
1539
 
1532
1540
  def own_possible_types
1533
- @own_possible_types ||= {}.tap(&:compare_by_identity)
1541
+ @own_possible_types ||= {}.compare_by_identity
1534
1542
  end
1535
1543
 
1536
1544
  def own_union_memberships
@@ -90,10 +90,13 @@ module GraphQL
90
90
  end
91
91
  end
92
92
  graphql_result
93
- elsif schema.has_defined_type?(type_name)
94
- raise TypeNotVisibleError.new(type_name: type_name)
95
93
  else
96
- raise TypeNotDefinedError.new(type_name: type_name)
94
+ unfiltered_type = Schema::Subset.pass_thru(schema: schema, context: context).type(type_name)
95
+ if unfiltered_type
96
+ raise TypeNotVisibleError.new(type_name: type_name)
97
+ else
98
+ raise TypeNotDefinedError.new(type_name: type_name)
99
+ end
97
100
  end
98
101
  end
99
102
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "2.3.10"
3
+ VERSION = "2.3.11"
4
4
  end
data/lib/graphql.rb CHANGED
@@ -121,3 +121,4 @@ require "graphql/unauthorized_error"
121
121
  require "graphql/unauthorized_field_error"
122
122
  require "graphql/load_application_object_failed_error"
123
123
  require "graphql/testing"
124
+ require "graphql/current"
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.3.10
4
+ version: 2.3.11
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-07-19 00:00:00.000000000 Z
11
+ date: 2024-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -321,6 +321,7 @@ files:
321
321
  - lib/graphql/backtrace/traced_error.rb
322
322
  - lib/graphql/backtrace/tracer.rb
323
323
  - lib/graphql/coercion_error.rb
324
+ - lib/graphql/current.rb
324
325
  - lib/graphql/dataloader.rb
325
326
  - lib/graphql/dataloader/async_dataloader.rb
326
327
  - lib/graphql/dataloader/null_dataloader.rb
@@ -472,6 +473,7 @@ files:
472
473
  - lib/graphql/schema/timeout.rb
473
474
  - lib/graphql/schema/type_expression.rb
474
475
  - lib/graphql/schema/type_membership.rb
476
+ - lib/graphql/schema/types_migration.rb
475
477
  - lib/graphql/schema/union.rb
476
478
  - lib/graphql/schema/unique_within_type.rb
477
479
  - lib/graphql/schema/validator.rb