Silent breaking of queries after writeFragment
See original GitHub issueIntended 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
- apollo-client@2.0.3
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Reading and writing data to the cache - Apollo GraphQL Docs
You can read and write cache data using GraphQL queries that are similar (or even identical) to queries that you execute on your...
Read more >@apollo/client | Yarn - Package Manager
Fixed bug where the useLazyQuery execution function would always use the refetch method of ObservableQuery , instead of properly reapplying the current ...
Read more >@apollo/client - Awesome JS
Fix issue where loading remains true after observer.refetch is called repeatedly with different variables when the same data are returned. @alessbell in #10143....
Read more >Configuring Rails Applications - Ruby on Rails Guides
After reading this guide, you will know: How to adjust the behavior of your ... This will break because autoloading during initialization cannot...
Read more >OS-COMMAND statement - Progress Documentation
Syntax OS-COMMAND [ SILENT | NO-WAIT | NO-CONSOLE ] [ command-token | VALUE ( expression ) ] ... SILENT After processing an operating...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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!