GraphQL查询问题 - shopify polaris

问题描述 投票:-1回答:1

我在开发shopify应用的时候,遇到了graphQL的问题,逻辑很简单。我需要得到 细目 从shopify商店使用graphQL.这里是gql的代码。

const GET_ORDER_DETAIL = gql`
query getOrderDetail($orderId: String) {
  order(id: $orderId) {
    name
    physicalLocation {
      id
    }
    lineItems (first:100){
      edges {
        node {
          id
        }
      }
    }
  }
}
`;

而这里是我的React代码。

{
  this.state.refund_list.map((list, index) => {
    const orderId = `gid://shopify/Order/${list.order_id}`; // I got correct orderId.

    return (
      <Query key={index} query={GET_ORDER_DETAIL} variables={{ id: orderId }}>
        {({ data, loading, error }) => {
          if (loading) return <div>loading...</div>;
          if (error) return <div>{error}</div>;
          console.log(data);
          return <div>test</div>;
        }}
      </Query>
    );
  })
}

而这里是错误的句子。

Uncaught Error: Objects are not valid as a React child (found: Error: GraphQL error: Type mismatch on variable $orderId and argument id (String! / ID!)). If you meant to render a collection of children, use an array instead.
reactjs graphql shopify-app polaris
1个回答
0
投票

我发现正确的类型 $orderId.我改了 StringID!

这是我的固定代码。

const GET_ORDER_DETAIL = gql`
query getOrderDetail($orderId: ID!) {
 ...
}
`;
...
<Query key={index} query={GET_ORDER_DETAIL} variables={{ orderId }}>
...
© www.soinside.com 2019 - 2024. All rights reserved.