I am trying to serialize data from a GraphQL Apollo request into JSON in order to decode into my swift model. However, when trying to serialize the data with an enum it fails.
static func decodeUser(userJson:JSONObject)->UserQL?{
let decoder = JSONDecoder()
print(userJson)
guard let jsonData = try? JSONSerializationFormat.serialize(value: userJson) else {
return nil
}
return try? decoder.decode(UserQL.self, from: jsonData)
}
Below is my User DTO
struct UserQL:Codable,Equatable{
var id:String
var username:String
var userType: UserType
var photoUrl:String?
var createdAt:String?
var bio:String?
enum CodingKeys:String,CodingKey {
case id,username,photoUrl,createdAt,bio,userType
}
I have tried changing userType to GraphQLEnum, however, that does not do anything. I was able to find a fix by changing the userType on the type User in the schema to String! because the enum is piped across as a String, then defining the enum in swift
I’m hoping to be able to avoid that though, because then my schema won’t match across platforms.