gpt4 book ai didi

graphql - 错误 : GraphQL error: Field 'metafieldsSet' doesn't exist on type 'Mutation' - Shopify GraphQL error

转载 作者:行者123 更新时间:2023-12-05 04:40:46 26 4
gpt4 key购买 nike

我最近一直在玩 Shopify 应用程序开发,我正在努力处理 graphql 调用来修改一些文本。下图显示了在我测试它的 shopify GraphQL 应用程序中正确进行的调用。

enter image description here

但是,当我尝试从 React 组件进行相同的调用时,出现以下错误

Unhandled Runtime Error
Error: GraphQL error: Field 'metafieldsSet' doesn't exist on type 'Mutation'
GraphQL error: Variable $metafields is declared by metafieldsSet but not used

这是我尝试更新元字段的 react 组件

import React, { useState } from 'react';
import gql from 'graphql-tag';
import { Mutation } from 'react-apollo';
import { Layout, Button, Banner, Toast, Stack, Frame } from '@shopify/polaris';
import { Context } from '@shopify/app-bridge-react';
// GraphQL mutation that updates the prices of products
const UPDATE_TEXT = gql`mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
value
id
key
ownerType

}
userErrors {
field
message
}
}
}
`;
class UpdateTheText extends React.Component{
static contextType = Context;
render(){
return(
<Mutation mutation={UPDATE_TEXT}>
{(handleSubmit, {error, data}) => {
const [hasResults, setHasResults] = useState(false);

const showError = error && (
<Banner status="critical">{error.message}</Banner>
);

const showToast = hasResults && (
<Toast
content="Successfully updated"
onDismiss={() => setHasResults(false)}
/>
);

return (
<Frame>
{showToast}
<Layout.Section>
{showError}
</Layout.Section>

<Layout.Section>
<Stack distribution={"center"}>
<Button
primary
textAlign={"center"}
onClick={() => {
let promise = new Promise((resolve) => resolve());
const newmetafields = {
key: "ExtraShopDesc",
namespace: "ExtraShopDescription",
ownerId: "gid://shopify/Shop/55595073672",
type: "single_line_text_field",
value: "This is an extra shop description twice"
}

promise = promise.then(() => handleSubmit({ variables: { metafields: newmetafields }}));


if (promise) {
promise.then(() => this.props.onUpdate().then(() => setHasResults(true)));
}}
}
>
Update Text
</Button>
</Stack>
</Layout.Section>
</Frame>
);
}}
</Mutation>
);
}

}

export default UpdateTheText;

我相信我正在将变量传递到 gql,但它似乎没有接收到它们?

最佳答案

感叹,

这一直是 API 版本问题。 Shopify CLI 仍然启动 Oct 2020 API。 Metafieldset 仅在 2021 API 中添加

https://shopify.dev/api/admin-graphql/2021-10/mutations/metafieldsset

错误信息让我失望

所以要更新只需更新 server.js 中的 API 版本

API_VERSION: "2021-10",

关于graphql - 错误 : GraphQL error: Field 'metafieldsSet' doesn't exist on type 'Mutation' - Shopify GraphQL error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70216232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com