Bulk GraphQL (Ruby): get orders since specific date

Claire222
Shopify Partner
66 2 5

Hi,

I can obtain a list of orders since a specific date using GraphQL, but can't seem to do so via Bulk

Non Bulk GraphQL - working

 

 

query ($query_string: String, $first: Int) {
  orders(query: $query_string, first: $first) {
    edges {
      node {
        id
        legacyResourceId
        name
        processedAt
        cancelledAt
      }
    }
  }
}

 

 

 

Here's the BULK QUERY

 

 

  QUERY_BULK= ShopifyAPI::GraphQL.client.parse <<-'GRAPHQL'
    mutation {
      bulkOperationRunQuery(
       query : """
        { 
          OrdersQuery($query_string: String): orders(query: $query_string) {
            edges {
              node {
                id
                legacyResourceId
                name
              }
            }
          }
        }
        """
      ) {
        bulkOperation {
          id
          status
        }
        userErrors {
          field
          message
        }
      }
    }
  GRAPHQL

 

 

 

and it's called via

 

 

client = ShopifyAPI::GraphQL.client
variables = {"query_string": "created_at:>=2020-01-01" }
result = client.query(QUERY_BULK, variables: variables) 

 

 

 

But I'm getting:

 

 

"Parse error on \"QUERY_BULK\" (IDENTIFIER) at [1, 3]"

 

 

I've tried placing `($query_string: String)` in various places of the GraphQL Query and it's not working. 

I have a few questions:

  • Does Shopify BULK GraphQL query support variables?
  • If so, how does someone run a query like get me all orders since XXX date, where the date can change?
0 Likes
_JB
Shopify Staff
Shopify Staff
750 87 165

Hey @Claire222,

Bulk operations does support variables, but you don't pass them in or declare the variable like with regular queries. When using bulk operations, you include the query string or other variables directly in the query. For your query it will look like this:

mutation {
  bulkOperationRunQuery(
    query:"""
    {
    orders(query: "created_at:>2020-01-01") {
    edges {
      node {
        id
        legacyResourceId
        name
        processedAt
        cancelledAt
      }
    }
  }
}   
    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

 

Our docs here have another example as well.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
Claire222
Shopify Partner
66 2 5

Thanks @_JB , does that mean it's not common to run bulk query for a specific shop, since it's unrealistic to create a new query for each shop in the code? Unless there's a way that queries doesn't have to be constants.

0 Likes
mc-dev
New Member
2 0 0

@_JB Is there a way to dynamically pass in a `Date` in to a bulk query? say each shop has a different date for the bulk query.

@Claire222 Have you found a solution?

0 Likes
HunkyBill
Shopify Expert
4374 36 468

It is pretty easy to customize bulk queries. While they don't accept variables, you can easily just HEREDOC the dynamic data you need. So in my case, my bulk download needs a specific date or collection ID, I just call my function that sets up everything, the dynamic data is rendered inline with the bulk GQL query, and boom. I have a GQL bulk query I can execute specific to the data I want.

Took a little bit of fiddling before I nailed it, but it works in any situation, so it's flexible.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes