Async Actions
Introduction
Sometimes you may not want to wait for an action to complete before
sending a response back to the client (say if the business logic takes a
long time). In such cases you can create an asynchronous action,
which returns an action_id
immediately to the client before contacting
the handler.
If you mark an action as asynchronous, Hasura also generates a
query
and a subscription
field for the action so that you can
query/subscribe to its status.
Only Actions of type mutation
can be async. Actions of type query are
always executed synchronously.
For example, let's say place_order
is an asynchronous action
mutation placeOrderRequest($order_input: place_order_input!) {
place_order(input: $order_input)
}
Executing this mutation will return a response like:
{
"data": {
"place_order": "23b1c256-7aff-4b95-95bd-68220d9f93f2"
}
}
The returned uuid
is the action id
of the async action. To get the
actual response of the action, you can query
or subscribe
to the
action using this action id
.
subscription getPlaceOrderResponse {
place_order(id: "23b1c256-7aff-4b95-95bd-68220d9f93f2") {
output
errors
}
}
Introduction to Hasura Actions - View Recording.