Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
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.
Solved! Go to the solution
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.
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.
User | RANK |
---|---|
6 | |
5 | |
5 | |
4 | |
4 |