【发布时间】: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