diff --git a/docs/docs/actions/create.mdx b/docs/docs/actions/create.mdx index 18e8e5884ce..4b02d62dae6 100644 --- a/docs/docs/actions/create.mdx +++ b/docs/docs/actions/create.mdx @@ -1,6 +1,6 @@ --- sidebar_label: Create Actions -sidebar_position: 1 +sidebar_position: 3 description: Create Hasura Actions keywords: - hasura diff --git a/docs/docs/actions/index.mdx b/docs/docs/actions/index.mdx deleted file mode 100644 index 4cbc61520fa..00000000000 --- a/docs/docs/actions/index.mdx +++ /dev/null @@ -1,163 +0,0 @@ ---- -description: Hasura Actions -keywords: - - hasura - - docs - - actions -slug: index -title: Actions ---- - -import Thumbnail from '@site/src/components/Thumbnail'; -import Actions from '@site/static/icons/features/actions.svg'; - -# Actions - -## What are Hasura Actions? - -Actions are a way to extend Hasura's schema with custom business logic using custom queries and mutations. Actions can -be added to Hasura to handle various use cases such as data validation, data enrichment from external sources and any -other complex business logic. - - - -:::tip Supported from - -Actions are supported in Hasura GraphQL Engine versions `v1.2.0` and above. - -Actions are supported for **Postgres versions 10 and above**. - -::: - -## Action description - -An action consists of the following parts: - -1. `Type`: The type of the action (`query` or `mutation`) -2. `Definition`: The definition of the query or mutation -3. `Handler`: The logic to be run when the query or mutation is executed -4. `Kind`: Sync or async. In case of a query action, there is no `Kind` associated with it. A query action is always - sync - -### Type - -Actions can be of two types: - -- **Query action**: An action of type `query` extends the query root of the Hasura schema. This means that you can - execute this action through a GraphQL query. Query Actions must be used where you want to fetch data from a data - source without changing anything on the data source. -- **Mutation action**: An action of type `mutation` extends the mutation root of the Hasura schema. This means that you - can execute this action through a GraphQL mutation. Mutation Actions must be used when you want to mutate the state of - a data source and fetch some data. - -### Definition - -The action definition consists of the following: - -- `Action Name`: The action will be available as a query or mutation in the GraphQL schema named as the action name -- `Arguments`: Arguments are used to pass dynamic values along with the query/mutation. -- `Response type`: The GraphQL type of the response that the query or mutation will return. Action response types - support objects, scalars and lists of those only. - -For instance, consider this action definition: - -```graphql -type Mutation { - userLogin(username: String!, password: String!): UserInfo -} -``` - -In case the action response is a scalar (eg. Int), the action can also be defined as: - -```graphql -type Mutation { - userLogin(username: String!, password: String!): Int! -} -``` - -In this definition, we are extending the mutation root with an action called `userLogin`. - -- `userLogin` is the action name -- `username` and `password` are the arguments that accept non-nullable string values. -- `UserInfo` is the response type of the action - -**Custom Types** - -In case the action returns an object type, you will have to define your custom types like so: - -```graphql -type UserInfo { - accessToken: String! - userId: Int! -} -``` - -Read more about [custom types](/actions/types.mdx). - -### Handler - -Once you define the action types, you also have to specify the logic to run when the action is executed. This can be -done in an HTTP webhook, also called the action handler. It could be a REST endpoint or a serverless function. - -Learn more about [writing an action handler](/actions/action-handlers.mdx). - -### Kind - -**Mutation Actions** are of two kinds: - -- **Synchronous**: Sync Actions return a response to the client after receiving a response from the handler. -- **Asynchronous**: [Async Actions](/actions/async-actions.mdx) return an `action id` as response to the client before - receiving a response from the handler and allow the client to subscribe to the actual response using the `action id`. - -**Query Actions** don't have a kind, they always behave like sync mutation Actions. - -## How it works? - -- Hasura receives the action GraphQL query or mutation and converts this request into an event payload. -- The event is captured, persisted and then delivered to the action handler with the appropriate retry/delivery - guarantees. -- The Action handler runs and returns a response that is captured as an event and again persisted to the event store. -- The Action response is returned to the client synchronously or asynchronously based on the kind. - -## Actions vs. Remote Schemas - -Both Actions and Remote Schemas can be used to extend Hasura with business logic. However, they have slightly different -use cases. - -**Actions** - -Actions can be used when we want to call a REST endpoint from Hasura as a resolver for some custom types. They are -especially useful for setting up serverless functions as resolvers. - -**Remote Schemas** - -If you have an existing GraphQL API or if you're comfortable building a GraphQL server yourself, you can use -[Remote Schemas](/remote-schemas/index.mdx) to add custom types and resolvers. - -## Learn more - -- [Creating Actions](/actions/create.mdx) -- [Custom types](/actions/types.mdx) -- [Action handlers](/actions/action-handlers.mdx) -- [Async Actions](/actions/async-actions.mdx) -- [Codegen](/actions/codegen/index.mdx) -- [Deriving Actions](/actions/derive.mdx) -- [Actions permissions](/actions/action-permissions.mdx) -- [Actions relationships](/actions/action-relationships.mdx) -- [REST Connectors for Actions](/actions/rest-connectors.mdx) -- [Debugging Actions](/actions/debugging.mdx) -- [Cleaning up async Action logs](/actions/logs-clean-up.mdx) - - - -:::info Additional Resources - -- Introduction to Hasura Actions - - [View Recording](https://hasura.io/events/webinar/hasura-actions/?pg=docs&plcmt=body&cta=view-recording&tech=) -- Custom Business Logic - [Learn Tutorial](https://hasura.io/learn/graphql/hasura/custom-business-logic/) - -::: diff --git a/docs/docs/actions/overview.mdx b/docs/docs/actions/overview.mdx new file mode 100644 index 00000000000..74caa4eadc6 --- /dev/null +++ b/docs/docs/actions/overview.mdx @@ -0,0 +1,80 @@ +--- +description: Hasura Actions +title: Overview +keywords: + - hasura + - docs + - actions +hide_table_of_contents: true +sidebar_position: 1 +--- + +import Thumbnail from '@site/src/components/Thumbnail'; +import VersionedLink from '@site/src/components/VersionedLink'; +import Actions from '@site/static/icons/features/actions.svg'; + +# Actions + +
+
+

+ Actions are a convenient and secure way to connect to REST APIs to achieve any business logic you may need, + directly from your GraphQL API. +

+

+ Maybe you need to validate, process or enrich some data, call another API, or log a user in. With Actions you can + connect to a REST endpoint which can be your own custom server, a public API, or a serverless function. +

+

+ You can also apply transforms to your payloads and responses and handle the response to your GraphQL client + asynchronously, subscribing to results as they occur. +

+

Quick Links

+
    +
  • + Get started with Actions in 60 seconds. +
  • +
  • + Learn how Actions work. +
  • +
+
+