Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

Querying ~500 orders too sluggish with GraphQL

Querying ~500 orders too sluggish with GraphQL

crt_leinade
Visitor
3 0 1

We’re trying to query around 500 orders to get customer, address, order line items, and product information for every product ordered. These are all the data points we need to produce a report on orders and products purchased.

Here’s an snippet of what we're working on right now:

const GET_ORDERS = `query ($cursor: String, $dateRange: String) {
  orders(first: 10 after: $cursor query:$dateRange) {
    pageInfo {
      hasNextPage
    }
    edges {
      cursor
      node {
        id
        name
        createdAt
        displayFulfillmentStatus
        tags
        note
        shippingAddress {
          id
          address1
          address2
          formattedArea
        }
        lineItems(first: 10) {
          edges {
            node {
              id
              name
              sku
              variant {
                id
                displayName
                weight
                weightUnit
              }
              product {
                id
                productType
              }
              quantity
              discountedUnitPriceSet {
                shopMoney {
                  amount
                  currencyCode
                }
              }
            }
          }
        }
        customer {
          id
          displayName
          phone
        }
      }
    }
  }
`

const queryString = 'created_at:>2020-10-19 AND created_at:<2020-10-26';
const [hasNextPage, setHasNextPage] = useState(false);
const [cursor, setCursor] = useState(null);
​
const { data: orderProduceData, loading } = useQuery(
    gql(GET_ORDERS_PRODUCE),
    {
        variables: { cursor, queryString },
        notifyOnNetworkStatusChange: true,
        onCompleted: data => {
            setCursor(getLastCursorInResponse(data));
            setHasNextPage(data?.orders.pageInfo.hasNextPage ?? false);
        },
    }
);
​
useEffect(() => {
    if (hasNextPage && cursor && !loading) {
        fetchMore({
            variables: { cursor, queryString },
            updateQuery: (prev, { fetchMoreResult }) => ({
                orders: {
                    pageInfo: {
                    ...prev?.pageInfo,
                    ...(fetchMoreResult?.pageInfo ?? {}),
                    },
                    edges: [...prev?.edges, ...(fetchMoreResult?.edges ?? [])],
                },
            }),
        });
    }
}, [hasNextPage, cursor, loading, fetchMore]);

 

Here are the approaches we’ve tried so far:

  • Paginating order data - using a higher page size hits the limit right off the bat. A lower one is too sluggish since we’re not only waiting for the server to query internally, but also have to figure in the back and forth of the request and the response. Right now, each order requires 47 calculated points and an average of 11 actual points

 

  • Paginating order and product data separately - this still hits the limit after a few pages
  • Thought of throttling the requests locally (sending requests only every second to allow the limit bucket to replenish itself), but that will result in some more delay
  • Requesting a bulk query operation - it doesn’t matter how small the requests are, the absolute minimum seem to be at around 15 seconds which is still too slow for us

 

Are there other approaches that are worth looking at to get a complete list of orders faster?

Or perhaps configuration somewhere that helps with this? Something like AWS’ request limit increase

Replies 2 (2)

dom-linq
Shopify Partner
34 1 14

This is a great question @crt_leinade, I am also looking for a faster and more reliable way to grab order data for larger stores.

HunkyBill
Shopify Partner
4853 60 568

Hang on.. you are complaining that 15 seconds is too long? What is your business use case for that? Seems a bit suspicious to NEED speed for what is nothing more than a housekeeping operation.

Can you at least define your need for speed? Be interesting to know.

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