hasura / hasura/graphql-engine
Insert an object along with its related objects through relationships for MS SQL Server
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
Hello, it would be great if Hasura for MS SQL Server supported inserts for related objects like it does for PostgreSQL. For example the example given in the Hasura docs for PostgresSQL [here](https://hasura.io/docs/latest/graphql/core/databases/postgres/mutations/insert/#one-to-one--one-to-many-relationships) or down below:
```graphql
mutation insertData {
insert_authors
(objects: [
{
name: "John",
address: {
data: {
location: "San Francisco"
}
},
articles: {
data: [
{
title: "GraphQL Guide",
content: "Let's see what we can do with GraphQL"
},
{
title: "Authentication Guide",
content: "Let's look at best practices for authentication"
}
]
}
}
]
) {
affected_rows
returning {
id
name
address_id
address {
id
location
}
articles {
id
title
author_id
}
}
}
}
```
The only really way around this that I can see is to do multiple mutations for each table for example in Apollo:
```javascript
const [addAuthor] = useMutation(ADD_AUTHORS);
const {author} = addAuthor(variables: authorsInput)
const [addArticles] = useMutation(ADD_ARTICLES);
const {article} = addArticles(variables: { author_id: author.id, ...articlesInput})
...etc
```
Which can get complicated very quickly and also doesn't allow any rollback if any of the mutations fails.
I am not familiar with Hasura codebase but if it is a feature not planning to be released anytime soon then I might be willing to submit a PR if you point me in the right direction.
Contributor guide
Research direction
Start with the linked Hasura PostgreSQL relationship-insert documentation and compare that behavior with the MS SQL Server mutation API. No implementation files or tests are named in the issue; done would mean supporting nested related-object inserts for MS SQL Server with rollback behavior when a mutation fails.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, sql
- Domain
- api, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100