I don't have a ton of experience with GraphQL, and I'm having trouble finding a straight answer for performing more than one query simultaneously, and whether any GraphQL should support this. My specific context is retrieving products from Shopify, but the answer is probably platform agnostic.
Let's start with this example:
query Q1 {
shop {
name
}
product(id: "gid://shopify/Product/9819449721123") {
category {
id
}
}
}
This retrieving some store info and some product info. Two different objects. However, if I try to retrieve two products, I run into trouble:
query {
product(id: "gid://shopify/Product/9819449721123") {
category {
id
}
}
product(id: "gid://shopify/Product/9808461332771") {
category {
id
}
}
}
The error is Field 'product' has an argument conflict:...
(dropping the rest of the string since it's obvious what the conflict entails and I'm using a UI client that include the response and a lot of escaped slashes in the error message).
How do I request more than one of the same type? There seems to be mention of multi-query requests everywhere, and yet none of anything that is mentioned seems to work. Plus, I'm not clear on whether there maybe whether it needs to start with a different root node type, and whether not every GraphQL server supports it.
I appreciate the help.
Yes. Add a label to the front of each type's line (we've included the product IDs in the result for the evidence):
query {
q1: product(id: "gid://shopify/Product/9819449721123") {
id
category {
id
}
}
q2: product(id: "gid://shopify/Product/9808461332771") {
id
category {
id
}
}
}
Response:
{
"data": {
"q1": {
"id": "gid://shopify/Product/9819449721123",
"category": {
"id": "gid://shopify/TaxonomyCategory/aa-1-10-2-14"
}
},
"q2": {
"id": "gid://shopify/Product/9808461332771",
"category": {
"id": "gid://shopify/TaxonomyCategory/aa-1-10-2"
}
}
},
"extensions": {
"cost": {
"requestedQueryCost": 4,
"actualQueryCost": 4,
"throttleStatus": {
"maximumAvailable": 20000,
"currentlyAvailable": 19996,
"restoreRate": 1000
}
}
}
}