-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating a local cache mutation with an optional field fails with a ApolloAPI.JSONDecodingError.missingValue
error
#2697
Comments
Hi @amseddi, thanks for creating this issue and for the sample test. We'll take a deeper look and get back to you. |
Interesting! I have a feeling that this has to do with the execution layer expecting @amseddi in your actual code that revealed this issue, are you explicitly setting a field to |
If I omit the value from the cache setup I get an error on the cache loading. The following unit test fails if I don't add a func test_readQuery_givenQueryDataWithVariableInCache_readsQuery() throws {
// given
enum Episode: String, EnumType {
case JEDI
}
class HeroNameSelectionSet: MockSelectionSet {
override class var __selections: [Selection] { [
.field("hero", Hero.self, arguments: ["episode": .variable("episode")])
]}
class Hero: MockSelectionSet {
override class var __selections: [Selection] {[
.field("__typename", String.self),
.field("name", String.self),
.field("nickname", String?.self),
]}
}
}
let query = MockQuery<HeroNameSelectionSet>()
query.__variables = ["episode": Episode.JEDI]
mergeRecordsIntoCache([
"QUERY_ROOT": ["hero(episode:JEDI)": CacheReference("hero(episode:JEDI)")],
"hero(episode:JEDI)": ["__typename": "Droid", "name": "R2-D2"]
// The next line makes this test succeed
// "hero(episode:JEDI)": ["__typename": "Droid", "name": "R2-D2", "nickname": NSNull()]
])
// when
runActivity("read query") { _ in
let readCompletedExpectation = expectation(description: "Read completed")
store.withinReadTransaction({ transaction in
let data = try transaction.read(query: query)
// then
expect(data.hero?.__typename).to(equal("Droid"))
expect(data.hero?.name).to(equal("R2-D2"))
expect(data.hero?.nickname).to(beNil())
}, completion: { result in
defer { readCompletedExpectation.fulfill() }
/// test_readQuery_givenQueryDataWithVariableInCache_readsQuery(): failed - Expected success, but result was an error: GraphQLExecutionError(path: hero.nickname, underlying: ApolloAPI.JSONDecodingError.missingValue)
XCTAssertSuccessResult(result)
})
self.wait(for: [readCompletedExpectation], timeout: Self.defaultWaitTimeout)
}
} |
Odd that definitely seems like a bug then, thank you for looking into it! We'll look deeper here. |
Bug report
Updating a local cache mutation with an optional field fails with a
ApolloAPI.JSONDecodingError.missingValue
error.Versions
apollo-ios
SDK version: 1.0.5Steps to reproduce
I created a failing unit test here amseddi@a4e1190.
ReadWriteFromStoreTests.swift
The text was updated successfully, but these errors were encountered: