reactjs - GraphQL 查询问题 - shopify 北极星
问题描述
我在开发 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.
解决方案
我找到了正确的类型$orderId
。我改变String
了ID!
这是我的固定代码。
const GET_ORDER_DETAIL = gql`
query getOrderDetail($orderId: ID!) {
...
}
`;
...
<Query key={index} query={GET_ORDER_DETAIL} variables={{ orderId }}>
...
推荐阅读
- javascript - 使用 JavaScript 和 CSS 定位子菜单
- javascript - 此代码如何将字符串添加到数组列表并返回它?
- file - 如何将 imagePath 更改为文件?
- xamarin - Xamarin Android 在 Azure Pipeline 中构建失败
- tensorflow - Tensorflow-Onnx-Tensorrt 的准确度下降
- c++ - 为什么我会收到来自 SymInitialize 的虚假错误消息?
- angular - 如何通过角度角色仅显示当前用户的组件
- azure - 将共享文件夹位置中的文件中的数据导入 SQL 托管实例?
- ms-access - 如何在 MS Access 中评估一组记录并获得单个结果
- gdb - GDB 输出中的意外行为