A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I'm trying to run a bulk operation that has a variable in it. It's almost identical to the example here: https://shopify.dev/api/usage/bulk-operations/queries except the query has a variable in it, e.g.:
mutation BulkOrders($created_at: String!) {
bulkOperationRunQuery(
query:"""
{
products(query: $created_at) {
edges {
node {
id
}
}
}
}
"""
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}
Is there any way for this to work? Trying to invoke it as is, with a variable like:
{
"created_at": "created_at:>'2022-04-22T00:00:00'"
}
yields:
{
"errors": [
{
"message": "Variable $created_at is declared by BulkOrders but not used",
"locations": [
{
"line": 1,
"column": 1
}
],
"path": [
"mutation BulkOrders"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "created_at"
}
}
]
}
I guess the string in `bulkOperationRunQuery` has to be static, so this is impossible? Is there any way to do a parameterized bulk query (beyond generating one per variable value dynamically at run time)?
Solved! Go to the solution
This is an accepted solution.
The `query` string is static. Parameters cannot be resolved within the query string, so the query must be built dynamically on the GraphQL client side.
This is an accepted solution.
The `query` string is static. Parameters cannot be resolved within the query string, so the query must be built dynamically on the GraphQL client side.