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.

Can't find field <field> on object (ROOT_QUERY) undefined.

See original GitHub issue

I’m using ReactNative, and am able to load a user object from my graphql server using

graphql(gql`{
    user(id: 1) {
        first_name
    }
}`)(DisplayComponent)

Therefore, I would expect this user to be in the cache. However, when I write the following code in the constructor of a different component:

apolloClient.readQuery({query: gql`
    query Test {
        user(id: 1) {
            first_name
        }
    }
`})

I get the following error: Can't find field user({"id":1}) on object (ROOT_QUERY) undefined.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:32
  • Comments:42 (6 by maintainers)

github_iconTop GitHub Comments

142reactions
TdyPcommented, Aug 29, 2018

For what it’s worth, I ran into the same issue and found out that I forgot the variables when calling readQuery:

const updateFunc = (cache, {data: {saveLibrary}}) => {
    const {libraries} = cache.readQuery({query: libQuery, variables: {id: saveLibrary.id}});
};

Maybe it can help someone 😃

98reactions
helfercommented, Jun 1, 2017

Closing this for lack of activity. If it’s still an issue, please provide a reproduction and we’ll reopen. Thanks! 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

react apollo - readQuery from cache results in Can't find field ...
I'm doing some simple queries and mutations fine but when I try to access data from apollo cache I keep getting "Can't find...
Read more >
Configuring the Apollo Client cache - Apollo GraphQL Docs
To learn how to interact with cached data, see Reading and writing data to the cache. ... Include a keyFields field in relevant...
Read more >
GraphQL specification
When querying an Object, the resulting mapping of fields are conceptually ordered in the same order in which they were encountered during query...
Read more >
ObjectType - Graphene-Python
ObjectType¶. A Graphene ObjectType is the building block used to define the relationship between Fields in your Schema and how their data is...
Read more >
GraphQL Content API - Contentful
Collection fields. Collections of entries and assets are exposed through collection fields in the root query object and in one-to- ...
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