Remove all and set new children of hasMany relation using nested mutation `@update`
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.5k
- Forks
- 468
- Avg merge
- 3h 9m
- Merged PRs (30d)
- 2
Description
What problem does this feature proposal attempt to solve?
I read about nested mutations and Ligthouse's 'shortcuts' to quickly manipulate objects in a hasMany relationship using these features:
type Mutation {
updateUser(input: UpdateUserInput! @spread): User @update
}
input UpdateUserInput {
id: ID!
name: String
posts: UpdatePostsHasMany
}
input UpdatePostsHasMany {
create: [CreatePostInput!]
update: [UpdatePostInput!]
upsert: [UpsertPostInput!]
delete: [ID!]
connect: [ID!]
disconnect: [ID!]
}
However, I often find myself having to clear all 'children' objects and create & connect new ones from the client side.
Currently, I solve this by first querying the IDs of all children and deleting them using delete: [ID!]. Followed by a create: [CreatePostInput!] where I can submit objects that are not yet in the database.
My feature proposal combines the deletion of old hasMany-items, creation of the new ones, and connecting the new ones to the parent object. This makes client-side code easier and, when using transactions, makes code more stable: If the client-side code requests the delete, and the creation of the new records fails, the parent is left without its children.
Which possible solutions should be considered?
To make this pattern easier I propose a set: [CreatePostInput!] which first deletes all children (in this example: Posts), after which it creates new posts from the input and immediately connects them to the parent (in this example: User).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Lighthouse nested mutations documentation, especially the hasMany shortcuts and the existing create, delete, connect, and disconnect operations. Trace how the @update mutation handles hasMany input and determine the transaction behavior needed for a proposed set operation. Done means the operation removes existing children, creates the supplied records, and connects the new records to the parent atomically.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, laravel, php
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100