@@ -114,6 +114,25 @@ public struct GraphQLError : Error, Codable {
114
114
originalError: error
115
115
)
116
116
}
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
+ }
117
136
}
118
137
119
138
extension GraphQLError : CustomStringConvertible {
@@ -144,6 +163,16 @@ public struct IndexPath : Codable {
144
163
public func appending( _ elements: IndexPathElement ) -> IndexPath {
145
164
return IndexPath ( self . elements + [ elements] )
146
165
}
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
+ }
147
176
}
148
177
149
178
extension IndexPath : ExpressibleByArrayLiteral {
0 commit comments