apollo-client: skip option fails when assigned a variable that flips from false to true
Intended outcome:
skip: true
results in no network request.
The error
property in the result of the useQuery hook reflects the current running query.
Actual outcome:
skip: true
results in a network request.
The error
property displays for the previous result.
How to reproduce the issue:
- Go here: https://codesandbox.io/s/apolloclient-v3-skip-bug-ov1z3?file=/src/app.js
- Click the button and observe the
400
from the graphql endpoint. - Click the button again and observe the successful response but the logged error message.
Related Issues https://github.com/apollographql/apollo-client/issues/6190 https://github.com/apollographql/apollo-client/issues/6572 https://github.com/apollographql/apollo-client/issues/6507
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 19 (2 by maintainers)
Commits related to this issue
- Avoid making network requests when skip is true When skip is set to true but other updated options have been passed into `useQuery` (like updated variables), `useQuery` will still make a network requ... — committed to apollographql/apollo-client by hwillson 4 years ago
- Avoid making network requests when skip is true When skip is set to true but other updated options have been passed into `useQuery` (like updated variables), `useQuery` will still make a network requ... — committed to apollographql/apollo-client by hwillson 4 years ago
- Avoid making network requests when skip is true When skip is set to true but other updated options have been passed into `useQuery` (like updated variables), `useQuery` will still make a network requ... — committed to apollographql/apollo-client by hwillson 4 years ago
- Avoid making network requests when skip is true When skip is set to true but other updated options have been passed into `useQuery` (like updated variables), `useQuery` will still make a network requ... — committed to apollographql/apollo-client by hwillson 4 years ago
- Avoid making network requests when skip is true When skip is set to true but other updated options have been passed into `useQuery` (like updated variables), `useQuery` will still make a network requ... — committed to apollographql/apollo-client by hwillson 4 years ago
We’re finalizing a fix for this and other
skip
related issues, and should have it ready today.i’m surprised the major release (out of beta) was done with this still broken (since it was a known thing not a bug that popped after release)… it’s a pretty widely used feature and I was a little shocked after I migrated to find the console error and this thread … would of been nice if it was a known thing to make mention of it in the release/migration guide … maybe its just me though?
https://github.com/apollographql/apollo-client/issues/6603 https://github.com/apollographql/apollo-client/issues/6644 https://github.com/apollographql/apollo-client/issues/6636 (fixed in upcoming 3.1.0.)
@hwillson I’ll give it a check after my morning meetings. Can you give me about two hours? If you publish pre’s to npm you could also check the sandbox quickly, I believe.
Edit: Looks like you guys do, and looks like it did fix the issue in the sandbox. As discussed on the PR, data is being returned now when
skip: true
, but at least no network request is made.Funnily enough we migrated back to beta-43. It’s more stable as of the moment of writing
@benjamn I’d like to learn more about the inner-workings of ApolloClient, and would be happy to try and fix this but I’m not sure what I’m looking for. I know the options are differing here, with
skip: true
being in the new options:https://github.com/apollographql/apollo-client/blob/7993a778ef5a9e61bfee72b956f4c179fce691f4/src/react/data/QueryData.ts#L241-L255
which calls to update the “current observable” on the query data class. I’m guessing that for some reason the thing that makes fetch/no-fetch decisions is not aware of this update.