graphql 0.12.1 → 0.13.0

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.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql.rb +31 -41
  3. data/lib/graphql/argument.rb +23 -21
  4. data/lib/graphql/base_type.rb +5 -8
  5. data/lib/graphql/define/assign_argument.rb +5 -2
  6. data/lib/graphql/define/type_definer.rb +2 -1
  7. data/lib/graphql/directive.rb +34 -36
  8. data/lib/graphql/directive/include_directive.rb +3 -7
  9. data/lib/graphql/directive/skip_directive.rb +3 -7
  10. data/lib/graphql/enum_type.rb +78 -76
  11. data/lib/graphql/execution_error.rb +1 -3
  12. data/lib/graphql/field.rb +99 -95
  13. data/lib/graphql/input_object_type.rb +49 -47
  14. data/lib/graphql/interface_type.rb +31 -34
  15. data/lib/graphql/introspection.rb +19 -18
  16. data/lib/graphql/introspection/directive_location_enum.rb +8 -0
  17. data/lib/graphql/introspection/directive_type.rb +1 -3
  18. data/lib/graphql/introspection/field_type.rb +1 -1
  19. data/lib/graphql/introspection/fields_field.rb +1 -1
  20. data/lib/graphql/introspection/introspection_query.rb +1 -3
  21. data/lib/graphql/introspection/possible_types_field.rb +7 -1
  22. data/lib/graphql/introspection/schema_field.rb +13 -9
  23. data/lib/graphql/introspection/type_by_name_field.rb +13 -17
  24. data/lib/graphql/introspection/typename_field.rb +12 -8
  25. data/lib/graphql/language.rb +5 -9
  26. data/lib/graphql/language/lexer.rb +668 -0
  27. data/lib/graphql/language/lexer.rl +149 -0
  28. data/lib/graphql/language/parser.rb +842 -116
  29. data/lib/graphql/language/parser.y +264 -0
  30. data/lib/graphql/language/token.rb +21 -0
  31. data/lib/graphql/list_type.rb +33 -31
  32. data/lib/graphql/non_null_type.rb +33 -31
  33. data/lib/graphql/object_type.rb +52 -55
  34. data/lib/graphql/query.rb +83 -80
  35. data/lib/graphql/query/context.rb +5 -1
  36. data/lib/graphql/query/directive_resolution.rb +16 -0
  37. data/lib/graphql/query/executor.rb +3 -3
  38. data/lib/graphql/query/input_validation_result.rb +17 -15
  39. data/lib/graphql/query/serial_execution.rb +5 -5
  40. data/lib/graphql/query/serial_execution/execution_context.rb +4 -3
  41. data/lib/graphql/query/serial_execution/selection_resolution.rb +19 -21
  42. data/lib/graphql/query/serial_execution/value_resolution.rb +1 -1
  43. data/lib/graphql/query/type_resolver.rb +22 -18
  44. data/lib/graphql/query/variable_validation_error.rb +14 -12
  45. data/lib/graphql/schema.rb +87 -77
  46. data/lib/graphql/schema/each_item_validator.rb +16 -12
  47. data/lib/graphql/schema/field_validator.rb +14 -10
  48. data/lib/graphql/schema/implementation_validator.rb +26 -22
  49. data/lib/graphql/schema/middleware_chain.rb +2 -1
  50. data/lib/graphql/schema/possible_types.rb +34 -0
  51. data/lib/graphql/schema/printer.rb +122 -120
  52. data/lib/graphql/schema/type_expression.rb +1 -0
  53. data/lib/graphql/schema/type_map.rb +3 -10
  54. data/lib/graphql/schema/type_reducer.rb +65 -81
  55. data/lib/graphql/schema/type_validator.rb +45 -41
  56. data/lib/graphql/static_validation.rb +7 -9
  57. data/lib/graphql/static_validation/all_rules.rb +29 -24
  58. data/lib/graphql/static_validation/arguments_validator.rb +39 -35
  59. data/lib/graphql/static_validation/literal_validator.rb +44 -40
  60. data/lib/graphql/static_validation/message.rb +30 -26
  61. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +15 -11
  62. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +14 -10
  63. data/lib/graphql/static_validation/rules/directives_are_defined.rb +16 -12
  64. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +59 -0
  65. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +25 -21
  66. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +28 -24
  67. data/lib/graphql/static_validation/rules/fields_will_merge.rb +84 -80
  68. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +49 -43
  69. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +22 -17
  70. data/lib/graphql/static_validation/rules/fragments_are_finite.rb +19 -15
  71. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +25 -20
  72. data/lib/graphql/static_validation/rules/fragments_are_used.rb +36 -23
  73. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +29 -25
  74. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +21 -17
  75. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +79 -70
  76. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +24 -20
  77. data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +122 -119
  78. data/lib/graphql/static_validation/type_stack.rb +138 -129
  79. data/lib/graphql/static_validation/validator.rb +29 -25
  80. data/lib/graphql/type_kinds.rb +42 -40
  81. data/lib/graphql/union_type.rb +22 -16
  82. data/lib/graphql/version.rb +1 -1
  83. data/readme.md +12 -27
  84. data/spec/graphql/base_type_spec.rb +3 -3
  85. data/spec/graphql/directive_spec.rb +10 -18
  86. data/spec/graphql/enum_type_spec.rb +7 -7
  87. data/spec/graphql/execution_error_spec.rb +1 -1
  88. data/spec/graphql/field_spec.rb +14 -13
  89. data/spec/graphql/id_type_spec.rb +6 -6
  90. data/spec/graphql/input_object_type_spec.rb +39 -39
  91. data/spec/graphql/interface_type_spec.rb +16 -32
  92. data/spec/graphql/introspection/directive_type_spec.rb +5 -9
  93. data/spec/graphql/introspection/input_value_type_spec.rb +10 -4
  94. data/spec/graphql/introspection/introspection_query_spec.rb +2 -2
  95. data/spec/graphql/introspection/schema_type_spec.rb +2 -2
  96. data/spec/graphql/introspection/type_type_spec.rb +34 -6
  97. data/spec/graphql/language/parser_spec.rb +299 -105
  98. data/spec/graphql/language/visitor_spec.rb +4 -4
  99. data/spec/graphql/list_type_spec.rb +11 -11
  100. data/spec/graphql/object_type_spec.rb +10 -10
  101. data/spec/graphql/query/arguments_spec.rb +7 -7
  102. data/spec/graphql/query/context_spec.rb +11 -3
  103. data/spec/graphql/query/executor_spec.rb +26 -19
  104. data/spec/graphql/query/serial_execution/execution_context_spec.rb +6 -6
  105. data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -2
  106. data/spec/graphql/query/type_resolver_spec.rb +3 -3
  107. data/spec/graphql/query_spec.rb +6 -38
  108. data/spec/graphql/scalar_type_spec.rb +28 -19
  109. data/spec/graphql/schema/field_validator_spec.rb +1 -1
  110. data/spec/graphql/schema/middleware_chain_spec.rb +12 -1
  111. data/spec/graphql/schema/printer_spec.rb +12 -4
  112. data/spec/graphql/schema/rescue_middleware_spec.rb +1 -1
  113. data/spec/graphql/schema/type_expression_spec.rb +2 -2
  114. data/spec/graphql/schema/type_reducer_spec.rb +21 -36
  115. data/spec/graphql/schema/type_validator_spec.rb +9 -9
  116. data/spec/graphql/schema_spec.rb +1 -1
  117. data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +4 -4
  118. data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +4 -4
  119. data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +5 -5
  120. data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +39 -0
  121. data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +5 -5
  122. data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +4 -4
  123. data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
  124. data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +1 -1
  125. data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +2 -2
  126. data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +2 -2
  127. data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +2 -2
  128. data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +3 -3
  129. data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +3 -3
  130. data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +5 -5
  131. data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +3 -1
  132. data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +4 -4
  133. data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +3 -3
  134. data/spec/graphql/static_validation/type_stack_spec.rb +3 -2
  135. data/spec/graphql/static_validation/validator_spec.rb +26 -6
  136. data/spec/graphql/union_type_spec.rb +5 -4
  137. data/spec/spec_helper.rb +2 -5
  138. data/spec/support/dairy_app.rb +30 -9
  139. data/spec/support/dairy_data.rb +1 -1
  140. data/spec/support/star_wars_data.rb +26 -26
  141. data/spec/support/star_wars_schema.rb +1 -1
  142. metadata +40 -21
  143. data/lib/graphql/language/transform.rb +0 -113
  144. data/lib/graphql/query/directive_chain.rb +0 -44
  145. data/lib/graphql/repl.rb +0 -27
  146. data/spec/graphql/language/transform_spec.rb +0 -156
@@ -5,6 +5,7 @@ module GraphQL
5
5
  @schema = schema
6
6
  @ast_node = ast_node
7
7
  end
8
+
8
9
  def type
9
10
  @type ||= build_type(@schema, @ast_node)
10
11
  end
@@ -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, :fetch, :to_h
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 warnings
34
- interface_only_types = @storage.values - safely_discovered_types
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
- # Starting from a given type, discover other types in the system by
2
- # traversing that type's fields, possible_types, etc
3
- class GraphQL::Schema::TypeReducer
4
- attr_reader :type, :existing_type_hash
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
- def initialize(type, existing_type_hash)
7
- validate_type(type)
8
- if type.respond_to?(:name) && existing_type_hash.fetch(type.name, nil).equal?(type)
9
- @result = existing_type_hash
10
- else
11
- @type = type
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
- safely_discovered(type_hash, field.type)
15
+ @existing_type_hash = existing_type_hash
45
16
  end
46
- end
47
- if type.kind.object?
48
- type.interfaces.each do |interface|
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
- end
53
- if type.kind.resolves?
54
- type.possible_types.each do |possible_type|
55
- reduce_type(possible_type, type_hash)
56
- if type.kind.union?
57
- safely_discovered(type_hash, possible_type)
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
- type_hash
69
- end
30
+ private
70
31
 
71
- def reduce_type(type, type_hash)
72
- if type.is_a?(GraphQL::BaseType)
73
- self.class.new(type.unwrap, type_hash).result
74
- else
75
- raise GraphQL::Schema::InvalidTypeError.new(type, ["Must be a GraphQL::BaseType"])
76
- end
77
- end
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
- def validate_type(type)
80
- errors = []
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
- def safely_discovered(type_hash, type)
89
- inner_type = type.unwrap
90
- if !type_hash.safely_discovered_types.include?(inner_type)
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
- type_hash.safely_discovered_types << inner_type
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
- class GraphQL::Schema::TypeValidator
2
- def validate(type, errors)
3
- own_errors = []
4
- implementation = GraphQL::Schema::ImplementationValidator.new(type, as: "Type", errors: own_errors)
5
- implementation.must_respond_to(:name)
6
- implementation.must_respond_to(:kind)
7
- if own_errors.any? # if no name or kind, abort!
8
- errors.push(*own_errors)
9
- return
10
- end
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
- type_name = type.name
13
- kind_name = type.kind.name
14
+ type_name = type.name
15
+ kind_name = type.kind.name
14
16
 
15
- implementation.must_respond_to(:description, as: kind_name)
16
- each_item_validator = GraphQL::Schema::EachItemValidator.new(own_errors)
17
+ implementation.must_respond_to(:description, as: kind_name)
18
+ each_item_validator = GraphQL::Schema::EachItemValidator.new(own_errors)
17
19
 
18
- if type.kind.fields?
19
- field_validator = GraphQL::Schema::FieldValidator.new
20
- implementation.must_respond_to(:fields, as: kind_name) do |fields|
21
- each_item_validator.validate(fields.keys, as: "#{type.name}.fields keys", must_be: "Strings") { |k| k.is_a?(String) }
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
- fields.values.each do |field|
24
- field_validator.validate(field, own_errors)
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
- if type.kind.resolves?
30
- implementation.must_respond_to(:resolve_type)
31
- implementation.must_respond_to(:possible_types, as: kind_name) do |possible_types|
32
- each_item_validator.validate(possible_types, as: "#{type_name}.possible_types", must_be: "objects") { |t| t.kind.object? }
33
- end
34
- end
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
- if type.kind.object?
37
- implementation.must_respond_to(:interfaces, as: kind_name) do |interfaces|
38
- each_item_validator.validate(interfaces, as: "#{type_name}.interfaces", must_be: "interfaces") { |t| t.kind.interface? }
39
- end
40
- end
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
- if type.kind.input_object?
43
- implementation.must_respond_to(:input_fields, as: kind_name)
44
- end
44
+ if type.kind.input_object?
45
+ implementation.must_respond_to(:input_fields, as: kind_name)
46
+ end
45
47
 
46
- if type.kind.union?
47
- union_types = type.possible_types
48
- if union_types.none?
49
- own_errors << "Union #{type_name} must be defined with 1 or more types, not 0!"
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
- module GraphQL::StaticValidation
2
- end
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 'graphql/static_validation/all_rules'
14
+ require "graphql/static_validation/all_rules"
@@ -1,24 +1,29 @@
1
- # Default rules for {GraphQL::StaticValidation::Validator}
2
- #
3
- # Order is important here. Some validators return {GraphQL::Language::Visitor::SKIP}
4
- # which stops the visit on that node. That way it doesn't try to find fields on types that
5
- # don't exist, etc.
6
- GraphQL::StaticValidation::ALL_RULES = [
7
- GraphQL::StaticValidation::DirectivesAreDefined,
8
- GraphQL::StaticValidation::FragmentsAreFinite,
9
- GraphQL::StaticValidation::FragmentTypesExist,
10
- GraphQL::StaticValidation::FragmentsAreOnCompositeTypes,
11
- GraphQL::StaticValidation::FragmentSpreadsArePossible,
12
- GraphQL::StaticValidation::FragmentsAreUsed,
13
- GraphQL::StaticValidation::FieldsAreDefinedOnType,
14
- GraphQL::StaticValidation::FieldsWillMerge,
15
- GraphQL::StaticValidation::FieldsHaveAppropriateSelections,
16
- GraphQL::StaticValidation::ArgumentsAreDefined,
17
- GraphQL::StaticValidation::ArgumentLiteralsAreCompatible,
18
- GraphQL::StaticValidation::RequiredArgumentsArePresent,
19
- GraphQL::StaticValidation::VariablesAreInputTypes,
20
- GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTyped,
21
- GraphQL::StaticValidation::VariablesAreUsedAndDefined,
22
- GraphQL::StaticValidation::VariableUsagesAreAllowed,
23
- GraphQL::StaticValidation::DocumentDoesNotExceedMaxDepth,
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
- # Implement validate_node
2
- class GraphQL::StaticValidation::ArgumentsValidator
3
- include GraphQL::StaticValidation::Message::MessageHelper
1
+ module GraphQL
2
+ module StaticValidation
3
+ # Implement validate_node
4
+ class ArgumentsValidator
5
+ include GraphQL::StaticValidation::Message::MessageHelper
4
6
 
5
- def validate(context)
6
- visitor = context.visitor
7
- visitor[GraphQL::Language::Nodes::Argument] << -> (node, parent) {
8
- if parent.is_a?(GraphQL::Language::Nodes::InputObject)
9
- arg_defn = context.argument_definition
10
- if arg_defn.nil?
11
- return
12
- else
13
- parent_defn = arg_defn.type.unwrap
14
- if parent_defn.is_a?(GraphQL::ScalarType)
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
- end
18
- elsif context.skip_field?(parent.name)
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
- private
31
+ private
30
32
 
31
- def parent_name(parent, type_defn)
32
- field_name = if parent.is_a?(GraphQL::Language::Nodes::Field)
33
- parent.alias || parent.name
34
- elsif parent.is_a?(GraphQL::Language::Nodes::InputObject)
35
- type_defn.name
36
- else
37
- parent.name
38
- end
39
- end
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
- def node_type(parent)
42
- parent.class.name.split("::").last
43
+ def node_type(parent)
44
+ parent.class.name.split("::").last
45
+ end
46
+ end
43
47
  end
44
48
  end