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.

proxy.readQuery throws an error on not executed queries

See original GitHub issue

I am having a structure which looks like the following:

type Person {
  id: string
  friends: [Friend]
  addresses: [Address]
}

At one point in time I am fetching one persons addresses, which is being cached in the store while using the id field.

At a later point in time, I am doing a mutation on the object and add a new friend. Please note, that at this point in time the user did not request to fetch the list of friends for now. In order to keep the friends list up to date, I am still doing a proxy.readQuery operation on the query which is responsible for fetching all friends of a user and pushing the new friend into it. For now I don’t keep track if the user already executed this query at some point in the past. If the user did so, everything is alright. If however he did not fetch the list of friends and I am trying to execute the proxy.readQuery on that query, I will get an exception like that:

Error: Can't find field PersonFriends on object (Person:UGVyc29uOjE=) {
  "id": "UGVyc29uOjE=",
  "Viewer_addresses": {
    "type": "id",
    "id": "$Person:UGVyc29uOjE=.Viewer_addresses",
    "generated": true
  },
  "__typename": "Person"
}

I would like to prevent catching this exception. Is there any way from Apollo’s side to know if a certain query was executed in the past and don’t execute the proxy.readQuery in that case?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
janaleiblecommented, Aug 10, 2017

See also issue #2007

0reactions
stale[bot]commented, Nov 14, 2017

This issue has been automatically closed because it has not had recent activity after being marked as stale. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to Apollo Client!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading and writing data to the cache - Apollo GraphQL Docs
If the cache is missing data for any of the query's fields, readQuery returns null . It does not attempt to fetch data...
Read more >
How to safely update Apollo client cache after mutation if ...
The cache update for the "Drafts" query works as expected, because the query has already been executed and data stored in the cache....
Read more >
How to update the Apollo Client's cache after a mutation
Keep in mind that both proxy.readQuery and proxy.writeQuery may throw errors independently. As an example, you can successfully read a query ...
Read more >
apollo-cache-inmemory-fork - npm package | Snyk
The query method, on the other hand, may send a request to your server if the appropriate data is not in your cache...
Read more >
node_modules/apollo-cache-inmemory ... - Gitlab IDI - NTNU
... throw an error if the data is not in your cache. readQuery will always read from the cache. You can use readQuery...
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