gqlify
gqlify copied to clipboard
Atomic operation on nested array in GraphQL API
Is your feature request related to a problem? Please describe.
We should provide atomic operation like add, remove, set operation for nested array type.
Describe the solution you'd like
type Tag {
name: String
}
type Book @GQLifyModel(dataSource: "firebase", key: "Book") {
id: ID! @unique @autoGen
name: String!
tags: [Tag]
}
Right now, we can only override the whole field with another array.
We should provide graphQL api like:
mutation {
# add a new tag
updateBook(where: {id: "1"}, data: {tags: {add: {name: "new tag"}}}) {
id
}
}
Additional context There are things we need to consider, for example:
- In terms of
remove, how do we match the element to be removed? Do we only remove one element matched? or all matched? - Different data-source has different way to handle nested array operation, how do we deal with it? for example:
- Mongo: https://docs.mongodb.com/manual/reference/operator/update-array/
- Firestore: https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array