首页 > 解决方案 > React Native GraphQL 使用 Apollo:将数组传递给突变输入

问题描述

我只是用 apollo 调用 api graph QL 几天

我只有一个简单的问题

如何将像变量一样的数组传递给突变

在我的代码第 7 行中,我想将“航点”数组传递给突变。

请!!!

const GET_QUOTATION = gql`
    query($date: String!) {
      getQuotation(
        input: {
          pickupTime: $date
          serviceType: CAR
          waypoints: [
            {
              type: PICKUP
              address1: "Anson Road, #23-01"
              address2: "079906"
              location: {lat: "1.307274", lng: "103.883998"}
              name: "Jack"
              phone: "82187877"
            }
          ]
        }
      ) {
        delivery {
          provider
          price
        }
        poolWindow {
          price
          window
        }
      }
    }
  `;

  const [getQuotation, quotationData] = useLazyQuery(GET_QUOTATION, {
    onCompleted() {
      console.log('-> success');
    },
    onError() {
      console.log('-> error');
    },
    variables: {
      date: '2021-03-12T18:54:00Z',
    },
  });

标签: react-nativegraphqlapollo

解决方案


推荐阅读