Skip to content

Commit 913eec5

Browse files
committed
protect from nil
1 parent 8dab0dc commit 913eec5

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Sources/GraphQL/Execution/Execute.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ func completeValue(
687687
}
688688

689689
// If result value is null-ish (nil or .null) then return .null.
690-
guard let r = result else {
690+
guard let res = result, let r = unwrap(res) else {
691691
return nil
692692
}
693693

@@ -951,8 +951,12 @@ func defaultResolve(source: Any, args: Map, context: Any, info: GraphQLResolveIn
951951
return nil
952952
}
953953

954+
guard let s = source as? MapFallibleRepresentable else {
955+
return nil
956+
}
957+
954958
// TODO: check why Reflection fails
955-
guard let value = try? get(info.fieldName, from: source) else {
959+
guard let value = try? get(info.fieldName, from: s) else {
956960
return nil
957961
}
958962

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
public func unwrap(_ value: Any) -> MapFallibleRepresentable? {
1+
func unwrap(_ value: Any) -> Any? {
22
let mirror = Mirror(reflecting: value)
33

44
if mirror.displayStyle != .optional {
5-
return value as? MapFallibleRepresentable
5+
return value
66
}
77

88
if mirror.children.isEmpty {
99
return nil
1010
}
1111

1212
let child = mirror.children.first!
13-
return child.value as? MapFallibleRepresentable
13+
return child.value
1414
}

0 commit comments

Comments
 (0)