Skip to content

feat(openapi-react-query): Add the ability to bring queryClient as argument #1814

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

Merged
merged 9 commits into from
Aug 7, 2024

Conversation

yoshi2no
Copy link
Contributor

@yoshi2no yoshi2no commented Aug 4, 2024

ref: #1805

Changes

Added the ability to pass queryClient as an argument in the openapi-react-query.
This enhancement allows users to directly pass queryClient to the useQuery, useMutation, useSuspenseQuery hooks.

The sample code in the issue is as follows:

const query = $api.useQuery('get', '/api/posts', {}, queryClient);

In my understanding, $api.useQuery currently accepts method, path, options, and queryOptions, and with the addition of queryClient, the correct format should be:

const query = $api.useQuery('get', '/api/posts', {}, {}, queryClient);

If I am mistaken in my understanding, please let me know. Your feedback would be greatly appreciated.

How to Review

I don’t think it is necessary to add tests for this change, but what do you think?

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

@yoshi2no yoshi2no requested a review from a team as a code owner August 4, 2024 09:34
Copy link

changeset-bot bot commented Aug 4, 2024

🦋 Changeset detected

Latest commit: a678749

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-react-query Minor

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

@kerwanp
Copy link
Contributor

kerwanp commented Aug 5, 2024

Hey! That looks really great, thanks a lot for your contrib!
Could you write some unit tests to ensure that we properly use the provided queryClient?

Then it will only needs the changesets and it will be ready to merge!

@yoshi2no
Copy link
Contributor Author

yoshi2no commented Aug 6, 2024

Thank you for the review!

  • Added test cases
    • The tests ensure that everything works correctly without using the QueryClientProvider. This is based on the approach used in react-query.
  • Added a minor changeset

Copy link
Contributor

@kerwanp kerwanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Really nice idea to check for react-query actual tests for that.

One more thing left, add yourself to the contributors list in docs/scripts/update-contributors.js

@kerwanp kerwanp merged commit 2a044d0 into openapi-ts:main Aug 7, 2024
7 checks passed
@github-actions github-actions bot mentioned this pull request Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants