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

Apollo Client 3.7.1 useLazyQuery throws out an error Federated Wrapper Error TypeError: Cannot read properties of undefined (reading 'shift') #10292

Open yjyongz opened 1 year ago

yjyongz commented 1 year ago

Intended outcome: when we use apollo client 3.5.10, the lazyQuery works fine and our component can render properly, but when we upgrade apollo client to 3.7.1 , it broke the lazy query.

Actual outcome: we are running micro apps using the federation model and one of our micro apps throw out an error when we call callback func from a lazy query.

Federated Wrapper Error TypeError: Cannot read properties of undefined (reading 'shift') at Object.complete (Concast.js?b779:43:1) at Concast.removeObserver (Concast.js?b779:114:1) at ObservableQuery.reobserve (ObservableQuery.js?70b0:431:1) at InternalState.useOptions (useQuery.js?80b9:138:1) at InternalState.useQuery (useQuery.js?80b9:72:1) at Module.useLazyQuery (useLazyQuery.js?a57d:20:1) at Ma (3812.ad3a9c28c566bf50e9e2.js:1:59293) at 6783.e4037127a108b46b6a9e.js:1:2669 at I (6783.e4037127a108b46b6a9e.js:1:3250) at renderWithHooks (react-dom.development.js?61bb:14985:1)

How to reproduce the issue:

Versions Shell: $ npx envinfo@latest --preset apollo --clipboard npx: installed 1 in 2.015s

System: OS: macOS 12.6 Binaries: Node: 14.19.3 - ~/.nvm/versions/node/v14.19.3/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 6.14.17 - ~/shell/node_modules/.bin/npm Browsers: Chrome: 107.0.5304.110 Edge: 107.0.1418.42 Safari: 16.0 npmPackages: @apollo/client: ^3.7.1 => 3.7.1 mock-apollo-client: ^1.2.0 => 1.2.

Micro apps: npx: installed 1 in 1.767s

System: OS: macOS 12.6 Binaries: Node: 14.19.3 - ~/.nvm/versions/node/v14.19.3/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 6.14.17 - ~/.nvm/versions/node/v14.19.3/bin/npm Browsers: Chrome: 107.0.5304.110 Edge: 107.0.1418.42 Safari: 16.0 npmPackages: @apollo/client: ^3.7.1 => 3.7.1

jerelmiller commented 1 year ago

Hey @yjyongz! Thanks for opening the issue. Would you be able to get us a reproduction? That would greatly help us narrow down the issue. You can use our prebuilt error template to make this a bit easier to recreate. Thanks!

yjyongz commented 1 year ago

we use a lot of @client and @export in the query. i guess it's something related to that; the rest of the query works fine in our production code.

yjyongz commented 1 year ago

Apollo Client 3.6.7 works fine, but 3.6.8 is broken

VasiliKubarka commented 1 year ago

the same for 3.6.9

throws this error for me when both @client and @export directives are used for same field

query Test($hello: ID) {
  someField @client @export(as: "hello")
}

for initial load works well, but on navigation back to screen this error thrown, hard to determine what exactly caused this issue and exact scenario of reproduction

jerelmiller commented 1 year ago

@yjyongz @VasiliKubarka would either of you be willing to share a code sample of how you're using the query and when it breaks? Are you seeing the error when you try and execute the query via useLazyQuery, or are you seeing this simply by passing a query with those directives? Any additional information that could help us would be super helpful 🙏

mccraveiro commented 1 year ago

@jerelmiller it might be related to this: https://github.com/apollographql/apollo-client/pull/10362