【问题标题】:GraphQL query issue - shopify polarisGraphQL 查询问题 - shopify 北极星
【发布时间】:2020-05-11 02:34:33
【问题描述】:

我在开发 shopify 应用程序时遇到了有关 graphQL 的问题。 逻辑很简单。我需要使用 graphQL 从 shopify 商店获取 lineItems。 这是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.

【问题讨论】:

  • 你不应该在Query中使用id而不是ids吗?
  • 哦,对不起,我编辑了。但有同样的问题。

标签: reactjs graphql shopify-app polaris


【解决方案1】:

我找到了$orderId 的正确类型。 我将String 更改为ID!

这是我的固定代码。

const GET_ORDER_DETAIL = gql`
query getOrderDetail($orderId: ID!) {
 ...
}
`;
...
<Query key={index} query={GET_ORDER_DETAIL} variables={{ orderId }}>
...

【讨论】:

    猜你喜欢
    • 2019-07-05
    • 2022-06-13
    • 2019-04-06
    • 1970-01-01
    • 2020-07-25
    • 1970-01-01
    • 2020-05-20
    • 1970-01-01
    • 2018-09-02
    相关资源
    最近更新 更多