将变量从 useMutation 钩子传递给 Apollo GraphQL 回调

时间:2021-03-16 19:56:45

标签: graphql apollo apollo-client react-apollo

我在我的应用程序的循环中使用来自 Apollo useMutation 钩子的 mutate 函数。它运行良好,但我需要将实际 GraphQL 调用中未使用的变量从循环范围传递到 onCompleted 回调,而且我在文档或论坛中没有看到任何策略。

目前的结构如下:

变异和回调

  const [getBalance] = useMutation(BALANCE_MUTATION, {
    onCompleted: ({ data }) => {
      // I would like to do something with data and the original orderLine here
    },
  });

循环和调用:

  orderLines.forEach((orderLine, i) => {
    getBalance({
      variables: {
        input: {
          orderNumber: orderLines.orderNumber,
          currency: orderLines.currency,
        },
      },
    });
  });

有人这样做过或知道推荐的策略吗?

0 个答案:

没有答案