Skip to content

Commit a301134

Browse files
Merge pull request #119 from GNMoseke/fix/optional-error-location
fix: correctly handle missing GraphQLError location/path on decode
2 parents b1e12f5 + ec6c690 commit a301134

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/GraphQL/Error/GraphQLError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public struct GraphQLError: Error, Codable {
118118
public init(from decoder: Decoder) throws {
119119
let container = try decoder.container(keyedBy: CodingKeys.self)
120120
message = try container.decode(String.self, forKey: .message)
121-
locations = try container.decode([SourceLocation]?.self, forKey: .locations) ?? []
121+
locations = (try? container.decode([SourceLocation]?.self, forKey: .locations)) ?? []
122122
path = try container.decode(IndexPath.self, forKey: .path)
123123
}
124124

@@ -166,7 +166,7 @@ public struct IndexPath: Codable {
166166

167167
public init(from decoder: Decoder) throws {
168168
var container = try decoder.unkeyedContainer()
169-
elements = try container.decode([IndexPathValue].self)
169+
elements = (try? container.decode([IndexPathValue].self)) ?? []
170170
}
171171

172172
public func encode(to encoder: Encoder) throws {

0 commit comments

Comments
 (0)