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
12import NIO
23
3- public struct GraphQLResult : Equatable {
4+ public struct GraphQLResult : Equatable , Encodable , CustomStringConvertible {
45 public var data : Map ?
56 public var errors : [ GraphQLError ]
67
78 public init ( data: Map ? = nil , errors: [ GraphQLError ] = [ ] ) {
89 self . data = data
910 self . errors = errors
1011 }
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+ }
1134}
1235
1336/// This is the primary entry point function for fulfilling GraphQL operations
You can’t perform that action at this time.
0 commit comments