As we query data from our server, we often deal with types of JSONObject which is a custom scalar of [String: JSONValue]. JSONValue is a type alias for Any. Our query looks something like this:
query QueryName($input: Intput!) {
resource{
user {
values(projections: $input)
}
}
}
This values object returns a JSONObject and the query functions perfectly using the Android library. However, working on the iOS library, we run into a failure while parsing the Dictionary.
extension Dictionary: JSONEncodable {
public var jsonValue: JSONValue {
return jsonObject
}
public var jsonObject: JSONObject {
var jsonObject = JSONObject(minimumCapacity: count)
for (key, value) in self {
if case let (key as String, value as JSONEncodable) = (key, value) {
jsonObject[key] = value.jsonValue
} else {
fatalError("Dictionary is only JSONEncodable if Value is (and if Key is String)") // We run into this fatalError
}
}
return jsonObject
}
}
This fatalError is called when trying to parse the following key-value pair:
key String "pk"
value __NSCFString "user#userID"
This seems to be an issue with casting the Objective-C CFString to NSString, but why would the string be in that format specifically when the backend simply sends a string?
What extensions do I need to add to be able to successfully parse a type of NSCFString and NSCFNumber (getting the same error with the number type).
We use SPM for our package management and are on Apollo-iOS version 0.53.0