Adding metafields error

Topic summary

A first-time app developer (Node) is trying to create a Shopify metafield definition via the Admin GraphQL API, following the 2021-10 docs. They receive schema-related errors indicating the mutation and input type are not recognized.

Errors reported:

  • “MetafieldDefinitionInput isn’t a defined input type (on $definition)”
  • “Field ‘metafieldDefinitionCreate’ doesn’t exist on type ‘Mutation’”
  • “Variable $definition is declared by metafieldDefinitionCreate but not used”

A code snippet (central to the issue) shows a mutation named “metafieldD efinitionCreate” with variables for description, key, name, namespace, ownerType, pin, type, and validations. The user notes they are new to GraphQL and used the Shopify CLI to scaffold the app.

Key point: The server rejects the mutation and input type, suggesting a mismatch with the GraphQL schema in use. No troubleshooting steps, fixes, or decisions are confirmed yet.

Status: Open; the user is requesting help and no resolution is provided in the thread.

Summarized with AI on February 22. AI used: gpt-5.

Hi,

I am trying to develop my first app and tried to create a metafield following the example linked here.

This is for an app made using $ shopify app create node.

I am new to using graphQL as well. The following error occurred:

GraphQL error: MetafieldDefinitionInput isn't a defined input type (on $definition)
GraphQL error: Field 'metafieldDefinitionCreate' doesn't exist on type 'Mutation'
GraphQL error: Variable $definition is declared by metafieldDefinitionCreate but not used

Code:

const ADD_FIELDS = gql`
    mutation metafieldDefinitionCreate($definition: MetafieldDefinitionInput!) {
    metafieldDefinitionCreate(definition: $definition) {
      createdDefinition {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
  `;

  const [addFields, { data, loading, error }] = useMutation(ADD_FIELDS, {
    'variables': {
      "definition": {
        "description": "",
        "key": "",
        "name": "",
        "namespace": "",
        "ownerType": "",
        "pin": "",
        "type": "",
        "validations": {
          "name": "",
          "value": ""
        }
      }
    }
  });

Any help is appreciated :slightly_smiling_face: thanks!

1 Like