Currently I am working on a feature that on button click a metafield gets updated. To verify that the metafield isn’t full, I send a GraphQL query to look if the metafield is blank or full.
But now comes the error: It says "Variable id of type ID! was provided invalid value". I don’t know what to do, to fix this error.
That is the GraphQL query:
export const VIEW_PRODUCT_METAFIELD = `
query VIEW_METAFIELD($id: ID!){
myProduct: product(id: $id) {
metafield(namespace:"custom", key:"myfield"){
namespace
key
value
updatedAt
}
}
}
`
My code is:
var shopifyId = "gid://shopify/Product/" + product_id;
var isFull = await client.query({
data: {
query: VIEW_PRODUCT_METAFIELD,
variables: {
input: {
id: shopifyId <=== Here occurs the error
}
}
}
});
I made a second version but neither of both work:
var isFull = await client.query({
data: {
query: VIEW_PRODUCT_METAFIELD,
variables: {
input: {
id: `gid://shopify/Product/${product_id}` <=== Here occurs the error
}
}
}
});
It would very help me if anyone has a solution for this.
3
Answers
I just inserted the query directly into the client.query({
It look like this now:
Can’t speak for your code but the code that works 100% of the time for me looks like this:
with data:
Anyone else coming here for the solution. Here’s the correct code. OP just used the variable input incorrectly.