mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
5116e16e18
* add support for action queries * a new parameter `type` is added in the ArgumentDefinition, its value can be either `query` or `mutation` and it defaults to the latter * throw 400 when a query action is tried to explain * update the actions docs to include query actions * refactor the ToJSON and ToOrdJSON of ActionDefinition Co-authored-by: Rishichandra Wawhal <rishi@hasura.io> Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
59 lines
1.5 KiB
ReStructuredText
59 lines
1.5 KiB
ReStructuredText
.. meta::
|
|
:description: Async actions
|
|
:keywords: hasura, docs, actions, async actions
|
|
|
|
.. _async_actions:
|
|
|
|
Async actions
|
|
=============
|
|
|
|
.. contents:: Table of contents
|
|
:backlinks: none
|
|
:depth: 1
|
|
:local:
|
|
|
|
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.
|
|
|
|
.. admonition:: Note
|
|
|
|
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
|
|
|
|
.. code-block:: graphql
|
|
|
|
mutation placeOrderRequest($order_input: place_order_input!) {
|
|
place_order(input: $order_input)
|
|
}
|
|
|
|
Executing this mutation will return a response like:
|
|
|
|
.. code-block:: json
|
|
|
|
{
|
|
"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``.
|
|
|
|
.. code-block:: graphql
|
|
|
|
subscription getPlaceOrderResponse {
|
|
place_order (id: "23b1c256-7aff-4b95-95bd-68220d9f93f2") {
|
|
output
|
|
errors
|
|
}
|
|
}
|
|
|