You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the subscript for the new ObjectData, which uses the NetworkResponseExecutionSource.DataTransformer, returns nil for integer id fields.
letvalue= object._rawData["id"] // value is Optional(AnyHashable(<<Int>>))
switch value {caseletscalar as ScalarType:print(scalar)caseletcustomScalar as CustomScalarType:print(customScalar._jsonValue as?ScalarType)default:print("nil!") // prints "nil!"
}switch value {caseletintID as Int:print(intID) // this properly prints the int
default:print("\(type) could not translate \(value) from \(object)!!")returnnil}
Version
v1.2
Steps to reproduce the behavior
My project is closed, but the API I'm using (which I have no control over) is open.
publicenumSchemaConfiguration:ApolloAPI.SchemaConfiguration{publicstaticfunc cacheKeyInfo(for type:ApolloAPI.Object, object:ApolloAPI.ObjectData)->ApolloAPI.CacheKeyInfo?{switch type {caseObjects.Media:letvalue= object._rawData["id"] // value is Optional(AnyHashable(<<Int>>))
switch value {caseletscalar as ScalarType:print(scalar)caseletcustomScalar as CustomScalarType:print(customScalar._jsonValue as?ScalarType)default:print("subscript returns nil") // this line executes
}switch value {caseletintID as Int:print(intID) // this properly prints the int
returnCacheKeyInfo(id:String(intID))default:print("\(type) could not translate \(value) from \(object)!!")returnnil}default:returnnil}}}
The fix for this has been merged into main and will go out with our next release.
@asbhat For context, the issue was essentially the value in the _rawData being AnyHashable<Int64> instead of just Int due to how the JSONSerialization class works, so the ScalarType casting was failing. The subscript methods for ObjectData and ListData will now handle this appropriately, however directly accessing _rawData will still provide the Int64 value.
The recommended way to access values on ObjectData is through the subscript methods and not through the _rawData property which is meant for internal use. So this would be how you would access the data:
I'll stop using the internal API once it gets released 🙂
@asbhat the pattern we use to designate something is 'internal' is with the leading underscore _, or sometimes a double-underscore __. Because of the split between the Apollo and ApolloAPI modules we need to have types/functions public when they're only meant for internal use.
Summary
Using the subscript for the new
ObjectData
, which uses theNetworkResponseExecutionSource.DataTransformer
, returnsnil
for integer id fields.Version
v1.2
Steps to reproduce the behavior
My project is closed, but the API I'm using (which I have no control over) is open.
URL: https://graphql.anilist.co
Example query
Schema Configuration
Logs
No response
Anything else?
https://anilist.github.io/ApiV2-GraphQL-Docs/
Let me know if there's anything else I can add to help!
The text was updated successfully, but these errors were encountered: