Migrate to async segmentation queries
Version 2023-01 of the GraphQL Admin API introduces support for asynchronous queries in
customersSegmentMembers. While most queries will continue to resolve synchronously, some queries could be processed asynchronously based on query complexity and the amount of shop data. Building proper asynchronous query handling provides a better user experience for complex queries.
This guide shows you how to migrate your app to support asynchronous customer segment queries.
Step 1: Retrieve a list of segment membersAnchor link to section titled "Step 1: Retrieve a list of segment members"
If a query to
customersSegmentMembers must be processed asynchronously, then the API returns a
The API can return async queries for unsaved and saved segments (
segmentId GraphQL parameters respectively).
Step 2: Request an asynchronous queryAnchor link to section titled "Step 2: Request an asynchronous query"
You can use the
customerSegmentMembersQueryCreate mutation to process your request asynchronously. Provide the
segmentId as part of the
input. You can optionally include the
The response contains a
id, which is unique identifier for the request,
done, which represent's the query's status, and a
currentCount of the number of segment members in your saved or unsaved segment.
Step 3: Check the request statusAnchor link to section titled "Step 3: Check the request status"
Most async queries should revolve within five seconds but some queries might take one to two minutes or even longer depending, on query complexity and amount of shop data.
You can check the status of your async request using its unique identifier. The response contains information about the query status and current count.
Alternatively, you can try to retrieve the list of customer segment members using the
queryId parameter. If the async query is still running, then the
QUERY_NOT_COMPLETE error code is returned.
Step 4: Retrieve the list of customer segment membersAnchor link to section titled "Step 4: Retrieve the list of customer segment members"
After the async query completes, you can retrieve a list of segment members by querying
customersSegmentMembers and passing in the