A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi there,
I'm trying to query Shopify's GQL API for all discount codes created in a particular store. I'm using the Remix framework provided by Shopify for a custom app.
So far I have the following:
const { storefront } = await unauthenticated.storefront(shopDomain); const response = await storefront.graphql( `query codeDiscountNodes { nodes { id codeDiscount { ... on DiscountCodeBasic { title summary } } } }`, { variables: { codeLimit } }, ); const { data } = await response.json();
This however fails with the following error message:
Error: Field 'nodes' is missing required arguments: ids
I'm obviously doing something wrong in the query, the above works fine in Shopify's GraphQL playground.
To be clear, I want all discount codes for the store as I won't have any identifiers to query against. I just need a list of the first 100 or something.
Can someone point me towards what's wrong with the above?
Many thanks!
Solved! Go to the solution
This is an accepted solution.
Ack, fixed this. The query should be formatted like so:
query ListDiscountCodes($limit: Int!) {
codeDiscountNodes(first: $limit) {
nodes {
id
codeDiscount {
... on DiscountCodeBasic {
title
summary
}
}
}
}
}
This is an accepted solution.
Ack, fixed this. The query should be formatted like so:
query ListDiscountCodes($limit: Int!) {
codeDiscountNodes(first: $limit) {
nodes {
id
codeDiscount {
... on DiscountCodeBasic {
title
summary
}
}
}
}
}