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
executing a LocalCacheMutation with an enum field causes the the ReadWriteTransaction to fail with an:
Invalid type in JSON write for SQLiteNormalizedCache
ApolloAPI.JSONDecodingError.couldNotConvert(value: AnyHashable(ApolloAPI.GraphQLEnum<SomeEnum>.case(someCase)), to: Swift.String)) for InMemoryNormalizedCache
The issue seems to spawn from the fact that on cache read, the enum gets created via it's rawValue accurately, but on write, in the case of the SQLiteNormalizedCache the JSONSerialization fails to serialize the data, as it receives an Enum type to serialize instead of the raw value of the corresponding enum case.
Adding an extra case to the SQLiteSerialization.serialize(fieldValue:) seems to fix this issue for the SQLiteNormalizedCache:
privatestaticfunc serialize(fieldValue:Record.Value)throws->Any{
switch fieldValue{...
case letvalue as JSONEncodable:return value._jsonValue
default:
...}}
But I'm not too sure the consequences of this particular change, and it also doesn't fix it for the inMemoryCache either.
Version
apollo-ios SDK version: 1.0.5
Steps to reproduce the behavior
I created a failing unit test in the ReadWriteFromStoreTests as follows:
For simplicity, I did a noop in the actual ReadWriteTransaction so as to make the issue in question clearer
func test_updateCacheMutation_enumFields_identityUpdates()throws{// givenstructGivenSelectionSet:MockMutableRootSelectionSet{publicvar__data:DataDict=DataDict([:], variables:nil)init(data:DataDict){ __data = data }staticvar__selections:[Selection]{[.field("hero",Hero.self)]}varhero:Hero{get{__data["hero"]}set{__data["hero"]= newValue }}enumHeroType:String,EnumType{case droid
}structHero:MockMutableRootSelectionSet{publicvar__data:DataDict=DataDict([:], variables:nil)init(data:DataDict){ __data = data }staticvar__selections:[Selection]{[.field("type", GraphQLEnum<HeroType>.self)]}vartype:GraphQLEnum<HeroType>{get{__data["type"]}set{__data["type"]= newValue }}}}letcacheMutation=MockLocalCacheMutation<GivenSelectionSet>()mergeRecordsIntoCache(["QUERY_ROOT":["hero":CacheReference("QUERY_ROOT.hero")],"QUERY_ROOT.hero":["__typename":"Droid","type":"droid"]])runActivity("update mutation"){ _ inletupdateCompletedExpectation=expectation(description:"Update completed")
store.withinReadWriteTransaction({ transaction intry transaction.update(cacheMutation){ data in// noop}}, completion:{ result indefer{ updateCompletedExpectation.fulfill()}XCTAssertSuccessResult(result)})self.wait(for:[updateCompletedExpectation], timeout:Self.defaultWaitTimeout)}letquery=MockQuery<GivenSelectionSet>()loadFromStore(operation: query){ result intryXCTAssertSuccessResult(result){ graphQLResult inXCTAssertEqual(graphQLResult.source,.cache)XCTAssertNil(graphQLResult.errors)letdata=tryXCTUnwrap(graphQLResult.data)XCTAssertEqual(data.hero.type,.case(.droid))}}}
The text was updated successfully, but these errors were encountered:
Summary
executing a LocalCacheMutation with an enum field causes the the
ReadWriteTransaction
to fail with an:Invalid type in JSON write
forSQLiteNormalizedCache
ApolloAPI.JSONDecodingError.couldNotConvert(value: AnyHashable(ApolloAPI.GraphQLEnum<SomeEnum>.case(someCase)), to: Swift.String))
forInMemoryNormalizedCache
The issue seems to spawn from the fact that on cache read, the enum gets created via it's
rawValue
accurately, but on write, in the case of theSQLiteNormalizedCache
theJSONSerialization
fails to serialize the data, as it receives anEnum
type to serialize instead of the raw value of the corresponding enum case.Adding an extra case to the
SQLiteSerialization.serialize(fieldValue:)
seems to fix this issue for theSQLiteNormalizedCache
:But I'm not too sure the consequences of this particular change, and it also doesn't fix it for the inMemoryCache either.
Version
apollo-ios SDK version: 1.0.5
Steps to reproduce the behavior
I created a failing unit test in the
ReadWriteFromStoreTests
as follows:For simplicity, I did a
noop
in the actualReadWriteTransaction
so as to make the issue in question clearerThe text was updated successfully, but these errors were encountered: