graphql 2.3.9 → 2.3.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/install_generator.rb +46 -0
- data/lib/graphql/current.rb +52 -0
- data/lib/graphql/dataloader/source.rb +5 -2
- data/lib/graphql/dataloader.rb +4 -1
- data/lib/graphql/execution/interpreter/arguments_cache.rb +5 -10
- data/lib/graphql/execution/interpreter/runtime.rb +2 -8
- data/lib/graphql/execution/interpreter.rb +2 -0
- data/lib/graphql/introspection/entry_points.rb +2 -2
- data/lib/graphql/introspection/schema_type.rb +1 -1
- data/lib/graphql/language/nodes.rb +2 -2
- data/lib/graphql/language/parser.rb +9 -1
- data/lib/graphql/query/context.rb +4 -2
- data/lib/graphql/query/null_context.rb +0 -4
- data/lib/graphql/query.rb +2 -6
- data/lib/graphql/schema/build_from_definition.rb +8 -1
- data/lib/graphql/schema/directive/flagged.rb +1 -1
- data/lib/graphql/schema/enum.rb +5 -1
- data/lib/graphql/schema/field/connection_extension.rb +1 -1
- data/lib/graphql/schema/interface.rb +20 -4
- data/lib/graphql/schema/introspection_system.rb +3 -2
- data/lib/graphql/schema/member/has_arguments.rb +7 -3
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +5 -1
- data/lib/graphql/schema/subset.rb +215 -102
- data/lib/graphql/schema/types_migration.rb +185 -0
- data/lib/graphql/schema/warden.rb +4 -7
- data/lib/graphql/schema.rb +30 -22
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +18 -27
- data/lib/graphql/testing/helpers.rb +6 -3
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +1 -0
- metadata +4 -2
data/lib/graphql/schema.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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 ||= {}.
|
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 ||= {}.
|
1541
|
+
@own_possible_types ||= {}.compare_by_identity
|
1534
1542
|
end
|
1535
1543
|
|
1536
1544
|
def own_union_memberships
|
@@ -5,36 +5,27 @@ module GraphQL
|
|
5
5
|
def on_variable_definition(node, parent)
|
6
6
|
if !node.default_value.nil?
|
7
7
|
value = node.default_value
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
nodes: node,
|
12
|
-
name: node.name,
|
13
|
-
error_type: VariableDefaultValuesAreCorrectlyTypedError::VIOLATIONS[:INVALID_ON_NON_NULL]
|
14
|
-
))
|
8
|
+
type = context.schema.type_from_ast(node.type, context: context)
|
9
|
+
if type.nil?
|
10
|
+
# This is handled by another validator
|
15
11
|
else
|
16
|
-
|
17
|
-
if type.nil?
|
18
|
-
# This is handled by another validator
|
19
|
-
else
|
20
|
-
validation_result = context.validate_literal(value, type)
|
12
|
+
validation_result = context.validate_literal(value, type)
|
21
13
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
error_message ||= "Default value for $#{node.name} doesn't match type #{type.to_type_signature}"
|
30
|
-
add_error(GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTypedError.new(
|
31
|
-
error_message,
|
32
|
-
nodes: node,
|
33
|
-
name: node.name,
|
34
|
-
type: type.to_type_signature,
|
35
|
-
error_type: VariableDefaultValuesAreCorrectlyTypedError::VIOLATIONS[:INVALID_TYPE],
|
36
|
-
))
|
14
|
+
if !validation_result.valid?
|
15
|
+
problems = validation_result.problems
|
16
|
+
first_problem = problems && problems.first
|
17
|
+
if first_problem
|
18
|
+
error_message = first_problem["explanation"]
|
37
19
|
end
|
20
|
+
|
21
|
+
error_message ||= "Default value for $#{node.name} doesn't match type #{type.to_type_signature}"
|
22
|
+
add_error(GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTypedError.new(
|
23
|
+
error_message,
|
24
|
+
nodes: node,
|
25
|
+
name: node.name,
|
26
|
+
type: type.to_type_signature,
|
27
|
+
error_type: VariableDefaultValuesAreCorrectlyTypedError::VIOLATIONS[:INVALID_TYPE],
|
28
|
+
))
|
38
29
|
end
|
39
30
|
end
|
40
31
|
end
|
@@ -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
|
-
|
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
|
|
data/lib/graphql/version.rb
CHANGED
data/lib/graphql.rb
CHANGED
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.
|
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-
|
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
|