简体   繁体   English

错误:GraphQL 错误:字段 'metafieldsSet' 在类型 'Mutation' 上不存在 - Shopify GraphQL 错误

[英]Error: GraphQL error: Field 'metafieldsSet' doesn't exist on type 'Mutation' - Shopify GraphQL error

I have been recently playing with Shopify App Development and i'm struggling with a graphql call to amend some text.我最近一直在玩 Shopify 应用程序开发,我正在努力使用 graphql 调用来修改一些文本。 The image below displays the call being made correctly in the shopify GraphQL app which is where I test it.下图显示了在 shopify GraphQL 应用程序中正确进行的调用,这是我对其进行测试的地方。

在此处输入图像描述

However when I attempt to make this same call from the react component I get the following error但是,当我尝试从反应组件进行相同的调用时,出现以下错误

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

Here is the react component in which I try and update the metafield这是我尝试更新元字段的反应组件

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;

I believe i'm passing the variables into the gql but it doesn't seem to be picking them up?我相信我正在将变量传递给 gql,但它似乎并没有把它们捡起来?

Sigh,叹,

This all along was an API version issue.这一直是 API 版本问题。 Shopify CLI still spins up Oct 2020 API. Shopify CLI 仍在 2020 年 10 月启动 API。 Metafieldset was only added in the 2021 API Metafieldset 仅在 2021 API 中添加

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

The error messages threw me off错误消息让我失望

So to update just update the API version in server.js所以要更新只需更新 server.js 中的 API 版本

API_VERSION: "2021-10",

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM