1

I have a mutation

mutation createQuoteLineMutation {
    createQuoteLine {
      quoteLine {
        name
        price
        product {
          name
        }
      }
    }
  }

My updater function is as below.

updater: (store) => {
      const payload = store.getRootField('createQuoteLine');
      const newQuoteLine = payload.getLinkedRecord('quoteLine');
      const quote = store.getRoot().getLinkedRecord('getQuote');
      const quoteLines = quote.getLinkedRecords('quoteLines') || [];
      const newQuoteLines = [...quoteLines, newQuoteLine];
      quote.setLinkedRecords(newQuoteLines, 'quoteLines');
}

This works fine for the first time, but the consequent mutations all the previously added quoteLines change to new one I'm assuming this is because newQuoteLine points to same object all the time.

adding below line at the end of updater function unlink quoteLine from createQuoteLine also does not work.

payload.setValue(null, 'quoteLine');

Any help in this regard is highly appreciated.

Pavan Bahuguni
  • 1,947
  • 1
  • 15
  • 21

1 Answers1

0

I have seen a quite similar problem, but I am not sure if it's the same. Try to pass an clientMutationId to the mutation, and increment it along.

const commit = (
  input,
  onCompleted: (response) => void,
) => {
  const variables = {
    input: {
      ...input,
      clientMutationId: temp++,
    },
  };

  commitMutation(Environment, {
    mutation,
    variables,
    onCompleted,
    onError: null,
    updater: store => {
      // ....
    },
  });
};

Try something like this and let me know if it fixes :).

denyzprahy
  • 820
  • 11
  • 24