question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Silent breaking of queries after writeFragment

See original GitHub issue

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:

https://github.com/apollographql/apollo-client/blob/master/packages/apollo-client/src/core/QueryManager.ts#L978

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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
haizzcommented, Feb 22, 2018

@Poincare Nope, sorry, already spent too much time on this.

0reactions
jbaxleyiiicommented, Jul 9, 2019

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found