Intended outcome:
Sufficient diagnostic information on why React components all of a sudden receive empty data object in case when there is a problem with data in cache (for example, missing fields).
Actual outcome:
No errors whatsoever. I had to spend hours digging through apollo-client source code to finally find this one and put a console.log(e) there to figure out the actual reason:
How to reproduce the issue:
Schema:
type Query {
a(id: String!): A!
}
type A {
id: String!
b: B!
a: A!
}
type B {
id: String!
c: C!
}
type C {
id: String!
}
Query:
query q($id: Int) {
a(id: $id) {
id
b {
id
}
a {
id
b {
id
c {
id
}
}
}
}
}
Fragment for writeFragment:
fragment update on A {
id
b {
id
}
}
writeFragment call:
apolloClient.writeFragment({
fragment: gql`
fragment update on A {
__typename
id
b {
__typename
id
}
}
`,
id: "a2",
data: {
__typename: "A",
id: "a2",
b: {
__typename: "B",
id: "b3"
}
}
});
Initial data in the cache:
{
a: {
id: "a1",
b: {
id: "b1"
},
a: {
id: "a2",
b: {
id: "b2",
c: {
id: "c1"
}
}
}
}
}
Cache after writeFragment:
{
a: {
id: "a1",
b: {
id: "b1"
},
a: {
id: "a2",
b: {
id: "b3"
}
}
}
};
The query has c field inside the nested b, but the updated cache does not. Which makes the query fail.
Version
Thank you for the clear description of this issue.
Although the line you point does throw an error, it doesn't seem to be the place where an error should actually "float up." It seems that the result for the "c" field is partially fulfilled and it seems Apollo Client should throw an error in this case when an incomplete result for the initial query. Is this a correct interpretation of the issue?
@Poincare yes, I would pretty much appreciate that!
Would it be possible for you to add a failing unit test for this particular case (i.e. verifying no error is thrown in the case you have described)?
@Poincare Nope, sorry, already spent too much time on this.
Thanks for reporting this. There hasn't been any activity here in quite some time, so we'll close this issue for now. If this is still a problem (using a modern version of Apollo Client), please let us know. Thanks!
Most helpful comment
@Poincare Nope, sorry, already spent too much time on this.