1

我有突变

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

我的更新程序功能如下。

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

这第一次工作得很好,但是所有先前添加的quoteLines 随之发生的突变都会更改为新的我假设这是因为newQuoteLine 一直指向同一个对象。

在更新程序函数的末尾添加以下行 unlink quoteLine from createQuoteLine 也不起作用。

payload.setValue(null, 'quoteLine');

非常感谢这方面的任何帮助。

4

1 回答 1

0

我看到了一个非常相似的问题,但我不确定它是否相同。尝试将 an 传递clientMutationId给突变,然后将其递增。

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

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

尝试这样的事情,让我知道它是否修复:)。

于 2019-03-02T21:41:09.363 回答