我在开发 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.