-
Notifications
You must be signed in to change notification settings - Fork 161
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
feat(react-query): support react query v5 #434
feat(react-query): support react query v5 #434
Conversation
🦋 Changeset detectedLatest commit: 753e929 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There's one issue I'm noticing with custom options. It's currently generating code that looks like this: export const useFooQuery = <
TData = FooQuery,
TError = Error
>(
variables: FooQueryVariables,
options?: UseQueryOptions<FooQuery, TError, TData>
) =>
useQuery<FooQuery, TError, TData>(
{
queryKey: ['Foo', variables],
queryFn: gqlFetcher<FooQuery, FooQueryVariables>(FooDocument, variables),
...options
}
); If you try to use it though, it throws a TS error: useFooQuery({id: 1}, {enabled: false})
// Property 'queryKey' is missing in type '{ enabled: boolean; }' but required in type 'UseQueryOptions<FooQuery, Error, FooQuery, QueryKey>' The issue is that the options?: Omit<UseQueryOptions<FooQuery, TError, TData>, 'queryKey' | 'queryFn'> then it should work fine |
Wondering if it would make sense to include with this MR, or if it should be added to a future one: v5 adds support for suspense queries. Currently we have a flag for So if both
|
Yeah you would need those with v5 because the suspense:boolean flag was removed |
@rliljest Thx for cathing the bug, the update should fix the issue!
FYI, the first generic |
@neil585456525 Tried this latest version, and it does work without errors when targeting react-query v5! Just noticed one issue that has not been brought up: When using react-query v4, there is a breaking change in the generated infinite queries when UPDATE: It looks like at least part of the issue is that I was on version 4 of |
@rliljest let me check the v4 compatibility, thx. It should be no break change for current usage. |
Hi @rliljest, after the research I found that the |
Hi @saihaj , we have already done the discussion and modifications. Please review our pr to see if we miss anything for the release 🙏 |
thank you so much everyone! |
Happy to file an issue if this is indeed a problem, but I had been using Either way thank you so much for this work to support the new react-query! |
@TkDodo @neil585456525 is this promblem resolved? after updateing is there any solution for this? my codegen config is like below. import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
documents: 'src/graphql/query/**/*.graphql',
generates: {
'src/graphql/generated/index.ts': {
config: {
addInfiniteQuery: true,
avoidOptionals: true,
exposeQueryKeys: true,
fetcher: 'apis/GraphQLApi#fetcher',
legacyMode: false,
reactQueryVersion: 5,
skipTypename: true,
},
plugins: ['typescript', 'typescript-operations', 'typescript-react-query'],
},
},
hooks: {
afterOneFileWrite: ['prettier --write'],
},
overwrite: true,
schema: 'src/graphql/schema.ts',
};
export default config; |
I have the exact same issue, v6 seems to break the preset |
Hi, I also have an issue with infinite query. I tried upgrading to the last version. I think this type is wrong
Is it the good type for TData @TkDodo @neil585456525 ?
because with the version 6.0.0 all my infinite queries types in typescript does not match what is really returned. I have a strange typescript error on what I should have on my result data. I should have an array
but what I really have is not an array
This type is used for the result and it already use InfiniteData. So I thinks it should not be in the useInfiniteQuery type params
Thanks for your help! |
@neil585456525 do you want that I create a new issue? |
@groomain It will be great thx! |
We've had to downgrade back because our outputted code is missing the Thank you for your hard work on this and let us know if you need any more info to help investigate! |
Done @neil585456525 |
@lafest did you find a solution to your issue? I had the same thing pop up. Opened an issue here #583 |
It would be great if someone could update the docs to mention that this does plugin support RQ5 🚀 Took me more than a little while to discover this PR and the new option being added to get it working. |
hey @South-Paw do you want to send in a PR? |
I did make a start on writing some new docs - but quickly realized there was a fair bit more that needed changing/updating than simply stating it supports RQ5. A fair bit of that page is out of sync with the package IMO. Unfortunately I think someone who's a bit more familiar with the package would be best placed to start on it too. I'm not well placed at this time to take on that task right now (time and familiarity wise). |
…ableQuery Implement `useBackgroundQuery` and `useLoadableQuery` hooks for React Apollo. These APIs are added in 3.8.0 and 3.9.0 respectively. Suspense support in Apollo Client provides 5 new hooks as described in https://www.apollographql.com/docs/react/data/suspense/. `useSuspenseQuery` support was added in dotansimha#434. Among other 4 hooks, `useBackgroundQuery` and `useLoadableQuery` are the ones that take a GraphQL document as an argument like other existing hooks. The support for these hooks are added in this change. Other hooks, `useQueryRefHanders` and `useReadQuery` do not take a GraphQL document as an argument, so they do not need to be added as the generated code. Both take the return values of other hooks as an argument, and the types are inferred from it.
…ableQuery Implement `useBackgroundQuery` and `useLoadableQuery` hooks for React Apollo. These APIs are added in 3.8.0 and 3.9.0 respectively. Suspense support in Apollo Client provides 5 new hooks as described in https://www.apollographql.com/docs/react/data/suspense/. `useSuspenseQuery` support was added in dotansimha#434. Among other 4 hooks, `useBackgroundQuery` and `useLoadableQuery` are the ones that take a GraphQL document as an argument like other existing hooks. The support for these hooks are added in this change. Other hooks, `useQueryRefHanders` and `useReadQuery` do not take a GraphQL document as an argument, so they do not need to be added as the generated code. Both take the return values of other hooks as an argument, and the types are inferred from it. Follow up to dotansimha#388. Fixes dotansimha#477.
Description
Let TypeScript React-Query plugin support V5 payload syntax.
Related #318
Type of change
Please delete options that are not relevant.
expected)
How Has This Been Tested?
reactQueryVersion
to 5 in config.Checklist:
CONTRIBUTING doc and the
style guidelines of this project