graphql 2.3.14 → 2.3.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.

Potentially problematic release.


This version of graphql might be problematic. Click here for more details.

Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/orm_mutations_base.rb +1 -1
  3. data/lib/generators/graphql/templates/base_resolver.erb +2 -0
  4. data/lib/generators/graphql/type_generator.rb +1 -1
  5. data/lib/graphql/analysis.rb +1 -1
  6. data/lib/graphql/execution/interpreter/resolve.rb +10 -6
  7. data/lib/graphql/language/comment.rb +18 -0
  8. data/lib/graphql/language/document_from_schema_definition.rb +38 -4
  9. data/lib/graphql/language/lexer.rb +15 -12
  10. data/lib/graphql/language/nodes.rb +22 -14
  11. data/lib/graphql/language/parser.rb +5 -0
  12. data/lib/graphql/language/printer.rb +23 -7
  13. data/lib/graphql/language.rb +6 -5
  14. data/lib/graphql/query.rb +1 -1
  15. data/lib/graphql/schema/argument.rb +13 -1
  16. data/lib/graphql/schema/enum.rb +1 -0
  17. data/lib/graphql/schema/enum_value.rb +9 -1
  18. data/lib/graphql/schema/field.rb +23 -3
  19. data/lib/graphql/schema/interface.rb +1 -0
  20. data/lib/graphql/schema/member/base_dsl_methods.rb +15 -0
  21. data/lib/graphql/schema/member/has_arguments.rb +2 -2
  22. data/lib/graphql/schema/member/has_fields.rb +2 -2
  23. data/lib/graphql/schema/resolver.rb +3 -4
  24. data/lib/graphql/schema/visibility/migration.rb +188 -0
  25. data/lib/graphql/schema/visibility/subset.rb +509 -0
  26. data/lib/graphql/schema/visibility.rb +30 -0
  27. data/lib/graphql/schema.rb +46 -41
  28. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +2 -0
  29. data/lib/graphql/testing/helpers.rb +1 -1
  30. data/lib/graphql/tracing/notifications_trace.rb +2 -2
  31. data/lib/graphql/version.rb +1 -1
  32. metadata +6 -4
  33. data/lib/graphql/schema/subset.rb +0 -509
  34. data/lib/graphql/schema/types_migration.rb +0 -187
@@ -45,8 +45,7 @@ require "graphql/schema/mutation"
45
45
  require "graphql/schema/has_single_input_argument"
46
46
  require "graphql/schema/relay_classic_mutation"
47
47
  require "graphql/schema/subscription"
48
- require "graphql/schema/subset"
49
- require "graphql/schema/types_migration"
48
+ require "graphql/schema/visibility"
50
49
 
51
50
  module GraphQL
52
51
  # A GraphQL schema which may be queried with {GraphQL::Query}.
@@ -205,24 +204,19 @@ module GraphQL
205
204
  @own_trace_modes ||= {}
206
205
  end
207
206
 
208
- module DefaultTraceClass
209
- end
210
-
211
- private_constant :DefaultTraceClass
212
-
213
207
  def build_trace_mode(mode)
214
208
  case mode
215
209
  when :default
216
210
  # Use the superclass's default mode if it has one, or else start an inheritance chain at the built-in base class.
217
- base_class = (superclass.respond_to?(:trace_class_for) && superclass.trace_class_for(mode)) || GraphQL::Tracing::Trace
218
- Class.new(base_class) do
211
+ base_class = (superclass.respond_to?(:trace_class_for) && superclass.trace_class_for(mode, build: true)) || GraphQL::Tracing::Trace
212
+ const_set(:DefaultTrace, Class.new(base_class) do
219
213
  include DefaultTraceClass
220
- end
214
+ end)
221
215
  when :default_backtrace
222
216
  schema_base_class = trace_class_for(:default, build: true)
223
- Class.new(schema_base_class) do
217
+ const_set(:DefaultTraceBacktrace, Class.new(schema_base_class) do
224
218
  include(GraphQL::Backtrace::Trace)
225
- end
219
+ end)
226
220
  else
227
221
  # First, see if the superclass has a custom-defined class for this.
228
222
  # Then, if it doesn't, use this class's default trace
@@ -339,8 +333,8 @@ module GraphQL
339
333
  # @return [Hash<String => Class>] A dictionary of type classes by their GraphQL name
340
334
  # @see get_type Which is more efficient for finding _one type_ by name, because it doesn't merge hashes.
341
335
  def types(context = GraphQL::Query::NullContext.instance)
342
- if use_schema_subset?
343
- return Subset.from_context(context, self).all_types_h
336
+ if use_schema_visibility?
337
+ return Visibility::Subset.from_context(context, self).all_types_h
344
338
  end
345
339
  all_types = non_introspection_types.merge(introspection_system.types)
346
340
  visible_types = {}
@@ -369,15 +363,15 @@ module GraphQL
369
363
  # @param type_name [String]
370
364
  # @return [Module, nil] A type, or nil if there's no type called `type_name`
371
365
  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)
366
+ if use_schema_visibility?
367
+ return Visibility::Subset.from_context(context, self).type(type_name)
374
368
  end
375
369
  local_entry = own_types[type_name]
376
370
  type_defn = case local_entry
377
371
  when nil
378
372
  nil
379
373
  when Array
380
- if context.respond_to?(:types) && context.types.is_a?(GraphQL::Schema::Subset)
374
+ if context.respond_to?(:types) && context.types.is_a?(GraphQL::Schema::Visibility::Subset)
381
375
  local_entry
382
376
  else
383
377
  visible_t = nil
@@ -435,7 +429,7 @@ module GraphQL
435
429
  if @query_object
436
430
  dup_defn = new_query_object || yield
437
431
  raise GraphQL::Error, "Second definition of `query(...)` (#{dup_defn.inspect}) is invalid, already configured with #{@query_object.inspect}"
438
- elsif use_schema_subset?
432
+ elsif use_schema_visibility?
439
433
  @query_object = block_given? ? lazy_load_block : new_query_object
440
434
  else
441
435
  @query_object = new_query_object || lazy_load_block.call
@@ -454,7 +448,7 @@ module GraphQL
454
448
  if @mutation_object
455
449
  dup_defn = new_mutation_object || yield
456
450
  raise GraphQL::Error, "Second definition of `mutation(...)` (#{dup_defn.inspect}) is invalid, already configured with #{@mutation_object.inspect}"
457
- elsif use_schema_subset?
451
+ elsif use_schema_visibility?
458
452
  @mutation_object = block_given? ? lazy_load_block : new_mutation_object
459
453
  else
460
454
  @mutation_object = new_mutation_object || lazy_load_block.call
@@ -473,7 +467,7 @@ module GraphQL
473
467
  if @subscription_object
474
468
  dup_defn = new_subscription_object || yield
475
469
  raise GraphQL::Error, "Second definition of `subscription(...)` (#{dup_defn.inspect}) is invalid, already configured with #{@subscription_object.inspect}"
476
- elsif use_schema_subset?
470
+ elsif use_schema_visibility?
477
471
  @subscription_object = block_given? ? lazy_load_block : new_subscription_object
478
472
  add_subscription_extension_if_necessary
479
473
  else
@@ -507,7 +501,7 @@ module GraphQL
507
501
  end
508
502
 
509
503
  def root_types
510
- if use_schema_subset?
504
+ if use_schema_visibility?
511
505
  [query, mutation, subscription].compact
512
506
  else
513
507
  @root_types
@@ -532,17 +526,17 @@ module GraphQL
532
526
  elsif superclass.respond_to?(:subset_class)
533
527
  superclass.subset_class
534
528
  else
535
- GraphQL::Schema::Subset
529
+ GraphQL::Schema::Visibility::Subset
536
530
  end
537
531
  end
538
532
 
539
- attr_writer :subset_class, :use_schema_subset
533
+ attr_writer :subset_class, :use_schema_visibility, :visibility
540
534
 
541
- def use_schema_subset?
542
- if defined?(@use_schema_subset)
543
- @use_schema_subset
544
- elsif superclass.respond_to?(:use_schema_subset?)
545
- superclass.use_schema_subset?
535
+ def use_schema_visibility?
536
+ if defined?(@use_schema_visibility)
537
+ @use_schema_visibility
538
+ elsif superclass.respond_to?(:use_schema_visibility?)
539
+ superclass.use_schema_visibility?
546
540
  else
547
541
  false
548
542
  end
@@ -552,11 +546,11 @@ module GraphQL
552
546
  # @return [Hash<String, Module>] All possible types, if no `type` is given.
553
547
  # @return [Array<Module>] Possible types for `type`, if it's given.
554
548
  def possible_types(type = nil, context = GraphQL::Query::NullContext.instance)
555
- if use_schema_subset?
549
+ if use_schema_visibility?
556
550
  if type
557
- return Subset.from_context(context, self).possible_types(type)
551
+ return Visibility::Subset.from_context(context, self).possible_types(type)
558
552
  else
559
- raise "Schema.possible_types is not implemented for `use_schema_subset?`"
553
+ raise "Schema.possible_types is not implemented for `use_schema_visibility?`"
560
554
  end
561
555
  end
562
556
  if type
@@ -789,13 +783,11 @@ module GraphQL
789
783
 
790
784
  attr_writer :validate_max_errors
791
785
 
792
- def validate_max_errors(new_validate_max_errors = nil)
793
- if new_validate_max_errors
794
- @validate_max_errors = new_validate_max_errors
795
- elsif defined?(@validate_max_errors)
796
- @validate_max_errors
786
+ def validate_max_errors(new_validate_max_errors = NOT_CONFIGURED)
787
+ if NOT_CONFIGURED.equal?(new_validate_max_errors)
788
+ defined?(@validate_max_errors) ? @validate_max_errors : find_inherited_value(:validate_max_errors)
797
789
  else
798
- find_inherited_value(:validate_max_errors)
790
+ @validate_max_errors = new_validate_max_errors
799
791
  end
800
792
  end
801
793
 
@@ -934,7 +926,7 @@ module GraphQL
934
926
  To add other types to your schema, you might want `extra_types`: https://graphql-ruby.org/schema/definition.html#extra-types
935
927
  ERR
936
928
  end
937
- add_type_and_traverse(new_orphan_types, root: false) unless use_schema_subset?
929
+ add_type_and_traverse(new_orphan_types, root: false) unless use_schema_visibility?
938
930
  own_orphan_types.concat(new_orphan_types.flatten)
939
931
  end
940
932
 
@@ -1193,7 +1185,7 @@ module GraphQL
1193
1185
  # @param new_directive [Class]
1194
1186
  # @return void
1195
1187
  def directive(new_directive)
1196
- if use_schema_subset?
1188
+ if use_schema_visibility?
1197
1189
  own_directives[new_directive.graphql_name] = new_directive
1198
1190
  else
1199
1191
  add_type_and_traverse(new_directive, root: false)
@@ -1463,8 +1455,17 @@ module GraphQL
1463
1455
  private
1464
1456
 
1465
1457
  def add_trace_options_for(mode, new_options)
1466
- t_opts = trace_options_for(mode)
1467
- t_opts.merge!(new_options)
1458
+ if mode == :default
1459
+ own_trace_modes.each do |mode_name, t_class|
1460
+ if t_class <= DefaultTraceClass
1461
+ t_opts = trace_options_for(mode_name)
1462
+ t_opts.merge!(new_options)
1463
+ end
1464
+ end
1465
+ else
1466
+ t_opts = trace_options_for(mode)
1467
+ t_opts.merge!(new_options)
1468
+ end
1468
1469
  nil
1469
1470
  end
1470
1471
 
@@ -1608,5 +1609,9 @@ module GraphQL
1608
1609
 
1609
1610
  # Install these here so that subclasses will also install it.
1610
1611
  self.connections = GraphQL::Pagination::Connections.new(schema: self)
1612
+
1613
+ # @api private
1614
+ module DefaultTraceClass
1615
+ end
1611
1616
  end
1612
1617
  end
@@ -19,6 +19,7 @@ module GraphQL
19
19
  GraphQL::Schema::Directive::FRAGMENT_DEFINITION => "fragment definitions",
20
20
  GraphQL::Schema::Directive::FRAGMENT_SPREAD => "fragment spreads",
21
21
  GraphQL::Schema::Directive::INLINE_FRAGMENT => "inline fragments",
22
+ GraphQL::Schema::Directive::VARIABLE_DEFINITION => "variable definitions",
22
23
  }
23
24
 
24
25
  SIMPLE_LOCATIONS = {
@@ -26,6 +27,7 @@ module GraphQL
26
27
  Nodes::InlineFragment => GraphQL::Schema::Directive::INLINE_FRAGMENT,
27
28
  Nodes::FragmentSpread => GraphQL::Schema::Directive::FRAGMENT_SPREAD,
28
29
  Nodes::FragmentDefinition => GraphQL::Schema::Directive::FRAGMENT_DEFINITION,
30
+ Nodes::VariableDefinition => GraphQL::Schema::Directive::VARIABLE_DEFINITION,
29
31
  }
30
32
 
31
33
  SIMPLE_LOCATION_NODES = SIMPLE_LOCATIONS.keys
@@ -91,7 +91,7 @@ module GraphQL
91
91
  end
92
92
  graphql_result
93
93
  else
94
- unfiltered_type = Schema::Subset.pass_thru(schema: schema, context: context).type(type_name)
94
+ unfiltered_type = Schema::Visibility::Subset.pass_thru(schema: schema, context: context).type(type_name)
95
95
  if unfiltered_type
96
96
  raise TypeNotVisibleError.new(type_name: type_name)
97
97
  else
@@ -33,8 +33,8 @@ module GraphQL
33
33
  "resolve_type_lazy" => "resolve_type.graphql",
34
34
  }.each do |trace_method, platform_key|
35
35
  module_eval <<-RUBY, __FILE__, __LINE__
36
- def #{trace_method}(**metadata, &blk)
37
- @notifications_engine.instrument("#{platform_key}", metadata, &blk)
36
+ def #{trace_method}(**metadata, &block)
37
+ @notifications_engine.instrument("#{platform_key}", metadata) { super(**metadata, &block) }
38
38
  end
39
39
  RUBY
40
40
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "2.3.14"
3
+ VERSION = "2.3.15"
4
4
  end
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.14
4
+ version: 2.3.15
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-08-13 00:00:00.000000000 Z
11
+ date: 2024-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -382,6 +382,7 @@ files:
382
382
  - lib/graphql/language.rb
383
383
  - lib/graphql/language/block_string.rb
384
384
  - lib/graphql/language/cache.rb
385
+ - lib/graphql/language/comment.rb
385
386
  - lib/graphql/language/definition_slice.rb
386
387
  - lib/graphql/language/document_from_schema_definition.rb
387
388
  - lib/graphql/language/generation.rb
@@ -485,11 +486,9 @@ files:
485
486
  - lib/graphql/schema/resolver/has_payload_type.rb
486
487
  - lib/graphql/schema/scalar.rb
487
488
  - lib/graphql/schema/subscription.rb
488
- - lib/graphql/schema/subset.rb
489
489
  - lib/graphql/schema/timeout.rb
490
490
  - lib/graphql/schema/type_expression.rb
491
491
  - lib/graphql/schema/type_membership.rb
492
- - lib/graphql/schema/types_migration.rb
493
492
  - lib/graphql/schema/union.rb
494
493
  - lib/graphql/schema/unique_within_type.rb
495
494
  - lib/graphql/schema/validator.rb
@@ -502,6 +501,9 @@ files:
502
501
  - lib/graphql/schema/validator/length_validator.rb
503
502
  - lib/graphql/schema/validator/numericality_validator.rb
504
503
  - lib/graphql/schema/validator/required_validator.rb
504
+ - lib/graphql/schema/visibility.rb
505
+ - lib/graphql/schema/visibility/migration.rb
506
+ - lib/graphql/schema/visibility/subset.rb
505
507
  - lib/graphql/schema/warden.rb
506
508
  - lib/graphql/schema/wrapper.rb
507
509
  - lib/graphql/static_validation.rb