-
Notifications
You must be signed in to change notification settings - Fork 181
Description
Which packages are impacted by your issue?
@graphql-codegen/typescript-react-apollo
Describe the bug
Hi,
Since #835 and after updating @graphql-codegen/typescript-react-apollo
to 4.3.2
, all of our suspense hooks now return data that are possibly 'undefined', breaking compilation:
Before:
const { data } = useGetCountriesSuspenseQuery()
// data has type GetCountriesQuery and can be accessed without issues
Now:
const { data } = useGetCountriesSuspenseQuery()
// data has type GetCountriesQuery | undefined, and needs optional chaining
I'm not sure whether or not this is a bug, or that there is an additional step necessary on my end to make typescript understand that in the above examples, we're not skipping the query using a skipToken
. Only when passing the skipToken
in the hook should the return type be possibly undefined.
Perhaps @jefrydco can shed some light on this? Is there any more configuration necessary to support the skipToken
variable in generated suspense hooks?
Cheers!
Your Example Website or App
N/A
Steps to Reproduce the Bug or Issue
Upgrade to @graphql-codegen/typescript-react-apollo v4.3.2
when using generated useSuspenseQuery hooks
Expected behavior
I expected the return type of data
for a useGetMyDataSuspenseQuery
be either GetMyData
or GetMyData | undefined
, depending on whether or not a skipToken
is present. Existing code not containing a skipToken
in the hook should have the same return types as before upgrading to @graphql-codegen/typescript-react-apollo v4.3.2
.
Screenshots or Videos
No response
Platform
- OS: Linux
- NodeJS: 18.16.0
graphql
version: 16.8.1@graphql-codegen/*
version(s):
"@graphql-codegen/add": "^3.2.1",
"@graphql-codegen/cli": "^5.0.2",
"@graphql-codegen/introspection": "^4.0.3",
"@graphql-codegen/typescript": "^4.0.6",
"@graphql-codegen/typescript-operations": "^4.2.0",
"@graphql-codegen/typescript-react-apollo": "^4.3.2",
Codegen Config File
overwrite: true
schema: ${VITE_API_URL}/graphql
documents: "src/**/*.graphql"
generates:
src/graphql/graphql.tsx:
plugins:
- add:
content: 'const defaultOptions = { onError: () => {} }'
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
config:
scalars:
DateTimeTz: 'Date'
JSON: '{ [key: string]: any }'
Percentage: 'number'
Upload: 'File'
./graphql.schema.json:
plugins:
- "introspection"
Additional context
No response