Skip to content
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

Can not use mutations outside composition function with provideApolloClient #1145

Closed
Zippersk opened this issue Feb 12, 2021 · 10 comments
Closed
Labels

Comments

@Zippersk
Copy link

Describe the bug
With the current implementation of v4, we can not use useMutation function outside Vue3 composition function.

In UseQuery source code we have this condition:

vm && trackQuery(loading)

In UseMutation source code a condition is missing.

trackMutation(loading)

This cause error when we use mutations outside the composition function:

Uncaught (in promise) Error: getCurrentTracking must be used during a component setup
    at getCurrentTracking (loadingTracking.js?b1f0:25)
    at track (loadingTracking.js?b1f0:50)
    at trackMutation (loadingTracking.js?b1f0:71)
    at Module.useMutation (useMutation.js?89f9:57)
@revelaustris
Copy link

Facing the same issue here.

@anli-xsigns
Copy link

Same for me, changing

   trackMutation(loading);

to

    // Is on server?
    var vm = getCurrentInstance();
    var isServer = vm === null || vm === void 0 ? void 0 : vm.$isServer;
    vm && trackMutation(loading);

fixes the issue. Should I create a PR?

@Zippersk
Copy link
Author

Zippersk commented Mar 5, 2021

@anli-xsigns I already created PR 3 weeks ago (#1146). @Akryum can you look at it, please?

@reaink
Copy link

reaink commented Mar 11, 2021

@Akryum can you look at it, please?

@jvmonjo
Copy link

jvmonjo commented Apr 20, 2021

@anli-xsigns I already created PR 3 weeks ago (#1146). @Akryum can you look at it, please?

Hi @anli-xsigns. Since I really need this working ASAP, is there any way I can Install your modified version of vue-apollo?

@Zippersk
Copy link
Author

@jvmonjo you can use this if you want https://github.com/Zippersk/vue-apollo/tree/v4

@TimWeidner
Copy link

I was able to work around this by moving my mutations to the setup function and returning them, but this is some pretty ugly code.

@hloehrmann
Copy link

Also would love to see this approved soon to use a mutation inside a route guard.

@TommyCoding
Copy link

TommyCoding commented May 11, 2021

Seems like subscriptions are affected too, I get the same error message when using useSubscription(...) outside of setup.

@Brymes
Copy link

Brymes commented Jun 28, 2021

@jvmonjo you can use this if you want https://github.com/Zippersk/vue-apollo/tree/v4

I have no idea how to use this PR in my code. Also please when would this be merged and a new release made.. Or if at all anyone has a fork of this PR deployed on NPM.. I need it in my project as soon as i can..

All Help would be appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants