簡體   English   中英

錯誤:GraphQL 錯誤:字段 'metafieldsSet' 在類型 'Mutation' 上不存在 - Shopify GraphQL 錯誤

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

我最近一直在玩 Shopify 應用程序開發,我正在努力使用 graphql 調用來修改一些文本。 下圖顯示了在 shopify GraphQL 應用程序中正確進行的調用,這是我對其進行測試的地方。

在此處輸入圖像描述

但是,當我嘗試從反應組件進行相同的調用時,出現以下錯誤

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

這是我嘗試更新元字段的反應組件

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 仍在 2020 年 10 月啟動 API。 Metafieldset 僅在 2021 API 中添加

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

錯誤消息讓我失望

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

API_VERSION: "2021-10",

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM