apollo icon indicating copy to clipboard operation
apollo copied to clipboard

loadingKey for mutation

Open shomodj opened this issue 7 years ago • 16 comments

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

shomodj avatar Jan 12 '17 13:01 shomodj

I'm also having problems with loadingKey

yeusiukou avatar Feb 20 '17 07:02 yeusiukou

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 --
});

Akryum avatar Feb 20 '17 10:02 Akryum

Any plans to support loadingKey for mutation?

shtse8 avatar Oct 26 '17 16:10 shtse8

+1

enginkartal avatar Oct 29 '17 21:10 enginkartal

+1

gijo-varghese avatar Nov 03 '17 17:11 gijo-varghese

+1

PatrickJS avatar Dec 10 '17 03:12 PatrickJS

+1

pschaub avatar Dec 12 '17 13:12 pschaub

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?

bbugh avatar May 28 '18 14:05 bbugh

Maybe you can use the <ApolloMutation> component?

Akryum avatar May 28 '18 15:05 Akryum

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 avatar May 28 '18 16:05 bbugh

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

bbugh avatar Jun 21 '18 17:06 bbugh

+1

chadwtaylor avatar Jun 26 '19 16:06 chadwtaylor

Thank god, I left VueJS!

gijo-varghese avatar Jun 26 '19 16:06 gijo-varghese

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?

siegy22 avatar Aug 26 '19 10:08 siegy22

+1

kieuminhcanh avatar Jun 07 '20 16:06 kieuminhcanh

June 2021 and $apollo.loading not work with mutation :disappointed:

TkaczykAdam avatar Jun 22 '21 10:06 TkaczykAdam