hasura / hasura/graphql-engine
Send results of a specified query to action handlers
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
I propose an extension to actions that would allow you to specify a query that's run as part of its associated action, with the result of the query included in the request to the action handler.
The arguments passed to the action's mutation field would be converted to a JSON object and used as the variables for the query. This would allow, for example, an action handler to be passed relevant fields of an entity when only the primary key of the entity was passed as an argument. Currently, if an action handler needs more information associated with the mutation arguments, it must perform a query itself, resulting in an extra network round-trip back to the graphql-engine server.
For example, given the following action definition:
```
type Mutation {
perform_widget_calculation_by_pk (
id: ID!
): widget_calculation_response
}
type widget_calculation_response {
widget_id : ID!
widget: widget!
result : Int!
}
```
...the following query could be defined:
```
query {
widget_by_pk(id: $id) {
pitch
roll
yaw
}
}
```
...with the variables derived from the mutation's arguments, e.g. if the mutation was called with `id: "123"`, then the variables object would be `{"id": "123"}`.
The action handler request would then include the query response somewhere in its body, and it could perform calculations on the widget's `yaw`, `pitch`, and `roll` without having to look them up itself.
Contributor guide
Research direction
No files, tests, or entry points are named. Start by tracing how action mutation arguments become action-handler requests, then determine where a configured query could use those arguments as variables and where its response would be added; done means the handler receives that query result without making a second request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100