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

useSuspenseQuery returns an error instead of throwing an exception #11800

Open
tarasmatsyk opened this issue Apr 22, 2024 · 1 comment
Open

Comments

@tarasmatsyk
Copy link

tarasmatsyk commented Apr 22, 2024

Issue Description

I am using a suspense query and an error boundary to catch all unhandled errors. An example of usage:

  // this component is wrapped in ErrorHandler and React.Suspense, error and networkStatus are just for debugging
  const {data, error, networkStatus} = useSuspenseQuery<MyType>(Query, {variables: myVariables});
  // data = null, error = "posted a few lines below", networkStatus: 8

everything works fine in 3.8.x, after update to 3.9.0+ suspense no longer throws an error and behaves more like useQuery hook without a loading property

an example of error

ApolloError: "error message coming from API"
    at new ApolloError2 (index.ts:101:10)
    at toApolloError (useSuspenseQuery.ts:322:7)
    at useSuspenseQuery.ts:275:14
    at mountMemo (react-dom.development.js:17225:19)
    at Object.useMemo (react-dom.development.js:17670:16)
    at Object.useMemo (react.development.js:1650:21)
    at useSuspenseQuery (useSuspenseQuery.ts:269:16)
    at CustomComponent
    at renderWithHooks (react-dom.development.js:16305:18)
    at mountIndeterminateComponent (react-dom.development.js:20074:13)

perhaps react-dom is involved somehow, I have a limited understanding of what happens here and cannot reproduce the issue if I pass my GQL response into unit tests apollo-client has (or I am bad at it)

server response example

{
   "data": null,
   "errors": [
       {
           "message": "error message coming from API",
           "locations": [
               {
                   "line": 2,
                   "column": 3
               }
           ], // no idea where this comes from
           "path": [
               "items"
           ],
           "extensions": {
               "code": 4,
               "exception": null
           }
       }
   ]
}

Unfortunately, I don't have more details at the moment. I am leaving this issue in case someone else faces similar behavior and I am able to get a reproducible sample

Link to Reproduction

N/A

Reproduction Steps

also discussed here:
#11664

@apollo/client version

3.9.0

@jerelmiller
Copy link
Member

Thanks so much 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants