apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.33k stars 2.65k forks source link

`skip` is not working correctly with `nextFetchPolicy` #8895

Open smitpatel1010 opened 2 years ago

smitpatel1010 commented 2 years ago
const { loading, data } = useQuery(QUERY, {
  skip: conditionallySkipped,
  fetchPolicy: 'cache-and-network',
  nextFetchPolicy: 'cache-first'
});

Intended outcome: If the skip is false in useQuery then a new call should go and the cache should update with a new response.

Actual outcome: If the skip is false in useQuery then a new call is going correct but the cache is not updating with the latest response came.

How to reproduce the issue: https://codesandbox.io/s/serene-grass-qwy7b?file=/src/index.js Open this codesandbox and follow below steps.

  1. toggle skip to true
  2. add new todo
  3. toggle skip to false

then check new call is going and received new data but the cache is not updating the value with the latest response.

brainkim commented 2 years ago

I’m currently on my phone in bed (it’s 3AM), but I bet you if you remove the nextFetchPolicy: 'cache-first' line, everything works as expected? Just a hunch. I will look into it more fully in the morning. Thanks for the reproduction!

smitpatel1010 commented 2 years ago

Yes, If we remove nextFetchPolicy: 'cache-first' line then it works fine. but I want pagination with cache-and-network and because of this issue I had to add this line. and Thanks for quick reply

brainkim commented 2 years ago

@smitpatel1010 Thanks for the confirmation! I updated the title to reflect this detail; I hope you don’t mind. I’m not too sure about how nextFetchPolicy should work with the skip option, so I might need to do some rereading of the docs for that option to see what’s up. I’ll also try to follow up on the issue you linked as it seems to be causing people a lot of frustration.

smitpatel1010 commented 2 years ago

Thanks @brainkim. I will also check if I can find any workaround or any relevant info in docs