Then I would find myself not using any of the generated mutations and writing everything with custom lambdas. Sort of why we are using Dgraph GraphQL right now, so we don’t have to write custom resolvers.
Consider this schema:
type User {
username: String @id
name: String!
created: DateTime!
updated: DateTime
posts: [Post] @hasInverse(field: author)
comments: [Comment] @hasInverse(field: author)
assigned: [Tasks] @hasInverse(field: assignee)
friends: [User] @hasInverse(field: friends)
}
type Post {
id: ID
title: String!
author: User!
comments: [Comment] @hasInverse(field: onPost)
replies: [Comment] @hasInverse(field: replyTo)
revisions: [Post]
created: DateTime!
updated: DateTime
}
type Comment {
id: ID
content: String!
onPost: Post
replyTo: Comment
revisions: [Comment]
created: DateTime!
updated: DateTime
}
type Task {
id: ID
content: String!
due: DateTime!
assignee: User
created: DateTime!
updated: DateTime
}
So of course all of the updated fields would work somewhat well as all using custom lambda mutations. I could then turn off all of the generated updateType mutations with the @generate function. But what about adding a complete subgraph at once. Right now it works with addUser, addPost, addComment, addTask. I can add something complex like this:
from a new User:
const newUser = {
username: "foo",
posts: [{
title: "bar",
comments: [{
content: "Lorem Ipsum",
}]
}]
assigned: [{
content: "Do This",
due: "2022-01-11"
}]
}
Or from a new Task:
const newTask = {
content: "Do This",
due: "2022-01-11",
assignee: {
username: "foo",
posts: [{
title: "bar",
comments: [{
content: "Lorem Ipsum",
}]
}]
}
}
Or from a new Post:
const newPost = {
title: "bar",
comments: [{
content: "Lorem Ipsum",
}]
author: {
username: "foo",
assigned: [{
content: "Do This",
due: "2022-01-11"
}]
}
}
Or from a new Comment
const newComment = {
content: "Lorem Ipsum",
author: {
username: "foo",
assigned: [{
content: "Do This",
due: "2022-01-11"
}]
}
onPost: {
title: "bar",
author: {
username: "foo"
}
}
}
So I would have to create custom add mutations for each of these handling also all of the connected custom add mutations because they all have a required created field that should be filled with a lambda.
Now I want to expand my schema and add a new type such as Tag that does not need to manage created and updated fields, so how do I do that? I would then need to use a custom addTag mutation for it because if I use just the generated addTag then if I added a new tag with any referenced post it would not add the created Field as required.
So here is the need for hooks on generated mutations instead of just the ability to write custom mutation resolvers in a lambda.
Edit:
Furthermore, to make all of these custom addMutations, I would have to rethink disable all of the generated add mutations. But then how would I add the data from a lambda without having the generated graphql add mutations? I guess I could use DQL, but then that bypasses all of the auth rules. So then I find myself not using the auth rules in GraphQL except for query. At this point instead of generated queries and mutations, I would just have generated queries and all of my mutations would be custom resolvers. At what point then do I realize that I am doing more work instead of less and stop using the graphql endpoint and just go and create my own using DQL or some other database. If everything is custom resolved then honestly I lost all the benefit of using the GraphQL endpoint at all.