A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I'm creating an app that has a form for adding products to inventory, on this form I'd like to include the price the product is to be set to. New to graphQL I'm having trouble wrapping my head around the productCreate mutation and setting the price without receiving an error.
I've tried including the price within the initial productCreate input:
{ "input": { "title": "test product2", "productType": "test type", "descriptionHtml": "test product description 2", "tags": "test", "variants":{ "price": "10" } } }
Which returns the error:
"message": "you must provide one of first or last"
At this point the product with the price has been created but the error persists on the client side confusing me as it makes it seem like the product is not created.
Could someone explain to me why I'm getting this error so I can figure out how to eliminate it from happening when I create products or update them with variants?
Cheers.
Solved! Go to the solution
This is an accepted solution.
Solved, but without clear understanding. I updated my mutation from:
mutation productCreate($input:ProductInput!) { productCreate(input:$input) { userErrors { field message } product { title description variants { edges { node { price } } } } } }
To the following:
mutation productCreate($input:ProductInput!) { productCreate(input:$input) { userErrors { field message } product { title description variants(first:1) { edges { node { price } } } } } }
Yet I do not know what this means nor where last, before, or after will be of use in the future.
Still seeking clarification for my edification.
This is an accepted solution.
Solved, but without clear understanding. I updated my mutation from:
mutation productCreate($input:ProductInput!) { productCreate(input:$input) { userErrors { field message } product { title description variants { edges { node { price } } } } } }
To the following:
mutation productCreate($input:ProductInput!) { productCreate(input:$input) { userErrors { field message } product { title description variants(first:1) { edges { node { price } } } } } }
Yet I do not know what this means nor where last, before, or after will be of use in the future.
Still seeking clarification for my edification.
Hey @jenn11 - You've got it right now. Typically fields that could return long lists accept arguments "first" and "after" to allow for specifying a specific region of a list, where "after" is a unique identifier of each of the values in the list. This is a GraphQL standard practice for fields such as this. This is used to control how much information you are loading, to avoid an overly costly query. There is some great information available here: https://www.shopify.ca/partners/blog/shopify-graphql-learning-kit#pagination
To learn more visit the Shopify Help Center or the Community Blog.
This should do it, I also filtered by active.
query activeCollectionDiscount {
automaticDiscountNodes (first: 10, query:"status:active") {
edges {
node {
id
automaticDiscount{
... on DiscountAutomaticBasic {
status
title
customerGets {
items {
__typename
... on DiscountCollections {
__typename
collections(first:1) {
edges{
node {
id
title
}
}
}
}
}
}
}
}
}
}
}
}