File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change
1
+ import Foundation
1
2
import NIO
2
3
3
- public struct GraphQLResult : Equatable {
4
+ public struct GraphQLResult : Equatable , Encodable , CustomStringConvertible {
4
5
public var data : Map ?
5
6
public var errors : [ GraphQLError ]
6
7
7
8
public init ( data: Map ? = nil , errors: [ GraphQLError ] = [ ] ) {
8
9
self . data = data
9
10
self . errors = errors
10
11
}
12
+
13
+ enum CodingKeys : String , CodingKey {
14
+ case data
15
+ case errors
16
+ }
17
+
18
+ public func encode( to encoder: Encoder ) throws {
19
+ var container = encoder. container ( keyedBy: CodingKeys . self)
20
+
21
+ if let data = self . data {
22
+ try container. encode ( data, forKey: . data)
23
+ }
24
+
25
+ if !self . errors. isEmpty {
26
+ try container. encode ( self . errors, forKey: . errors)
27
+ }
28
+ }
29
+
30
+ public var description : String {
31
+ let data = try ! JSONEncoder ( ) . encode ( self )
32
+ return String ( data: data, encoding: . utf8) !
33
+ }
11
34
}
12
35
13
36
/// This is the primary entry point function for fulfilling GraphQL operations
You can’t perform that action at this time.
0 commit comments