使用 apollo 缓存调用存储一次的 fetch API?

Call a fetch API which is stored once in using apollo cache?

我一直在研究 Apollo GQL。我正在使用 apollo 缓存来减少不需要的 API 调用。我现在面临的问题是,当我更新数据时,我不应该重新获取数据,因为 API 已经被调用一次并存储在缓存中。

我必须在以下突变调用后重新获取数据。

const [
reopenInvoice,
{ loading: reopenLoading, data: reopenData, error: reopenError },
] = useMutation<IReopenData, IReopenVariables>(INVOICE_CLONE, {
onCompleted: ({ invoiceClone: { errors, status } }) => {
  if (!errors || !errors.length) {
    message.success("Invoice Reopened");
  } else {
    message.error(errors.join(" "));
  }
},
});

"refetchQueries" 是更新缓存的最简单方法。

https://www.apollographql.com/docs/angular/features/cache-updates/#refetchqueries

 const [reopenInvoice, { loading: reopenLoading, data: reopenData, error: reopenError }] = useMutation<IReopenData, IReopenVariables>(
        INVOICE_CLONE,
        {
            onCompleted: ({ invoiceClone: { errors, status } }) => {
                if (!errors || !errors.length) {
                    message.success("Invoice Reopened");
                } else {
                    message.error(errors.join(" "));
                }
            },
            refetchQueries: [
                {
                    query: TO_REFETCH_QUERY,
                    variables: {
                        id: objectID,
                    },
                },
            ],
        }
    );