urql
urql copied to clipboard
feat(vue): refactor composable functions
Summary
This includes https://github.com/urql-graphql/urql/pull/3612, but fixed reactivity loosing here.
In addition, a little refactoring for use* composable functions for reducing code duplication and adding more test cases.
Set of changes
- Remove wrapping args in reactive in useQuery.ts and useSubscription.ts
- Add
createRequestWithArgs(),useClientState()anduseRequestState()utils to avoid code duplication. - Refactor
useQuery(),useSubscription()anduseMutation()to use shared utils mentioned above. - Add
isReadonly()check before changingisPausedvariable, as it could be readonly. - ~~Remove
onBeforeUnmountand unwatch handlers, as watcher automatically stopped when the owner component is unmounted~~ - Remove
flush: 'pre'in watcher options, as this is default setting - Rename
unref()tounwrap()to avoid confusions with vue function - Reuse
then()handler foruseQuery()for cleaner code and avoid duplications - Cover of reactive arguments usage with test cases
🦋 Changeset detected
Latest commit: 01c39229c4a38e6f42836df5e29c96c4f40726af
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @urql/vue | 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
This is a really good refactoring. The only thing that bothers me is why the effects in useClientHandle() were initially manually stopped; I couldn’t find the reason (or I didn’t look well).
Thanks @negezor ☀️
why the effects in
useClientHandle()were initially manually stopped
The reason of having useClientHandle() and manually stopping watchers I found is here https://github.com/urql-graphql/urql/pull/3610#issuecomment-2178843530. And the reason it was removed in current PR - I consider this as excessive concern for rare use cases and attempt to bypass vue limitations, which should be completely on users responsibility imho.
But I can agree this kind of removal is overkill for mine "little refactoring", so I'll revert this functionality here. I guess we can found an optimal solution in scope of that PR.
@kitten could you please review the PR?
@kitten gentle ping 👀
@yurks I deployed these changes to production, found one problem. Uploading files does not work in mutations, it sends {} instead of File
@yurks I deployed these changes to production, found one problem. Uploading files does not work in mutations, it sends
{}instead ofFile
@negezor thanks for the review! I optimised that piece of code, and added test case for checking different types of variables.