apollographql / react-apollo

:recycle: React integration for Apollo Client
https://www.apollographql.com/docs/react/
MIT License
6.85k stars 790 forks source link

FetchPolicy 'network-only' and 'no-cache' return cached value in Apollo Client v3 #4020

Closed thojanssens closed 4 years ago

thojanssens commented 4 years ago

When I run multiple times a query with a fetchPolicy set to 'network-only' or 'no-cache', it will execute only 1 server request.

client.query({
  fetchPolicy: 'network-only',
  query: gql`
    query {
      me {
        id
      }
    }`
}) .then(result => console.log(result))

When I execute this 3 times, I will see only 1 call to the network in Chrome's Network Tab, my server logs only 1 time, but 3 logs in the client's console.

I checked the request and response HTTP headers to see if there is some incompatibility, but I don't see anything suspicious. Request headers include:

Cache-Control: no-cache Pragma: no-cache

Response headers include:

cache-control: max-age=0, private, must-revalidate

The status code is 200 OK

Any idea?

thojanssens commented 4 years ago

Sorry, I'm new to Apollo and didn't see the apollo-client repo which seems more suited for this issue.

https://github.com/apollographql/apollo-client/issues/6432