mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
docs: add action response transform
This PR adds docs for the console support of action response transform. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6622 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Sean Park-Ross <94021366+seanparkross@users.noreply.github.com> GitOrigin-RevId: 215b6df9fc7e7f27e4cbd9798ba5a97d66b91138
This commit is contained in:
parent
c92988bcbf
commit
2bc05c1697
@ -728,6 +728,98 @@ X-Hasura-Role: admin
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### Response Body
|
||||
|
||||
You can transform the default body of your HTTP API response by configuring a response transform template. This can
|
||||
be used to match the output types defined in your Action with your HTTP API.
|
||||
|
||||
:::info Note
|
||||
|
||||
Response transforms are applicable only for JSON responses.
|
||||
|
||||
:::
|
||||
|
||||
<Tabs className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
In the `Configure REST Connectors` section, click on `Add Response Transform`:
|
||||
|
||||
<Thumbnail
|
||||
src="/img/actions/transform-response_actions_2.13.png"
|
||||
alt="response transform method"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
Hit `Create Action` to apply your changes.
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Update the `actions.yaml` file inside the `metadata` directory and add a [response_transform][responsetransformation]
|
||||
field to the Action:
|
||||
|
||||
```yaml {6-9}
|
||||
- name: create_user
|
||||
definition:
|
||||
kind: synchronous
|
||||
handler: https://action.my_app.com/create-user
|
||||
timeout: 60
|
||||
response_transform:
|
||||
template_engine: Kriti
|
||||
version: 2
|
||||
body: '{"action": "transform", "template": "{\n \"test\":{{$body.input.arg1.id}}\n}"}'
|
||||
```
|
||||
|
||||
Apply the metadata by running:
|
||||
|
||||
```bash
|
||||
hasura metadata apply
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
REST Connectors can be configured for Actions using the [create_action][metadata-create-action] or
|
||||
[update_action][metadata-update-action] metadata APIs by adding a [response_transform][responsetransformation] field to
|
||||
the args:
|
||||
|
||||
```http {24-29}
|
||||
POST /v1/metadata HTTP/1.1
|
||||
Content-Type: application/json
|
||||
X-Hasura-Role: admin
|
||||
|
||||
{
|
||||
"type":"create_action",
|
||||
"args":{
|
||||
"name":"create_user",
|
||||
"definition":{
|
||||
"kind":"synchronous",
|
||||
"arguments":[
|
||||
{
|
||||
"name":"username",
|
||||
"type":"String!"
|
||||
},
|
||||
{
|
||||
"name":"email",
|
||||
"type":"String!"
|
||||
}
|
||||
],
|
||||
"output_type":"User",
|
||||
"handler":"{{ACTION_BASE_URL}}",
|
||||
"timeout":60,
|
||||
"response_transform": {
|
||||
"template_engine": "Kriti",
|
||||
"version": 2,
|
||||
"body": {"action": "transform", "template": "{\n \"test\":{{$body.input.arg1.id}}\n}"},
|
||||
"comment": "Custom action to create user"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## Example
|
||||
|
||||
Let's integrate Auth0's management API to update the profile of a user:
|
||||
@ -789,3 +881,4 @@ The transform is given by:
|
||||
[metadata-create-action]: /api-reference/metadata-api/actions.mdx#metadata-create-action
|
||||
[metadata-update-action]: /api-reference/metadata-api/actions.mdx#metadata-update-action
|
||||
[requesttransformation]: /api-reference/syntax-defs.mdx#requesttransformation
|
||||
[responsetransformation]: /api-reference/syntax-defs.mdx#responsetransformation
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 230 KiB |
BIN
docs/static/img/actions/transform-response_actions_2.13.png
vendored
Normal file
BIN
docs/static/img/actions/transform-response_actions_2.13.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 228 KiB |
Loading…
Reference in New Issue
Block a user