GraphQL error: Variable was provided invalid value for metafields.0.type

Solved
Tergiversator
New Member
1 0 0

I've been trying to run a metafield mutation in code:

import { useMutation } from 'react-apollo';
import gql from 'graphql-tag';
...
const UPDATE_METAFIELD = gql`
  mutation productUpdate($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      id
      metafield(namespace: "nutrition", key: "calories") {
        id
        namespace
        key
        value
      }
    }
  }
}
`;
...
const productInput = {
    "id": "gid://shopify/Product/[productid number]",
    "metafields": {
      "namespace": "nutrition",
      "key": "vitamins",
      "value": "2000",
      "valueType": "INTEGER",
      "type": "number_integer"
    }
  };
const [mutate, { data, loading, error }] = useMutation(UPDATE_METAFIELD);
...
mutate({ variables: { input: productInput }});

 However when I run the code, I get the following error:

"Error: GraphQL error: Variable $input of type ProductInput! was provided invalid value for metafields.0.type (Field is not defined on MetafieldInput)"

I have checked the docs and "INTEGER" and "number_integer" should both be valid values for the valueType and type fields.  Any help on this would be much appreciated.

Accepted Solution (1)

Accepted Solutions
swalkinshaw
Shopify Staff
Shopify Staff
20 4 9

This is an accepted solution.

The `type` input field only exists on API versions 2021-07 and newer and I'm guessing you're using an older API version. See https://shopify.dev/api/admin/graphql/reference/metafields/metafieldinput?api%5Bversion%5D=2021-07

 

Just a note that when you do get `type` working on the new API version, you don't have to include the `valueType` anymore.

View solution in original post

Reply 1 (1)
swalkinshaw
Shopify Staff
Shopify Staff
20 4 9

This is an accepted solution.

The `type` input field only exists on API versions 2021-07 and newer and I'm guessing you're using an older API version. See https://shopify.dev/api/admin/graphql/reference/metafields/metafieldinput?api%5Bversion%5D=2021-07

 

Just a note that when you do get `type` working on the new API version, you don't have to include the `valueType` anymore.