6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/graphql/query/serial_execution/value_resolution.rb', line 6
def self.resolve(parent_type, field_defn, field_type, value, selection, query_ctx)
if value.nil? || value.is_a?(GraphQL::ExecutionError)
if field_type.kind.non_null?
if value.nil?
type_error = GraphQL::InvalidNullError.new(parent_type, field_defn, value)
query_ctx.schema.type_error(type_error, query_ctx)
end
raise GraphQL::Query::Executor::PropagateNull
else
nil
end
else
case field_type.kind
when GraphQL::TypeKinds::SCALAR, GraphQL::TypeKinds::ENUM
field_type.coerce_result(value, query_ctx)
when GraphQL::TypeKinds::LIST
wrapped_type = field_type.of_type
result = []
i = 0
value.each do |inner_value|
inner_ctx = query_ctx.spawn_child(
key: i,
object: inner_value,
irep_node: selection,
)
result << resolve(
parent_type,
field_defn,
wrapped_type,
inner_value,
selection,
inner_ctx,
)
i += 1
end
result
when GraphQL::TypeKinds::NON_NULL
wrapped_type = field_type.of_type
resolve(
parent_type,
field_defn,
wrapped_type,
value,
selection,
query_ctx,
)
when GraphQL::TypeKinds::OBJECT
query_ctx.execution_strategy.selection_resolution.resolve(
value,
field_type,
selection,
query_ctx
)
when GraphQL::TypeKinds::UNION, GraphQL::TypeKinds::INTERFACE
query = query_ctx.query
resolved_type = query.resolve_type(value)
possible_types = query.possible_types(field_type)
if !possible_types.include?(resolved_type)
type_error = GraphQL::UnresolvedTypeError.new(value, field_defn, parent_type, resolved_type, possible_types)
query.schema.type_error(type_error, query_ctx)
raise GraphQL::Query::Executor::PropagateNull
else
resolve(
parent_type,
field_defn,
resolved_type,
value,
selection,
query_ctx,
)
end
else
raise("Unknown type kind: #{field_type.kind}")
end
end
end
|