Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Variable in GraphQL bulk operation?

Solved

Variable in GraphQL bulk operation?

few_meaning
Shopify Partner
20 3 2

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)?

Accepted Solution (1)

few_meaning
Shopify Partner
20 3 2

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.

View solution in original post

Reply 1 (1)

few_meaning
Shopify Partner
20 3 2

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.