-
Notifications
You must be signed in to change notification settings - Fork 471
feat(vue): refactor composable functions #3619
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
Conversation
🦋 Changeset detectedLatest commit: 01c3922 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 |
This is a really good refactoring. The only thing that bothers me is why the effects in |
Thanks @negezor ☀️
The reason of having But I can agree this kind of removal is overkill for mine "little refactoring", so I'll revert this functionality here. |
@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 |
packages/vue-urql/src/utils.ts
Outdated
@@ -26,6 +26,12 @@ const unwrap = <T>(maybeRef: MaybeRef<T>): T => | |||
? maybeRef.value | |||
: maybeRef; | |||
|
|||
const _toString = Object.prototype.toString; | |||
const isPlainObject = (obj: any): boolean => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ï think we might do better in re-using/copying our existing checks https://github.com/urql-graphql/urql/blob/main/packages/core/src/utils/variables.ts#L23-L24 for files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that checks is for Files/Blobs only. I just think this might be overkill here, as finally urql/core is used with its internal validations.
What I am trying to do here - is just unwrap possible refs and pass everything as it is. That's why I found isPlainObject()
way more generic: urql/core could be kind of "source of truth" for input validation
Resolves #3507
Resolves #3633
Summary
This includes #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
createRequestWithArgs()
,useClientState()
anduseRequestState()
utils to avoid code duplication.useQuery()
,useSubscription()
anduseMutation()
to use shared utils mentioned above.isReadonly()
check before changingisPaused
variable, as it could be readonly.RemoveonBeforeUnmount
and unwatch handlers, as watcher automatically stopped when the owner component is unmountedflush: 'pre'
in watcher options, as this is default settingunref()
tounwrap()
to avoid confusions with vue functionthen()
handler foruseQuery()
for cleaner code and avoid duplications