-
-
Notifications
You must be signed in to change notification settings - Fork 675
An example of the nested mutation #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Nested mutations sound nice, I haven't thought about it but it seems possible to do. However, about the resolver inheritance part:
We've already discussed it: |
@limenutt In GraphQL spec, So the problem is that clients could do parallel mutation by e.g.: mutation {
project {
add(input: { name: "test2" }) {
id
}
edit(input: { id: 2, name: "test2 edit" }) {
id
}
delete(id: 2) {
id
}
}
} And as they're resolvers are attached to But by design, mutation are changing the app/server state so they have to be reliable. So I think that this approach to designing schema doesn't give any improvements to the clients, just have negative impacts. As you will have generic service for common business logic, it's easy to create separate one-line resolvers with mutations like If this answer exhaust the topic, please close the issue 😉 |
Thank you, I appreciate your prompt thorough response! |
Just adding my opinion this would be awesome to have. There are examples of mainstream API's taking this tact successfully. In my experience, having resolvers at root level results in an anemic domain model and should be avoided if possible. |
I have no idea why nesting might help you with domain model. If you want to have: query {
user {
create(...) {
# ...
}
}
} you can just join the two words into a one camelCase'd: mutation {
userCreate(...) {
# ...
}
} TypeGraphQL let define such schema in a decoupled fashion. Instead of adding
GraphQL is designed around root level queries and mutations and you need to live with this. |
It wasn't immediately clear to me how to make this work, so here's some example code to help anyone else trying to do this:
|
It would be cool to be able to nest mutations to get work done in fewer requests. Imagine you want to add an createAuthor(input: $authorInput) {
name
createBook(input: $bookInput) {
title
}
} That'd be neat. But it is not currently part of the Graphql spec, see the discussion here. |
Hi!
First of all, great library, thanks a lot!
I'm currently building a graphql API and want to make it as generic as possible.
I have many objects and want to have same generic mutations for each object type (create, update and delete). At the moment, I have implemented a resolver for each of my object types, each with it's methods so I can update my objects like this:
Is there a way to instead nest the mutation under the object name, like so
In this case I could implement the basic mutations (add, update and delete) in the base resolver class and just inherit from it in object-specific resolvers, maybe use some decorators to override the input types.
The text was updated successfully, but these errors were encountered: