kamilkisiela / apollo-angular

A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
https://apollo-angular.com
MIT License
1.5k stars 311 forks source link

Object literal may only specify known properties, and 'onCompleted' does not exist in type 'MutationOptionsAlone<>'. #1595

Closed teebszet closed 4 years ago

teebszet commented 4 years ago

Although it is described in the Apollo Client v3 documentation here: https://www.apollographql.com/docs/react/data/mutations/, onCompleted is not defined as one of the accepted mutation options.

I'm using graphql-codegen to generate the mutation service and calling it like this:

  this.addPaymentBatchGQL.mutate(
    { args },
    { 
      update: (cache, { data, errors }) => { 
        try { 
          const { addPaymentBatch } = data;
          cache.writeFragment({
            fragment: AddPaymentBatchFragmentDoc,
            data: addPaymentBatch,
          });
        } catch (e) { 
          console.error(e);
        } 
      },
>>    onCompleted: (data) => { 
        // call oncomplete hook
      },
    } 
  );

Environment:

fetis commented 4 years ago

this looks like React specific for me because I can't find it in mutate API https://www.apollographql.com/docs/react/api/core/ApolloClient/#ApolloClient.mutate which we use

I think a standard observer next callback should fit your needs

 apollo.mutate(..).subscribe(results => ...)
teebszet commented 4 years ago

@fetis thanks, yeah you're right that should be the API to be referencing.

my use case is actually to have a callback or hook for after the update function finishes, and the cache has been updated (which, admittedly, the onComplete callback also does not cover).

after I posted this, I looked through the apollo client query manager code, and my conclusion was no such hook exists, but for me it would be a nice to have! I still haven't figured out a workaround for this