Hello Shopify Developer Community,
I would like to propose a crucial feature enhancement for the events
query in the Admin GraphQL API.
The Problem Currently, the events
query allows filtering by fields like action
and subject_type
, but it does not support direct filtering by subject_id
, the GID of a specific object.
Primary Use Case A very common scenario for our application is to determine if a product is non-existent because it was deleted, or if it never existed in the first place. The only way to do this currently is as follows:
-
Fetch all product deletion events using
query: "action:'destroy' AND subject_type:'PRODUCT'"
. -
If there are many results, paginate through all of them.
-
Loop through all the fetched results within our application code to check if our specific
subjectId
is present.
This workflow is highly inefficient. To check the status of a single product, it forces us to make a large number of unnecessary API calls and transfer a lot of data, leading to significant performance degradation and a spike in API usage.
Proposed Solution I propose enhancing the query
argument for the events
field to support filtering by subject_id
, allowing for a query like this:
GraphQL
query {
events(first: 1, query: "action:'destroy' AND subject_type:'PRODUCT' AND subject_id:'gid://shopify/Product/1234567890'") {
edges {
node {
id
... on BasicEvent {
subjectId
}
}
}
}
}
Benefits
-
Increased API Efficiency: Get the exact result needed in a single, precise query.
-
Improved Developer Experience: Eliminates the need for complex pagination and client-side filtering logic.
-
Reduced Server Load: Decreases the load on both Shopify’s servers and our own application servers.
I am confident that this feature would be a valuable addition for many developers trying to build stable and efficient apps on the Shopify platform.
Thank you for your consideration.