I think I encountered a bug with the productCreate mutation.
When creating a new product, I am adding new data into a custom app-data metafield of type single_line_text_field which was defined previously. Here is the structure of the MetafieldInput as part of the call to productCreate, where key3 is the single_line_text_field:
// productCreate mutation,
{
variables: {
media: media,
input: {
metafields: [
{
namespace: "$app:{appName}",
key: "key1",
value: JSON.stringify(data1)
},
{
namespace: "$app:{appName}",
key: "key2",
value: data2
},
{
namespace: "$app:{appName}",
key: "key3",
value: data3
},
],
},
},
}
With this call, I receive the following userErrors:
{
"data": {
"productCreate": {
"product": null,
"userErrors": [
{
"field": [
"metafields",
"2",
"type"
],
"message": "Type can't be blank"
}
]
}
}
If I add type: "single_line_text_field" to key3, the mutation does not error out, but then there is no data in the app-data metafield. If I remove namespace for key3, the mutation does not fail, and the data gets populated in the app-data metafield. In addition, if I remove namespace from key1 and key2, the mutation fails with similar userErrors ![]()
According to the documentation, the namespace field for the MetafieldInput object states:
Required when creating a metafield, but optional when updating. Used to help identify the metafield when updating, but can’t be updated itself
In my case, the metafield for key3 has already been defined. Therefore, technically I am updating the metafield, which should mean namespace is optional. However, omitting namespace seems to work for single_line_text_field metafields, but not for other metafield types (namespace required for key1 and key2, but not key3)
Please confirm if this is a bug or a documentation error.
The X-Request-Id for this call is b425c575-073e-4f8c-8812-064af3dc72df-1739377843