Skip to content

Commit 300dbd7

Browse files
Fixes variable defaultValues application
1 parent d4c8a04 commit 300dbd7

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Sources/GraphQL/Execution/Values.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@ import OrderedCollections
77
* parsed to match the variable definitions, a GraphQLError will be thrown.
88
*/
99
func getVariableValues(schema: GraphQLSchema, definitionASTs: [VariableDefinition], inputs: [String: Map]) throws -> [String: Map] {
10-
return try definitionASTs.reduce([:]) { values, defAST in
11-
var valuesCopy = values
10+
11+
var vars = [String: Map]()
12+
for defAST in definitionASTs {
1213
let varName = defAST.variable.name.value
13-
14-
valuesCopy[varName] = try getVariableValue(
14+
15+
let input: Map
16+
if let nonNilInput = inputs[varName] {
17+
input = nonNilInput
18+
} else {
19+
// If variable is not in inputs it is undefined
20+
input = .undefined
21+
}
22+
vars[varName] = try getVariableValue(
1523
schema: schema,
1624
definitionAST: defAST,
17-
input: inputs[varName] ?? .null
25+
input: input
1826
)
19-
20-
return valuesCopy
2127
}
28+
return vars
2229
}
2330

2431

Sources/GraphQL/Map/Map.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ extension Map : Equatable {}
709709

710710
public func == (lhs: Map, rhs: Map) -> Bool {
711711
switch (lhs, rhs) {
712+
case (.undefined, .undefined):
713+
return true
712714
case (.null, .null):
713715
return true
714716
case let (.bool(l), .bool(r)) where l == r:

0 commit comments

Comments
 (0)