@@ -114,6 +114,25 @@ public struct GraphQLError : Error, Codable {
114114 originalError: error
115115 )
116116 }
117+
118+ public init ( from decoder: Decoder ) throws {
119+ let container = try decoder. container ( keyedBy: CodingKeys . self)
120+ message = try container. decode ( String . self, forKey: . message)
121+ locations = try container. decode ( [ SourceLocation] ? . self, forKey: . locations) ?? [ ]
122+ path = try container. decode ( IndexPath . self, forKey: . path)
123+ }
124+
125+ public func encode( to encoder: Encoder ) throws {
126+ var container = encoder. container ( keyedBy: CodingKeys . self)
127+
128+ try container. encode ( message, forKey: . message)
129+
130+ if !locations. isEmpty {
131+ try container. encode ( locations, forKey: . locations)
132+ }
133+
134+ try container. encode ( path, forKey: . path)
135+ }
117136}
118137
119138extension GraphQLError : CustomStringConvertible {
@@ -144,6 +163,16 @@ public struct IndexPath : Codable {
144163 public func appending( _ elements: IndexPathElement ) -> IndexPath {
145164 return IndexPath ( self . elements + [ elements] )
146165 }
166+
167+ public init ( from decoder: Decoder ) throws {
168+ var container = try decoder. unkeyedContainer ( )
169+ elements = try container. decode ( [ IndexPathValue ] . self)
170+ }
171+
172+ public func encode( to encoder: Encoder ) throws {
173+ var container = encoder. unkeyedContainer ( )
174+ try container. encode ( contentsOf: elements)
175+ }
147176}
148177
149178extension IndexPath : ExpressibleByArrayLiteral {
0 commit comments