TriPSs / nestjs-query

Easy CRUD for GraphQL.
https://tripss.github.io/nestjs-query/
MIT License
164 stars 46 forks source link

Option to update multiple #262

Open RyanLackie opened 6 months ago

RyanLackie commented 6 months ago

Is your feature request related to a problem? Please describe. Hey 👋

@TriPSs I saw your feature request in the original project by Doug Martin.

This is a similar situation I am running into where ideally I would send a single mutation request to update multiple records with their own values. The same structure could be used to update a parent object along with multiple (one to many) related children too, each with their own values.

This is similar to what mutations Hasura supports.

Is this something you think nestjs-query would eventually support? I'm not familiar with what changes would be needed to support this functionality but I imagine it could be a large undertaking.

Have you read the Contributing Guidelines?

Yes

Describe the solution you'd like Along with the normal update many mutation:

mutation {
  updateManyTodoItems(
    input: { filter: { id: { in: [1, 2] } }, update: { completed: true } }
  ) {
    updatedCount
  }
}

Also being able to process inputs that look like:

mutation {
  updateManyTodoItems(
    input: [
        { id: 1, update: { completed: true },
        { filter: { id: { in: [2, 3] } }, update: { completed: false }
    ]
  ) {
    updatedCount
  }
}

and

mutation {
  updateOneTodoItem(
    input: {
        id: 1,
        update: {
            childTodoItems: {
                input: [
                   { id: 1, update: { completed: true },
                   { filter: { id: { in: [2, 3] } }, update: { completed: false }
                ]
            }
        }
    }
  ) {
    updatedCount
  }
}

Describe alternatives you've considered Alternatively the client could orchestrate these requests which isn't that bad of a problem, however allowing this tool to take on that responsibility would massively reduce the code and complexity the client would need to handle.