-
Notifications
You must be signed in to change notification settings - Fork 164
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
skipToken support for typescript-react-apollo #647
Comments
The fix is pretty easy to do: Before: export function useFeedSuspenseQueryMySuffix(baseOptions?: Apollo.SuspenseQueryHookOptions<FeedQuery, FeedQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useSuspenseQuery<FeedQuery, FeedQueryVariables>(FeedDocument, options);
}`); After: export function useFeedSuspenseQueryMySuffix(baseOptions?: Apollo.SkipToken | Apollo.SuspenseQueryHookOptions<FeedQuery, FeedQueryVariables>) {
const options = (baseOptions === Apollo.skipToken) ? baseOptions : { ...defaultOptions, ...baseOptions }
return Apollo.useSuspenseQuery<FeedQuery, FeedQueryVariables>(FeedDocument, options);
}`); Just need to add Apollo.SkipToken the type on the baseOptions and change a little bit how options is defined. I already do a commit on a fork: Do you want I create a PR? |
@vbornand I attempted something similar but it gives incorrect types for when you don't supply eg:
|
The To minimize the amount of generated code, I managed to make it function correctly by merely supporting the I am still considering how to best integrate this feature. Just like I can submit a PR for this, but I need opinions on the creation of an additional file. ps. At this point, it seems much better to just use |
skip
as an option for suspense hooks is going to be deprecated in favour of a newskipToken
technique in an upcoming version of Apollo, as it provides more type safety.Apollo docs on
skip
:More reading:
You can work around this at the moment by using
useSuspenseQuery
directly from@apollo/client
and using the document and types generated bygraphql-code-generator
, eg:Describe the solution you'd like
It would great if the generated suspense hook had native support for this (which aligns with what their docs recommend), eg:
The text was updated successfully, but these errors were encountered: