-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useQuery with cache-only does not receive data from another query of the same data #9383
Comments
Can you post both queries? Does the subscription have all the same data as the initial query? If not can you put |
Added them at the top inside a disclosure!
It does (using Fragments). See the queries
Both the initial query and the individual query already have that option set to true. |
I think the problem here is you are requesting a different query that was not requested before ( I suggest instead of using |
The reason for using
I suppose a |
I got your point, I think your workaround is the best at the moment. also, you can track this issue. it introduces an |
Had a similar issue and was able to figure out a solution thanks to this SO answer and this section in the Apollo Docs @jamesopti In your example, you'd want to provide a cache redirect like so: const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
getCat(_, { args, toReference }) {
return toReference({ __typename: 'Cat', id: args.id, orgId: args.orgId });
},
},
},
},
}); |
@jamesopti 👋 let me know if you feel this question is answered from the responses above. |
Hi @jamesopti 👋 Were the suggestions above re: |
We're closing this issue now but feel free to ping the maintainers or open a new issue if you still need support. Thank you! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Intended outcome:
I am making two queries, one for a list of cats (via the network) and one for a single cat (via cache-only). I'm also subscribing to updates to all cats:
Queries
I would expect that on initial page load and any subscription updates to cats that my singular cat query will always update based on the cache value supplied by the cats query/subscription
Actual outcome:
The singular
useQuery
is never supplied any data.How to reproduce the issue:
See code above
Workaround:
Manually updating the cache like this appears to achieve the desired outcome:
Versions
➜ client git:(main) ✗ yarn info @apollo/client
└─ @apollo/client@npm:3.5.8
├─ Instances: 1
├─ Version: 3.5.8
System:
OS: macOS 12.0.1
Binaries:
Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
Yarn: 2.4.3 - ~/.nvm/versions/node/v16.13.0/bin/yarn
npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
Browsers:
Chrome: 97.0.4692.99
Safari: 15.1
The text was updated successfully, but these errors were encountered: