Skip to content

Commit 2c80a9d

Browse files
author
Garrett Moseke
committed
fix: correctly handle missing GraphQLError location/path on decode
1 parent b1e12f5 commit 2c80a9d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/GraphQL/Error/GraphQLError.swift

Lines changed: 3 additions & 3 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

@@ -127,7 +127,7 @@ public struct GraphQLError: Error, Codable {
127127

128128
try container.encode(message, forKey: .message)
129129

130-
if !locations.isEmpty {
130+
if locations.isEmpty {
131131
try container.encode(locations, forKey: .locations)
132132
}
133133

@@ -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)