graphql 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql.rb +31 -41
- data/lib/graphql/argument.rb +23 -21
- data/lib/graphql/base_type.rb +5 -8
- data/lib/graphql/define/assign_argument.rb +5 -2
- data/lib/graphql/define/type_definer.rb +2 -1
- data/lib/graphql/directive.rb +34 -36
- data/lib/graphql/directive/include_directive.rb +3 -7
- data/lib/graphql/directive/skip_directive.rb +3 -7
- data/lib/graphql/enum_type.rb +78 -76
- data/lib/graphql/execution_error.rb +1 -3
- data/lib/graphql/field.rb +99 -95
- data/lib/graphql/input_object_type.rb +49 -47
- data/lib/graphql/interface_type.rb +31 -34
- data/lib/graphql/introspection.rb +19 -18
- data/lib/graphql/introspection/directive_location_enum.rb +8 -0
- data/lib/graphql/introspection/directive_type.rb +1 -3
- data/lib/graphql/introspection/field_type.rb +1 -1
- data/lib/graphql/introspection/fields_field.rb +1 -1
- data/lib/graphql/introspection/introspection_query.rb +1 -3
- data/lib/graphql/introspection/possible_types_field.rb +7 -1
- data/lib/graphql/introspection/schema_field.rb +13 -9
- data/lib/graphql/introspection/type_by_name_field.rb +13 -17
- data/lib/graphql/introspection/typename_field.rb +12 -8
- data/lib/graphql/language.rb +5 -9
- data/lib/graphql/language/lexer.rb +668 -0
- data/lib/graphql/language/lexer.rl +149 -0
- data/lib/graphql/language/parser.rb +842 -116
- data/lib/graphql/language/parser.y +264 -0
- data/lib/graphql/language/token.rb +21 -0
- data/lib/graphql/list_type.rb +33 -31
- data/lib/graphql/non_null_type.rb +33 -31
- data/lib/graphql/object_type.rb +52 -55
- data/lib/graphql/query.rb +83 -80
- data/lib/graphql/query/context.rb +5 -1
- data/lib/graphql/query/directive_resolution.rb +16 -0
- data/lib/graphql/query/executor.rb +3 -3
- data/lib/graphql/query/input_validation_result.rb +17 -15
- data/lib/graphql/query/serial_execution.rb +5 -5
- data/lib/graphql/query/serial_execution/execution_context.rb +4 -3
- data/lib/graphql/query/serial_execution/selection_resolution.rb +19 -21
- data/lib/graphql/query/serial_execution/value_resolution.rb +1 -1
- data/lib/graphql/query/type_resolver.rb +22 -18
- data/lib/graphql/query/variable_validation_error.rb +14 -12
- data/lib/graphql/schema.rb +87 -77
- data/lib/graphql/schema/each_item_validator.rb +16 -12
- data/lib/graphql/schema/field_validator.rb +14 -10
- data/lib/graphql/schema/implementation_validator.rb +26 -22
- data/lib/graphql/schema/middleware_chain.rb +2 -1
- data/lib/graphql/schema/possible_types.rb +34 -0
- data/lib/graphql/schema/printer.rb +122 -120
- data/lib/graphql/schema/type_expression.rb +1 -0
- data/lib/graphql/schema/type_map.rb +3 -10
- data/lib/graphql/schema/type_reducer.rb +65 -81
- data/lib/graphql/schema/type_validator.rb +45 -41
- data/lib/graphql/static_validation.rb +7 -9
- data/lib/graphql/static_validation/all_rules.rb +29 -24
- data/lib/graphql/static_validation/arguments_validator.rb +39 -35
- data/lib/graphql/static_validation/literal_validator.rb +44 -40
- data/lib/graphql/static_validation/message.rb +30 -26
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +15 -11
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +14 -10
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +16 -12
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +59 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +25 -21
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +28 -24
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +84 -80
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +49 -43
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +22 -17
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +19 -15
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +25 -20
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +36 -23
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +29 -25
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +21 -17
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +79 -70
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +24 -20
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +122 -119
- data/lib/graphql/static_validation/type_stack.rb +138 -129
- data/lib/graphql/static_validation/validator.rb +29 -25
- data/lib/graphql/type_kinds.rb +42 -40
- data/lib/graphql/union_type.rb +22 -16
- data/lib/graphql/version.rb +1 -1
- data/readme.md +12 -27
- data/spec/graphql/base_type_spec.rb +3 -3
- data/spec/graphql/directive_spec.rb +10 -18
- data/spec/graphql/enum_type_spec.rb +7 -7
- data/spec/graphql/execution_error_spec.rb +1 -1
- data/spec/graphql/field_spec.rb +14 -13
- data/spec/graphql/id_type_spec.rb +6 -6
- data/spec/graphql/input_object_type_spec.rb +39 -39
- data/spec/graphql/interface_type_spec.rb +16 -32
- data/spec/graphql/introspection/directive_type_spec.rb +5 -9
- data/spec/graphql/introspection/input_value_type_spec.rb +10 -4
- data/spec/graphql/introspection/introspection_query_spec.rb +2 -2
- data/spec/graphql/introspection/schema_type_spec.rb +2 -2
- data/spec/graphql/introspection/type_type_spec.rb +34 -6
- data/spec/graphql/language/parser_spec.rb +299 -105
- data/spec/graphql/language/visitor_spec.rb +4 -4
- data/spec/graphql/list_type_spec.rb +11 -11
- data/spec/graphql/object_type_spec.rb +10 -10
- data/spec/graphql/query/arguments_spec.rb +7 -7
- data/spec/graphql/query/context_spec.rb +11 -3
- data/spec/graphql/query/executor_spec.rb +26 -19
- data/spec/graphql/query/serial_execution/execution_context_spec.rb +6 -6
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -2
- data/spec/graphql/query/type_resolver_spec.rb +3 -3
- data/spec/graphql/query_spec.rb +6 -38
- data/spec/graphql/scalar_type_spec.rb +28 -19
- data/spec/graphql/schema/field_validator_spec.rb +1 -1
- data/spec/graphql/schema/middleware_chain_spec.rb +12 -1
- data/spec/graphql/schema/printer_spec.rb +12 -4
- data/spec/graphql/schema/rescue_middleware_spec.rb +1 -1
- data/spec/graphql/schema/type_expression_spec.rb +2 -2
- data/spec/graphql/schema/type_reducer_spec.rb +21 -36
- data/spec/graphql/schema/type_validator_spec.rb +9 -9
- data/spec/graphql/schema_spec.rb +1 -1
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +4 -4
- data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +4 -4
- data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +5 -5
- data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +39 -0
- data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +5 -5
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +4 -4
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
- data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +1 -1
- data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +2 -2
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +2 -2
- data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +2 -2
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +3 -3
- data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +3 -3
- data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +5 -5
- data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +3 -1
- data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +4 -4
- data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +3 -3
- data/spec/graphql/static_validation/type_stack_spec.rb +3 -2
- data/spec/graphql/static_validation/validator_spec.rb +26 -6
- data/spec/graphql/union_type_spec.rb +5 -4
- data/spec/spec_helper.rb +2 -5
- data/spec/support/dairy_app.rb +30 -9
- data/spec/support/dairy_data.rb +1 -1
- data/spec/support/star_wars_data.rb +26 -26
- data/spec/support/star_wars_schema.rb +1 -1
- metadata +40 -21
- data/lib/graphql/language/transform.rb +0 -113
- data/lib/graphql/query/directive_chain.rb +0 -44
- data/lib/graphql/repl.rb +0 -27
- data/spec/graphql/language/transform_spec.rb +0 -156
@@ -8,14 +8,10 @@ module GraphQL
|
|
8
8
|
# If you want a type, but want to handle the undefined case, use {#fetch}.
|
9
9
|
class TypeMap
|
10
10
|
extend Forwardable
|
11
|
-
def_delegators :@storage, :key?, :keys, :values
|
12
|
-
|
13
|
-
# Used for detecting deprecated interface member inferrance
|
14
|
-
attr_accessor :safely_discovered_types
|
11
|
+
def_delegators :@storage, :key?, :keys, :values
|
15
12
|
|
16
13
|
def initialize
|
17
14
|
@storage = {}
|
18
|
-
@safely_discovered_types = []
|
19
15
|
end
|
20
16
|
|
21
17
|
def [](key)
|
@@ -30,11 +26,8 @@ module GraphQL
|
|
30
26
|
end
|
31
27
|
end
|
32
28
|
|
33
|
-
def
|
34
|
-
|
35
|
-
interface_only_types.map do |unsafe_type|
|
36
|
-
"Type \"#{unsafe_type}\" was inferred from an interface's #possible_types. This won't be supported in the next version of GraphQL. Pass this type with the `types:` argument to `Schema.new` instead!"
|
37
|
-
end
|
29
|
+
def fetch(key, fallback_value)
|
30
|
+
@storage.key?(key) ? @storage[key] : fallback_value
|
38
31
|
end
|
39
32
|
end
|
40
33
|
end
|
@@ -1,95 +1,79 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module GraphQL
|
2
|
+
class Schema
|
3
|
+
# Starting from a given type, discover other types in the system by
|
4
|
+
# traversing that type's fields, possible_types, etc
|
5
|
+
class TypeReducer
|
6
|
+
attr_reader :type, :existing_type_hash
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
@existing_type_hash = existing_type_hash
|
14
|
-
end
|
15
|
-
|
16
|
-
def result
|
17
|
-
@result ||= find_types(type, existing_type_hash)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Reduce all of `types` and return the combined result
|
21
|
-
def self.find_all(types)
|
22
|
-
type_map = GraphQL::Schema::TypeMap.new
|
23
|
-
types.reduce(type_map) do |memo, type|
|
24
|
-
type_map.safely_discovered_types << type
|
25
|
-
self.new(type.unwrap, memo).result
|
26
|
-
end
|
27
|
-
type_map.warnings.each do |warning|
|
28
|
-
warn(warning)
|
29
|
-
end
|
30
|
-
type_map
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def find_types(type, type_hash)
|
36
|
-
type_hash[type.name] = type
|
37
|
-
if type.kind.fields?
|
38
|
-
type.all_fields.each do |field|
|
39
|
-
reduce_type(field.type, type_hash)
|
40
|
-
field.arguments.each do |name, argument|
|
41
|
-
reduce_type(argument.type, type_hash)
|
42
|
-
safely_discovered(type_hash, argument.type)
|
8
|
+
def initialize(type, existing_type_hash)
|
9
|
+
validate_type(type)
|
10
|
+
if type.respond_to?(:name) && existing_type_hash.fetch(type.name, nil).equal?(type)
|
11
|
+
@result = existing_type_hash
|
12
|
+
else
|
13
|
+
@type = type
|
43
14
|
end
|
44
|
-
|
15
|
+
@existing_type_hash = existing_type_hash
|
45
16
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
reduce_type(interface, type_hash)
|
50
|
-
safely_discovered(type_hash, interface)
|
17
|
+
|
18
|
+
def result
|
19
|
+
@result ||= find_types(type, existing_type_hash)
|
51
20
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
21
|
+
|
22
|
+
# Reduce all of `types` and return the combined result
|
23
|
+
def self.find_all(types)
|
24
|
+
type_map = GraphQL::Schema::TypeMap.new
|
25
|
+
types.reduce(type_map) do |memo, type|
|
26
|
+
self.new(type, memo).result
|
58
27
|
end
|
59
28
|
end
|
60
|
-
end
|
61
|
-
if type.kind.input_object?
|
62
|
-
type.input_fields.each do |name, input_field|
|
63
|
-
reduce_type(input_field.type, type_hash)
|
64
|
-
safely_discovered(type_hash, input_field.type)
|
65
|
-
end
|
66
|
-
end
|
67
29
|
|
68
|
-
|
69
|
-
end
|
30
|
+
private
|
70
31
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
32
|
+
def find_types(type, type_hash)
|
33
|
+
type_hash[type.name] = type
|
34
|
+
if type.kind.fields?
|
35
|
+
type.all_fields.each do |field|
|
36
|
+
reduce_type(field.type, type_hash, "Field #{type.name}.#{field.name}")
|
37
|
+
field.arguments.each do |name, argument|
|
38
|
+
reduce_type(argument.type, type_hash, "Argument #{name} on #{type.name}.#{field.name}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
if type.kind.object?
|
43
|
+
type.interfaces.each do |interface|
|
44
|
+
reduce_type(interface, type_hash, "Interface on #{type.name}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
if type.kind.union?
|
48
|
+
type.possible_types.each do |possible_type|
|
49
|
+
reduce_type(possible_type, type_hash, "Possible type for #{type.name}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
if type.kind.input_object?
|
53
|
+
type.input_fields.each do |name, input_field|
|
54
|
+
reduce_type(input_field.type, type_hash, "Input field #{type.name}.#{name}")
|
55
|
+
end
|
56
|
+
end
|
78
57
|
|
79
|
-
|
80
|
-
|
81
|
-
type_validator = GraphQL::Schema::TypeValidator.new
|
82
|
-
type_validator.validate(type, errors)
|
83
|
-
if errors.any?
|
84
|
-
raise GraphQL::Schema::InvalidTypeError.new(type, errors)
|
85
|
-
end
|
86
|
-
end
|
58
|
+
type_hash
|
59
|
+
end
|
87
60
|
|
88
|
-
|
89
|
-
|
90
|
-
|
61
|
+
def reduce_type(type, type_hash, name = nil)
|
62
|
+
if type.is_a?(GraphQL::BaseType)
|
63
|
+
self.class.new(type.unwrap, type_hash).result
|
64
|
+
else
|
65
|
+
raise GraphQL::Schema::InvalidTypeError.new(type, name)
|
66
|
+
end
|
67
|
+
end
|
91
68
|
|
92
|
-
|
69
|
+
def validate_type(type)
|
70
|
+
errors = []
|
71
|
+
type_validator = GraphQL::Schema::TypeValidator.new
|
72
|
+
type_validator.validate(type, errors)
|
73
|
+
if errors.any?
|
74
|
+
raise GraphQL::Schema::InvalidTypeError.new(type, errors)
|
75
|
+
end
|
76
|
+
end
|
93
77
|
end
|
94
78
|
end
|
95
79
|
end
|
@@ -1,54 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module GraphQL
|
2
|
+
class Schema
|
3
|
+
class TypeValidator
|
4
|
+
def validate(type, errors)
|
5
|
+
own_errors = []
|
6
|
+
implementation = GraphQL::Schema::ImplementationValidator.new(type, as: "Type", errors: own_errors)
|
7
|
+
implementation.must_respond_to(:name)
|
8
|
+
implementation.must_respond_to(:kind)
|
9
|
+
if own_errors.any? # if no name or kind, abort!
|
10
|
+
errors.push(*own_errors)
|
11
|
+
return
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
type_name = type.name
|
15
|
+
kind_name = type.kind.name
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
implementation.must_respond_to(:description, as: kind_name)
|
18
|
+
each_item_validator = GraphQL::Schema::EachItemValidator.new(own_errors)
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
if type.kind.fields?
|
21
|
+
field_validator = GraphQL::Schema::FieldValidator.new
|
22
|
+
implementation.must_respond_to(:fields, as: kind_name) do |fields|
|
23
|
+
each_item_validator.validate(fields.keys, as: "#{type.name}.fields keys", must_be: "Strings") { |k| k.is_a?(String) }
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
fields.values.each do |field|
|
26
|
+
field_validator.validate(field, own_errors)
|
27
|
+
end
|
28
|
+
end
|
25
29
|
end
|
26
|
-
end
|
27
|
-
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
if type.kind.union?
|
32
|
+
implementation.must_respond_to(:resolve_type)
|
33
|
+
implementation.must_respond_to(:possible_types, as: kind_name) do |possible_types|
|
34
|
+
each_item_validator.validate(possible_types, as: "#{type_name}.possible_types", must_be: "objects") { |t| t.kind.object? }
|
35
|
+
end
|
36
|
+
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
if type.kind.object?
|
39
|
+
implementation.must_respond_to(:interfaces, as: kind_name) do |interfaces|
|
40
|
+
each_item_validator.validate(interfaces, as: "#{type_name}.interfaces", must_be: "interfaces") { |t| t.kind.interface? }
|
41
|
+
end
|
42
|
+
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
if type.kind.input_object?
|
45
|
+
implementation.must_respond_to(:input_fields, as: kind_name)
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
if type.kind.union?
|
49
|
+
union_types = type.possible_types
|
50
|
+
if union_types.none?
|
51
|
+
own_errors << "Union #{type_name} must be defined with 1 or more types, not 0!"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
errors.push(*own_errors)
|
50
55
|
end
|
51
56
|
end
|
52
|
-
errors.push(*own_errors)
|
53
57
|
end
|
54
58
|
end
|
@@ -1,16 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "graphql/static_validation/message"
|
2
|
+
require "graphql/static_validation/arguments_validator"
|
3
|
+
require "graphql/static_validation/type_stack"
|
4
|
+
require "graphql/static_validation/validator"
|
5
|
+
require "graphql/static_validation/validation_context"
|
6
|
+
require "graphql/static_validation/literal_validator"
|
3
7
|
|
4
|
-
require 'graphql/static_validation/message'
|
5
|
-
require 'graphql/static_validation/arguments_validator'
|
6
|
-
require 'graphql/static_validation/type_stack'
|
7
|
-
require 'graphql/static_validation/validator'
|
8
|
-
require 'graphql/static_validation/validation_context'
|
9
|
-
require 'graphql/static_validation/literal_validator'
|
10
8
|
|
11
9
|
rules_glob = File.expand_path("../static_validation/rules/*.rb", __FILE__)
|
12
10
|
Dir.glob(rules_glob).each do |file|
|
13
11
|
require(file)
|
14
12
|
end
|
15
13
|
|
16
|
-
require
|
14
|
+
require "graphql/static_validation/all_rules"
|
@@ -1,24 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
module GraphQL
|
2
|
+
module StaticValidation
|
3
|
+
# Default rules for {GraphQL::StaticValidation::Validator}
|
4
|
+
#
|
5
|
+
# Order is important here. Some validators return {GraphQL::Language::Visitor::SKIP}
|
6
|
+
# which stops the visit on that node. That way it doesn't try to find fields on types that
|
7
|
+
# don't exist, etc.
|
8
|
+
ALL_RULES = [
|
9
|
+
GraphQL::StaticValidation::DirectivesAreDefined,
|
10
|
+
GraphQL::StaticValidation::DirectivesAreInValidLocations,
|
11
|
+
GraphQL::StaticValidation::FragmentsAreFinite,
|
12
|
+
GraphQL::StaticValidation::FragmentsAreUsed,
|
13
|
+
GraphQL::StaticValidation::FragmentTypesExist,
|
14
|
+
GraphQL::StaticValidation::FragmentsAreOnCompositeTypes,
|
15
|
+
GraphQL::StaticValidation::FragmentSpreadsArePossible,
|
16
|
+
GraphQL::StaticValidation::FieldsAreDefinedOnType,
|
17
|
+
GraphQL::StaticValidation::FieldsWillMerge,
|
18
|
+
GraphQL::StaticValidation::FieldsHaveAppropriateSelections,
|
19
|
+
GraphQL::StaticValidation::ArgumentsAreDefined,
|
20
|
+
GraphQL::StaticValidation::ArgumentLiteralsAreCompatible,
|
21
|
+
GraphQL::StaticValidation::RequiredArgumentsArePresent,
|
22
|
+
GraphQL::StaticValidation::VariablesAreInputTypes,
|
23
|
+
GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTyped,
|
24
|
+
GraphQL::StaticValidation::VariablesAreUsedAndDefined,
|
25
|
+
GraphQL::StaticValidation::VariableUsagesAreAllowed,
|
26
|
+
GraphQL::StaticValidation::DocumentDoesNotExceedMaxDepth,
|
27
|
+
]
|
28
|
+
end
|
29
|
+
end
|
@@ -1,44 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module GraphQL
|
2
|
+
module StaticValidation
|
3
|
+
# Implement validate_node
|
4
|
+
class ArgumentsValidator
|
5
|
+
include GraphQL::StaticValidation::Message::MessageHelper
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
def validate(context)
|
8
|
+
visitor = context.visitor
|
9
|
+
visitor[GraphQL::Language::Nodes::Argument] << -> (node, parent) {
|
10
|
+
if parent.is_a?(GraphQL::Language::Nodes::InputObject)
|
11
|
+
arg_defn = context.argument_definition
|
12
|
+
if arg_defn.nil?
|
13
|
+
return
|
14
|
+
else
|
15
|
+
parent_defn = arg_defn.type.unwrap
|
16
|
+
if parent_defn.is_a?(GraphQL::ScalarType)
|
17
|
+
return
|
18
|
+
end
|
19
|
+
end
|
20
|
+
elsif context.skip_field?(parent.name)
|
15
21
|
return
|
22
|
+
elsif parent.is_a?(GraphQL::Language::Nodes::Directive)
|
23
|
+
parent_defn = context.schema.directives[parent.name]
|
24
|
+
else
|
25
|
+
parent_defn = context.field_definition
|
16
26
|
end
|
17
|
-
|
18
|
-
|
19
|
-
return
|
20
|
-
elsif parent.is_a?(GraphQL::Language::Nodes::Directive)
|
21
|
-
parent_defn = context.schema.directives[parent.name]
|
22
|
-
else
|
23
|
-
parent_defn = context.field_definition
|
27
|
+
validate_node(parent, node, parent_defn, context)
|
28
|
+
}
|
24
29
|
end
|
25
|
-
validate_node(parent, node, parent_defn, context)
|
26
|
-
}
|
27
|
-
end
|
28
30
|
|
29
|
-
|
31
|
+
private
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
def parent_name(parent, type_defn)
|
34
|
+
field_name = if parent.is_a?(GraphQL::Language::Nodes::Field)
|
35
|
+
parent.alias || parent.name
|
36
|
+
elsif parent.is_a?(GraphQL::Language::Nodes::InputObject)
|
37
|
+
type_defn.name
|
38
|
+
else
|
39
|
+
parent.name
|
40
|
+
end
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
+
def node_type(parent)
|
44
|
+
parent.class.name.split("::").last
|
45
|
+
end
|
46
|
+
end
|
43
47
|
end
|
44
48
|
end
|