hasura / hasura/graphql-engine
Allow bulk mutations via SQL functions
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
I would like to encapsulate data invariant in the interface to prevent impossible states. In practice this involves writing a stored producer that takes in a record and distributes relevant pieces of it into relevant tables, sometimes deriving computed values from the input.
However currently such functions are can only work with single entities and are more or less correspond to `insert_*_one` mutations.
### Describe the solution you'd like
I would like hasura graphql-engine to exposed batch mutations for tracked VOLATILE functions just like it exposes `insert_*` mutations. Which either could be a default or something you can configure through metadata.
Personally I think it would be best if e.g VOLATILE function `add_task(done boolean, name text)` would map to two mutations:
1. That does bulk mutations e.g. `add_task(objects:{done:Boolean!, name:String!}[]!, ...)`
2. That does single mutation e.g. `add_task_one(object:{done:Boolean!, name:String!}, ...)`
### Describe alternatives you've considered
- Using mutation aliases to work around this limitation, however it does not really work well when you need to add an array of things and then turn results back back into array. I'm also not sure if a failure in one would fail them all or not.
- Using jsonb as an input arg, downside of this approach (if viable at all) that no typing information will be provided.
### If the feature is approved, would you be willing to submit a PR?
Provided a mentor, I might
Contributor guide
Research direction
Start by locating the code that exposes tracked PostgreSQL VOLATILE functions as GraphQL mutations and read how existing insert_* and insert_*_one mutations are generated. Define how typed bulk inputs, result arrays, metadata configuration, and failure behavior should work; done means bulk and single function mutations are consistently exposed and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, postgres, sql
- Domain
- api, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100