A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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:
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
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.
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.