Say I have a book-sharing app, and given say a user with a collection of favorite books, when adding a favorite book is the most common best practice that we just use editUser mutation and update their collection of favorites in the user object itself, or use a named addFavorite mutation that just sends along the book to add?
type Book {
title: String
author: Author
}
type User {
name: String
address: Address
favorites: [Book]
}
My opinion is that it's clearer and better to have a named mutation for addFavorite since it's the key use case and it's clearer to have mutations that add relationships rather than having it implied through the update of another object.
mutation AddFavorite($userId: ID!, $book: BookInput!) {
addFavorite(userId: $userId, book: $book)
}
vs
mutation EditUser($userId: ID!, $input: UserInput!) {
editUser(userId: $userId, input: $input) {
}
input UserInput {
name: String
address: Address
addFavorite: [Book!]
}