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.

Optimistic option on ApolloClient.readQuery

See original GitHub issue

Pre 2.0 I believe that client.readQuery would also return optimistic mutation results. After upgrading to 2.0 most of my optimistic code broke since I use it in tandem with subscriptions. In the subscription (for a new message) I would read the store and check if an optimistic result was there (designated by a negative ID) and not do anything with the subscription if that were the case. Now that doesn’t work anymore. I did some digging and saw that the apollo-cache package now has an optimistic: boolean param in the readQuery function which would solve my issues but it doesn’t seem to be accessible to the apollo-client package. Is this intentional or just a missing API that needs to be written?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lfadescommented, Nov 3, 2017

it’s the same as the result of this.initProxy() so yes, you’ll need to pass true as the second prop to query in the optimistic results too

0reactions
hwillsoncommented, Aug 10, 2018

https://github.com/apollographql/apollo-client/pull/2429 addresses this and was merged. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimistic mutation results - Apollo GraphQL Docs
To enable this optimistic UI behavior, we provide an optimisticResponse option to the mutate function that we use to execute our mutation.
Read more >
Apollo Cache – Angular - GraphQL Code Generator
Then, you can pass in your newly created cache to ApolloClient. ... you can use the Apollo Client class methods readQuery, readFragment, ...
Read more >
Optimistic UIs with React, Apollo Client and TypeScript (Part III)
Whenever the mutate function is called, the Apollo Client checks if an optimisticResponse option is provided for the mutation. If so, then the ......
Read more >
optimisticResponse vs update in Apollo Client? - Stack Overflow
As per the docs, if you are updating an existing item, say editing a title of a todo item, you only need optimisticResponse...
Read more >
Reason Apollo Cache Update Patterns - peterpme
Updating the cache using an optimistic response reduces the amount of… ... ReadQuery(GetAssets); module AssetWriteQuery = ApolloClient.WriteQuery(GetAssets) ...
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