-
-
Notifications
You must be signed in to change notification settings - Fork 48
Create vue query plugin #112
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
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/damianosipiuk/vue-query/HjBVg9R8fa8N79rQypJEtcNg98Pm |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 246d485:
|
Kudos, SonarCloud Quality Gate passed!
|
Codecov Report
@@ Coverage Diff @@
## main #112 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 14 +1
Lines 240 252 +12
Branches 45 50 +5
=========================================
+ Hits 240 252 +12
Continue to review full report at Codecov.
|
@aantipov Hi, Currently i think we could borrow a piece of code from Also if we would be able to create a single plugin that works for both versions, i would be happy to mark |
That would be ideal. On the other hand, I'm asking myself - how far should we go in Vue2 support? There is also another dimension - NuxtJS (current with Vue2 and future with Vue3 versions) which can also bring certain complexities. @DamianOsipiuk what expectation do you have regarding the usage of VueQuery within Vue2 and Vue3 ecosystems? Vue3 is 1.5 years old. Smaller projects are migrating to Vue3. Bigger projects will, probably, never migrate to Vue3. And I don't even expect those bigger projects start using CompositionAPI (it has its own limitations). VueQuery requires a mind shift as of handling server data. Old big Vue2 projects most probably won't risk that change. There are already many apps created with Vue3. And, going forward, Vue3 base will increase and Vue2's will decrease I, personally, woudn't event consider supporting legacy Vue2. Better invest time into DX and Documentation to make the library more attractive, understandable and easier to work with. What's your opinion? |
I think that we should support Vue 2 at least to the point when
As of now Vue 2 usage is still very big. Vue 2 is set as the Support for Vue 2 is currently pretty straightforward (maybe besides devtools), so i think we can still easily support it. Also there is Vue 2.7 in the pipeline that should enable compositionAPI usage without additional libraries. This should make support even easier. |
Oh, didn't know about it. So it'll make vue-demi redundant? Ok. Understand your point. Fair enough.
This hack looks really cryptic, I don't like it and don't know how it works and if it can help us. I have another idea. My proposal is to go with the current |
I would like to stick with provide/inject as it is recommended way to pass data |
Agree. Thanks. Hope it all works as expected. Looking forward to the feature!
Good point. It might be helpful to have this opportunity |
Closing in favor of #116 |
Story
I wanted to use VueQuery in my app's root component:
But I got an error in the console saying that there are no query client available.
After digging into it, I realised that
useQueryProvider
calls Vue'sprovide
. Query hooks rely oninject
which can be used in child components only. That's why I got the errorProblem
I could work around - e.g. create a wrapper root component and call
useQueryProvider
there. Or refactor my root component and call query hooks in children components.But I see also other problems with
useQueryProvider
:useQueryProvider
hook. Should I use it in every component or only in the root component?Context
. In Vue community "Provider" doesn't really makes any sense.Vue libraries are usually initialized as plugins.

Take for example Pinia
I think we can do the same thing - initialize Vue Query as a plugin and, thus, make it consistent with other Vue libraries.
It also fits perfectly our case. In 99% cases our users need a global Query Client. We can make it globally available when initializing as a plugin. That would solve my original problem - using VueQuery in the root component.
Implemented Changes
VueQueryPlugin
(to be used in Vue3 only because plugin api in Vue2 and Vue3 is different)With these changes Vue3 users are able to init VueQuery like this:
