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.
- 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
data/lib/graphql/query.rb
CHANGED
@@ -1,98 +1,101 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
11
|
+
attr_reader :schema, :document, :context, :fragments, :operations, :debug, :max_depth
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
+
@result ||= Executor.new(self).result
|
48
|
+
end
|
47
49
|
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
71
|
+
private
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
def validation_errors
|
74
|
+
@validation_errors ||= schema.static_validator.validate(self)
|
75
|
+
end
|
74
76
|
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
90
|
-
require
|
91
|
-
require
|
92
|
-
require
|
93
|
-
require
|
94
|
-
require
|
95
|
-
require
|
96
|
-
require
|
97
|
-
require
|
98
|
-
require
|
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
|
-
@
|
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 = "
|
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
|
-
|
2
|
-
class
|
3
|
-
|
1
|
+
module GraphQL
|
2
|
+
class Query
|
3
|
+
class InputValidationResult
|
4
|
+
attr_accessor :problems
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def valid?
|
7
|
+
@problems.nil?
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def add_problem(explanation, path = nil)
|
11
|
+
@problems ||= []
|
12
|
+
@problems.push({ "path" => path || [], "explanation" => explanation })
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def merge_result!(path, inner_result)
|
16
|
+
return if inner_result.valid?
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
require
|
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
|
-
@
|
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
|
-
@
|
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
|
-
|
45
|
-
|
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
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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.
|
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
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
2
|
-
class
|
3
|
-
|
1
|
+
module GraphQL
|
2
|
+
class Query
|
3
|
+
class VariableValidationError < GraphQL::ExecutionError
|
4
|
+
attr_accessor :value, :validation_result
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def initialize(variable_ast, type, value, validation_result)
|
7
|
+
@value = value
|
8
|
+
@validation_result = validation_result
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
15
|
+
def to_h
|
16
|
+
super.merge({ "value" => value, "problems" => validation_result.problems })
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|