apollo-client: Updating 3.4.17 -> 3.5.5 causing weird behaviour with tests
Intended outcome:
- Update the package
Actual outcome:
- Tests started to fail with the following error:
Invariant Violation: client.watchQuery cannot be called with fetchPolicy set to "standby"
I narrowed it down to my components that are doing somethign like useQuery(query, {skip: whatever})
. If I hardcode skip to true, the invariant violation will pop up consistently, if I hardcode it to false, it goes away đ
I also tried changing my approach to use useLazyQuery
instead of doing a skip approach, however with useLazyQuery
I get the invariant violation consistently đ˘
Iâm not explicitly using a fetch policy anywhere, just sticking to the default, so I have no idea why it would be complaining about a fetchPolicy thats set to âstandbyâ.
This also happens when trying to update to version 3.5.0 instead of 3.5.5.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 3
- Comments: 15 (3 by maintainers)
Commits related to this issue
- Downgrade @apollo/client ref: https://github.com/apollographql/apollo-client/issues/9122 — committed to syuchan1005/BookReader by syuchan1005 3 years ago
@dovalist It looks like youâre still using the
apollo-client
package (AC2). All AC3 versions of Apollo Client (3.0.0-3.5.5) are published to npm under the name@apollo/client
, just in case thatâs useful to know. Given the version range identified by @meeoh (updating 3.4.17 to 3.5.5), I donât think AC2 issues belong in this issue.Invariant Violation: client.watchQuery cannot be called with fetchPolicy set to âstandbyâ at new InvariantError (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/apollo-client/node_modules/ts-invariant/lib/invariant.js:16:28) at invariant (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/apollo-client/node_modules/ts-invariant/lib/invariant.js:28:15) at QueryManager.watchQuery (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/apollo-client/bundle.umd.js:1692:143) at ApolloClient.watchQuery (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/apollo-client/bundle.umd.js:2572:32) at /Users/rms/WebstormProjects/dovalist/hotels/node_modules/@apollo/client/react/hooks/hooks.cjs:35:31 at useReducer (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/react-dom/cjs/react-dom-server.node.development.js:1194:57) at Object.useState (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/react-dom/cjs/react-dom-server.node.development.js:1132:10) at Object.useState (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/react/cjs/react.development.js:1497:21) at useQuery (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/@apollo/client/react/hooks/hooks.cjs:28:20) at useLazyQuery (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/@apollo/client/react/hooks/hooks.cjs:265:18) at HotelListing (webpack-internal:///./pages/listing/index.jsx:110:75) at processChild (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/react-dom/cjs/react-dom-server.node.development.js:3043:14) at resolve (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/react-dom/cjs/react-dom-server.node.development.js:2960:5) at ReactDOMServerRenderer.render (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/react-dom/cjs/react-dom-server.node.development.js:3435:22) at ReactDOMServerRenderer.read (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/react-dom/cjs/react-dom-server.node.development.js:3373:29) at renderToString (/Users/rms/WebstormProjects/dovalist/hotels/node_modules/react-dom/cjs/react-dom-server.node.development.js:3988:27) { framesToPop: 1 }
Same here, it works as long has skip value is falsy. Reverted to 3.4.17 and I donât have the error anymore
Yeah it definitely looks like the underlying client is the issue here! It looks like https://github.com/Shopify/quilt/tree/main/packages/graphql-testing is the culprit here, as its importing
apollo-client
. Guess Iâll look into getting that updated to support the latest versions of apollo!I got the same issue after I upgrade apollo-client to @apollo/client@^3.5.10. And I narrow down the code to find it is related to the
skip
in my case. Ifskip = true
I will see this error.Sorry for the late response @brainkim, heres my stack trace:
I am using https://github.com/Shopify/quilt/tree/main/packages/react-testing which seems like it would be the source of the issue, but since other people are experiencing it im curious if theres some overlap somewhere