Reputation: 380
I'm using GraphQL latest version 1.9.3
They have removed option of passThroughCustomScalar
Currently response is coming in dictionary form and schema.graphql has generated as below
public typealias JSON = String
I've tried below code to convert string to dictionary
extension JSON: JSONDecodable, JSONEncodable {
public init(jsonValue value: JSONValue) throws {
switch value {
case let string as String:
self = string
case let int as Int:
self = String(int)
case let dictionary as [String: Any]:
guard let data = try? JSONSerialization.data(withJSONObject: dictionary, options: []) else { fallthrough }
guard let serializedJson = String(data: data, encoding: .utf8) else { fallthrough }
self = serializedJson
default:
throw JSONDecodingError.couldNotConvert(value: value, to: String.self)
}
}
public var jsonValue: JSONValue {
return self
}
}
Still I'm getting error of jsondecoding
ApolloAPI.JSONDecodingError.couldNotConvert(value: AnyHashable
to: Swift.String))
Please help me
Upvotes: 0
Views: 79