Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'data' of undefined when using useLazyQuery #11251

Closed
stretch0 opened this issue Sep 26, 2023 · 3 comments
Closed

Cannot read property 'data' of undefined when using useLazyQuery #11251

stretch0 opened this issue Sep 26, 2023 · 3 comments

Comments

@stretch0
Copy link

Issue Description

When using useLazyQuery and I expect an error to be returned from the server, ApolloClient appears to crash as it can't read result.data.

image

You can see in the code, I am using SpaceX's API: https://spacex-production.up.railway.app/

I am then running a lazy query where I pass in an invalid query variable which causes the server to return an error (this works in the explorer all ok.

When I click the button to trigger my query, it casues the apollo client error to be thrown. I would expect the error from the server to be surfaced from useLazyQuery.

I am using
node 20
"@apollo/client": "^3.8.4",

Link to Reproduction

https://github.com/stretch0/apollo-client-native-sandbox

Reproduction Steps

Setup app

Using node v20

npm install
npm run android

Once app loads, click the PRESS ME button.

Note Apollo Client throws an error complaining it can't read property data of undefined.

Screen.Recording.2023-09-26.at.11.56.01.mov

I have also tested this same query using the useQuery hook and it just seems to show loading: true the whole time, rather than returning an error. I would expect an error to be returned form the useQuery hook.

Any help in understanding this issue with surfacing the correct error would be greatly appreciated. Thanks

@stretch0
Copy link
Author

stretch0 commented Sep 26, 2023

I have just rolled back to version "@apollo/client": "^3.7.17" and it seems to work as expected. This is the latest version I can get to work.

As soon as I upgrade to 3.8.0, it breaks. Must be something in this release: https://github.com/apollographql/apollo-client/releases/tag/v3.8.0

@phryneas
Copy link
Member

phryneas commented Sep 26, 2023

This is a duplicate of #11149 and will be fixed in #11249 (you can find a temporary npm release with the workaround in both PRs)

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants