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
@@ -1,98 +1,101 @@
1
- class GraphQL::Query
2
- class OperationNameMissingError < GraphQL::Error
3
- def initialize(names)
4
- msg = "You must provide an operation name from: #{names.join(", ")}"
5
- super(msg)
1
+ module GraphQL
2
+ # A combination of query string and {Schema} instance which can be reduced to a {#result}.
3
+ class Query
4
+ class OperationNameMissingError < GraphQL::ExecutionError
5
+ def initialize(names)
6
+ msg = "You must provide an operation name from: #{names.join(", ")}"
7
+ super(msg)
8
+ end
6
9
  end
7
- end
8
10
 
9
- attr_reader :schema, :document, :context, :fragments, :operations, :debug, :max_depth
11
+ attr_reader :schema, :document, :context, :fragments, :operations, :debug, :max_depth
10
12
 
11
- # Prepare query `query_string` on `schema`
12
- # @param schema [GraphQL::Schema]
13
- # @param query_string [String]
14
- # @param context [#[]] an arbitrary hash of values which you can access in {GraphQL::Field#resolve}
15
- # @param variables [Hash] values for `$variables` in the query
16
- # @param debug [Boolean] if true, errors are raised, if false, errors are put in the `errors` key
17
- # @param validate [Boolean] if true, `query_string` will be validated with {StaticValidation::Validator}
18
- # @param operation_name [String] if the query string contains many operations, this is the one which should be executed
19
- def initialize(schema, query_string, context: nil, variables: {}, debug: false, validate: true, operation_name: nil, max_depth: nil)
20
- @schema = schema
21
- @debug = debug
22
- @max_depth = max_depth || schema.max_depth
23
- @context = Context.new(query: self, values: context)
24
- @validate = validate
25
- @operation_name = operation_name
26
- @fragments = {}
27
- @operations = {}
28
- @provided_variables = variables
29
- @document = GraphQL.parse(query_string)
30
- @document.definitions.each do |part|
31
- if part.is_a?(GraphQL::Language::Nodes::FragmentDefinition)
32
- @fragments[part.name] = part
33
- elsif part.is_a?(GraphQL::Language::Nodes::OperationDefinition)
34
- @operations[part.name] = part
13
+ # Prepare query `query_string` on `schema`
14
+ # @param schema [GraphQL::Schema]
15
+ # @param query_string [String]
16
+ # @param context [#[]] an arbitrary hash of values which you can access in {GraphQL::Field#resolve}
17
+ # @param variables [Hash] values for `$variables` in the query
18
+ # @param debug [Boolean] if true, errors are raised, if false, errors are put in the `errors` key
19
+ # @param validate [Boolean] if true, `query_string` will be validated with {StaticValidation::Validator}
20
+ # @param operation_name [String] if the query string contains many operations, this is the one which should be executed
21
+ def initialize(schema, query_string, context: nil, variables: {}, debug: false, validate: true, operation_name: nil, max_depth: nil)
22
+ @schema = schema
23
+ @debug = debug
24
+ @max_depth = max_depth || schema.max_depth
25
+ @context = Context.new(query: self, values: context)
26
+ @validate = validate
27
+ @operation_name = operation_name
28
+ @fragments = {}
29
+ @operations = {}
30
+ @provided_variables = variables
31
+ @document = GraphQL.parse(query_string)
32
+ @document.definitions.each do |part|
33
+ if part.is_a?(GraphQL::Language::Nodes::FragmentDefinition)
34
+ @fragments[part.name] = part
35
+ elsif part.is_a?(GraphQL::Language::Nodes::OperationDefinition)
36
+ @operations[part.name] = part
37
+ end
35
38
  end
36
39
  end
37
- end
38
40
 
39
- # Get the result for this query, executing it once
40
- def result
41
- if @validate && validation_errors.any?
42
- return { "errors" => validation_errors }
43
- end
41
+ # Get the result for this query, executing it once
42
+ def result
43
+ if @validate && validation_errors.any?
44
+ return { "errors" => validation_errors }
45
+ end
44
46
 
45
- @result ||= Executor.new(self).result
46
- end
47
+ @result ||= Executor.new(self).result
48
+ end
47
49
 
48
50
 
49
- # This is the operation to run for this query.
50
- # If more than one operation is present, it must be named at runtime.
51
- # @return [GraphQL::Language::Nodes::OperationDefinition, nil]
52
- def selected_operation
53
- @selected_operation ||= find_operation(@operations, @operation_name)
54
- end
51
+ # This is the operation to run for this query.
52
+ # If more than one operation is present, it must be named at runtime.
53
+ # @return [GraphQL::Language::Nodes::OperationDefinition, nil]
54
+ def selected_operation
55
+ @selected_operation ||= find_operation(@operations, @operation_name)
56
+ end
55
57
 
56
- # Determine the values for variables of this query, using default values
57
- # if a value isn't provided at runtime.
58
- #
59
- # Raises if a non-null variable isn't provided at runtime.
60
- # @return [GraphQL::Query::Variables] Variables to apply to this query
61
- def variables
62
- @variables ||= GraphQL::Query::Variables.new(
63
- schema,
64
- selected_operation.variables,
65
- @provided_variables
66
- )
67
- end
58
+ # Determine the values for variables of this query, using default values
59
+ # if a value isn't provided at runtime.
60
+ #
61
+ # Raises if a non-null variable isn't provided at runtime.
62
+ # @return [GraphQL::Query::Variables] Variables to apply to this query
63
+ def variables
64
+ @variables ||= GraphQL::Query::Variables.new(
65
+ schema,
66
+ selected_operation.variables,
67
+ @provided_variables
68
+ )
69
+ end
68
70
 
69
- private
71
+ private
70
72
 
71
- def validation_errors
72
- @validation_errors ||= schema.static_validator.validate(self)
73
- end
73
+ def validation_errors
74
+ @validation_errors ||= schema.static_validator.validate(self)
75
+ end
74
76
 
75
77
 
76
- def find_operation(operations, operation_name)
77
- if operations.length == 1
78
- operations.values.first
79
- elsif operations.length == 0
80
- nil
81
- elsif !operations.key?(operation_name)
82
- raise OperationNameMissingError, operations.keys
83
- else
84
- operations[operation_name]
78
+ def find_operation(operations, operation_name)
79
+ if operations.length == 1
80
+ operations.values.first
81
+ elsif operations.length == 0
82
+ nil
83
+ elsif !operations.key?(operation_name)
84
+ raise OperationNameMissingError, operations.keys
85
+ else
86
+ operations[operation_name]
87
+ end
85
88
  end
86
89
  end
87
90
  end
88
91
 
89
- require 'graphql/query/arguments'
90
- require 'graphql/query/context'
91
- require 'graphql/query/directive_chain'
92
- require 'graphql/query/executor'
93
- require 'graphql/query/literal_input'
94
- require 'graphql/query/serial_execution'
95
- require 'graphql/query/type_resolver'
96
- require 'graphql/query/variables'
97
- require 'graphql/query/input_validation_result'
98
- require 'graphql/query/variable_validation_error'
92
+ require "graphql/query/arguments"
93
+ require "graphql/query/context"
94
+ require "graphql/query/directive_resolution"
95
+ require "graphql/query/executor"
96
+ require "graphql/query/literal_input"
97
+ require "graphql/query/serial_execution"
98
+ require "graphql/query/type_resolver"
99
+ require "graphql/query/variables"
100
+ require "graphql/query/input_validation_result"
101
+ require "graphql/query/variable_validation_error"
@@ -15,12 +15,16 @@ module GraphQL
15
15
  # @return [GraphQL::Query] The query whose context this is
16
16
  attr_reader :query
17
17
 
18
+ # @return [GraphQL::Schema]
19
+ attr_reader :schema
20
+
18
21
  # Make a new context which delegates key lookup to `values`
19
22
  # @param query [GraphQL::Query] the query who owns this context
20
23
  # @param values [Hash] A hash of arbitrary values which will be accessible at query-time
21
24
  def initialize(query:, values:)
22
25
  @query = query
23
- @values = values
26
+ @schema = query.schema
27
+ @values = values || {}
24
28
  @errors = []
25
29
  end
26
30
 
@@ -0,0 +1,16 @@
1
+ module GraphQL
2
+ class Query
3
+ module DirectiveResolution
4
+ def self.include_node?(ast_node, query)
5
+ ast_node.directives.each do |ast_directive|
6
+ directive = query.schema.directives[ast_directive.name]
7
+ args = GraphQL::Query::LiteralInput.from_arguments(ast_directive.arguments, directive.arguments, query.variables)
8
+ if !directive.include?(args)
9
+ return false
10
+ end
11
+ end
12
+ true
13
+ end
14
+ end
15
+ end
16
+ end
@@ -14,12 +14,12 @@ module GraphQL
14
14
  def result
15
15
  execute
16
16
  rescue GraphQL::ExecutionError => err
17
+ query.context.errors << err
17
18
  {"errors" => [err.to_h]}
18
- rescue GraphQL::Query::OperationNameMissingError => err
19
- {"errors" => [{"message" => err.message}]}
20
19
  rescue StandardError => err
20
+ query.context.errors << err
21
21
  query.debug && raise(err)
22
- message = "Something went wrong during query execution: #{err}" #\n#{err.backtrace.join("\n ")}"
22
+ message = "Internal error" # : #{err} \n#{err.backtrace.join("\n ")}"
23
23
  {"errors" => [{"message" => message}]}
24
24
  end
25
25
 
@@ -1,22 +1,24 @@
1
- class GraphQL::Query
2
- class InputValidationResult
3
- attr_accessor :problems
1
+ module GraphQL
2
+ class Query
3
+ class InputValidationResult
4
+ attr_accessor :problems
4
5
 
5
- def valid?
6
- @problems.nil?
7
- end
6
+ def valid?
7
+ @problems.nil?
8
+ end
8
9
 
9
- def add_problem(explanation, path = nil)
10
- @problems ||= []
11
- @problems.push({ 'path' => path || [], 'explanation' => explanation })
12
- end
10
+ def add_problem(explanation, path = nil)
11
+ @problems ||= []
12
+ @problems.push({ "path" => path || [], "explanation" => explanation })
13
+ end
13
14
 
14
- def merge_result!(path, inner_result)
15
- return if inner_result.valid?
15
+ def merge_result!(path, inner_result)
16
+ return if inner_result.valid?
16
17
 
17
- inner_result.problems.each do |p|
18
- item_path = [path, *p['path']]
19
- add_problem(p['explanation'], item_path)
18
+ inner_result.problems.each do |p|
19
+ item_path = [path, *p["path"]]
20
+ add_problem(p["explanation"], item_path)
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -32,8 +32,8 @@ module GraphQL
32
32
  end
33
33
  end
34
34
 
35
- require 'graphql/query/serial_execution/execution_context'
36
- require 'graphql/query/serial_execution/value_resolution'
37
- require 'graphql/query/serial_execution/field_resolution'
38
- require 'graphql/query/serial_execution/operation_resolution'
39
- require 'graphql/query/serial_execution/selection_resolution'
35
+ require "graphql/query/serial_execution/execution_context"
36
+ require "graphql/query/serial_execution/value_resolution"
37
+ require "graphql/query/serial_execution/field_resolution"
38
+ require "graphql/query/serial_execution/operation_resolution"
39
+ require "graphql/query/serial_execution/selection_resolution"
@@ -2,15 +2,16 @@ module GraphQL
2
2
  class Query
3
3
  class SerialExecution
4
4
  class ExecutionContext
5
- attr_reader :query, :strategy
5
+ attr_reader :query, :schema, :strategy
6
6
 
7
7
  def initialize(query, strategy)
8
8
  @query = query
9
+ @schema = query.schema
9
10
  @strategy = strategy
10
11
  end
11
12
 
12
13
  def get_type(type)
13
- @query.schema.types[type]
14
+ @schema.types[type]
14
15
  end
15
16
 
16
17
  def get_fragment(name)
@@ -18,7 +19,7 @@ module GraphQL
18
19
  end
19
20
 
20
21
  def get_field(type, name)
21
- @query.schema.get_field(type, name)
22
+ @schema.get_field(type, name)
22
23
  end
23
24
 
24
25
  def add_error(err)
@@ -41,18 +41,14 @@ module GraphQL
41
41
  end
42
42
 
43
43
  def flatten_inline_fragment(ast_node)
44
- chain = GraphQL::Query::DirectiveChain.new(ast_node, execution_context.query) {
45
- flatten_fragment(ast_node)
46
- }
47
- chain.result
44
+ return {} unless GraphQL::Query::DirectiveResolution.include_node?(ast_node, execution_context.query)
45
+ flatten_fragment(ast_node)
48
46
  end
49
47
 
50
48
  def flatten_fragment_spread(ast_node)
49
+ return {} unless GraphQL::Query::DirectiveResolution.include_node?(ast_node, execution_context.query)
51
50
  ast_fragment_defn = execution_context.get_fragment(ast_node.name)
52
- chain = GraphQL::Query::DirectiveChain.new(ast_node, execution_context.query) {
53
- flatten_fragment(ast_fragment_defn)
54
- }
55
- chain.result
51
+ flatten_fragment(ast_fragment_defn)
56
52
  end
57
53
 
58
54
  def flatten_fragment(ast_fragment)
@@ -64,9 +60,13 @@ module GraphQL
64
60
  end
65
61
 
66
62
  def fragment_type_can_apply?(ast_fragment)
67
- child_type = execution_context.get_type(ast_fragment.type)
68
- resolved_type = GraphQL::Query::TypeResolver.new(target, child_type, type).type
69
- !resolved_type.nil?
63
+ if ast_fragment.type.nil?
64
+ true
65
+ else
66
+ child_type = execution_context.get_type(ast_fragment.type)
67
+ resolved_type = GraphQL::Query::TypeResolver.new(target, child_type, type, execution_context.query.context).type
68
+ !resolved_type.nil?
69
+ end
70
70
  end
71
71
 
72
72
  def merge_fields(field1, field2)
@@ -89,15 +89,13 @@ module GraphQL
89
89
  end
90
90
 
91
91
  def resolve_field(ast_node)
92
- chain = GraphQL::Query::DirectiveChain.new(ast_node, execution_context.query) {
93
- execution_context.strategy.field_resolution.new(
94
- ast_node,
95
- type,
96
- target,
97
- execution_context
98
- ).result
99
- }
100
- chain.result
92
+ return {} unless GraphQL::Query::DirectiveResolution.include_node?(ast_node, execution_context.query)
93
+ execution_context.strategy.field_resolution.new(
94
+ ast_node,
95
+ type,
96
+ target,
97
+ execution_context
98
+ ).result
101
99
  end
102
100
 
103
101
  def merge_into_result(memo, selection)
@@ -107,7 +105,7 @@ module GraphQL
107
105
  selection.name
108
106
  end
109
107
 
110
- memo[name] = if memo.has_key?(name)
108
+ memo[name] = if memo.key?(name)
111
109
  merge_fields(memo[name], selection)
112
110
  else
113
111
  selection
@@ -54,7 +54,7 @@ module GraphQL
54
54
 
55
55
  class HasPossibleTypeResolution < BaseResolution
56
56
  def non_null_result
57
- resolved_type = field_type.resolve_type(value)
57
+ resolved_type = field_type.resolve_type(value, execution_context)
58
58
  strategy_class = get_strategy_for_kind(resolved_type.kind)
59
59
  inner_strategy = strategy_class.new(value, resolved_type, target, parent_type, ast_field, execution_context)
60
60
  inner_strategy.result
@@ -1,21 +1,25 @@
1
- # Given an object, a type name (from the query) and a type object,
2
- # Return the type that should be used for `object`
3
- # or Return `nil` if it's a mismatch
4
- class GraphQL::Query::TypeResolver
5
- attr_reader :type
6
- def initialize(target, child_type, parent_type)
7
- @type = if child_type.nil?
8
- nil
9
- elsif parent_type.kind.union?
10
- parent_type.resolve_type(target)
11
- elsif child_type.kind.union? && child_type.include?(parent_type)
12
- parent_type
13
- elsif child_type.kind.interface?
14
- child_type.resolve_type(target)
15
- elsif child_type == parent_type
16
- parent_type
17
- else
18
- nil
1
+ module GraphQL
2
+ class Query
3
+ # Given an object, a type name (from the query) and a type object,
4
+ # Return the type that should be used for `object`
5
+ # or Return `nil` if it's a mismatch
6
+ class TypeResolver
7
+ attr_reader :type
8
+ def initialize(target, child_type, parent_type, query_ctx)
9
+ @type = if child_type.nil?
10
+ nil
11
+ elsif parent_type.kind.union?
12
+ parent_type.resolve_type(target)
13
+ elsif child_type.kind.union? && child_type.include?(parent_type)
14
+ parent_type
15
+ elsif child_type.kind.interface?
16
+ child_type.resolve_type(target, query_ctx)
17
+ elsif child_type == parent_type
18
+ parent_type
19
+ else
20
+ nil
21
+ end
22
+ end
19
23
  end
20
24
  end
21
25
  end
@@ -1,18 +1,20 @@
1
- class GraphQL::Query
2
- class VariableValidationError < GraphQL::ExecutionError
3
- attr_accessor :value, :validation_result
1
+ module GraphQL
2
+ class Query
3
+ class VariableValidationError < GraphQL::ExecutionError
4
+ attr_accessor :value, :validation_result
4
5
 
5
- def initialize(variable_ast, type, value, validation_result)
6
- @value = value
7
- @validation_result = validation_result
6
+ def initialize(variable_ast, type, value, validation_result)
7
+ @value = value
8
+ @validation_result = validation_result
8
9
 
9
- msg = "Variable #{variable_ast.name} of type #{type} was provided invalid value"
10
- super(msg)
11
- self.ast_node = variable_ast
12
- end
10
+ msg = "Variable #{variable_ast.name} of type #{type} was provided invalid value"
11
+ super(msg)
12
+ self.ast_node = variable_ast
13
+ end
13
14
 
14
- def to_h
15
- super.merge({ 'value' => value, 'problems' => validation_result.problems })
15
+ def to_h
16
+ super.merge({ "value" => value, "problems" => validation_result.problems })
17
+ end
16
18
  end
17
19
  end
18
20
  end