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

loadingKey for mutation #23

Open
shomodj opened this issue Jan 12, 2017 · 16 comments
Open

loadingKey for mutation #23

shomodj opened this issue Jan 12, 2017 · 16 comments

Comments

@shomodj
Copy link

shomodj commented Jan 12, 2017

is it just me or loadingKey is not woking for mutations?

@yeusiukou
Copy link

I'm also having problems with loadingKey

@Akryum
Copy link
Member

Akryum commented Feb 20, 2017

There is no loadingKey feature on mutations at the moment. You can implement it very easily yourself:

this.loading ++

this.$apollo.mutate({
  // Query
  mutation: gql`mutation ($label: String!) {
    addTag(label: $label) {
      id
      label
    }
  }`,
  // Parameters
  variables: {
    label: newTag,
  },
}).then((data) => {
  this.loading --
}).catch((error) => {
  this.loading --
});

@shtse8
Copy link

shtse8 commented Oct 26, 2017

Any plans to support loadingKey for mutation?

@enginkartal
Copy link

+1

@gijo-varghese
Copy link

+1

2 similar comments
@PatrickJS
Copy link

+1

@pschaub
Copy link

pschaub commented Dec 12, 2017

+1

@bbugh
Copy link
Contributor

bbugh commented May 28, 2018

Are there plans for this? We have a lot of cases where we do live updated forms, and want to have a "saving..." a la Google Docs. The amount of places we'd need to track variables for the mutation is doable but would be a lot easier if mutation just had a loadingKey instead of having to track variables in many different components.

I checked out the source code for adding this feature in a PR but at first look it seems more complex than I expected. mutate just seems to be a wrapper for apollo-client, and the query is tracked as part of smart-query via an observable in watchQuery and applyLoadingModifier. I didn't go any further because it seems like I'd need to deep-dive into apollo-client to follow it. Am I correct in this complexity or is it a simple matter of adding an observable to mutate the way watchQuery and subscribe have?

@Akryum
Copy link
Member

Akryum commented May 28, 2018

Maybe you can use the <ApolloMutation> component?

@bbugh
Copy link
Contributor

bbugh commented May 28, 2018

That looks plausible. In one case, we have a form with 10 fields. If the user changes a field, we send a mutation to the server with the update, and at the top of the form show "saving". When the migration is done, we show "saved" for a few seconds. It looks like if we wrap the whole form with the ApolloMutation component that it would work. I'll give it a shot, thanks!

@bbugh
Copy link
Contributor

bbugh commented Jun 21, 2018

ApolloMutation works great! We've started using the component operations and it makes the code so nice and easy. Thank you for the PROTIP!

@chadwtaylor
Copy link

+1

@gijo-varghese

This comment has been minimized.

@siegy22
Copy link

siegy22 commented Aug 26, 2019

I expected to at least have $apollo.loading set to true, but that doesn't get updated. :(
So the current way to do this, is just use the ApolloMutation component?

@kieuminhcanh
Copy link

+1

@TkaczykAdam
Copy link

June 2021 and $apollo.loading not work with mutation 😞

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

No branches or pull requests