I have the following GraphQL schema. It has Books
and Authors
with a many to many relationship. How do I create a new Book mutation for an existing Author?
schema
type Author implements Node {
books: [Book!]! @relation(name: "BookAuthors")
createdAt: DateTime!
id: ID! @isUnique
name: String!
updatedAt: DateTime!
}
type Book implements Node {
authors: [Author!]! @relation(name: "BookAuthors")
createdAt: DateTime!
id: ID! @isUnique
title: String!
updatedAt: DateTime!
}
mutation
mutation CreateBook($title: String!, $authors: [Author!]) {
createBook(
title: $title,
authors: $authors,
) {
id
title
}
}
variables
{
"title": "Ryans Book",
"authors": ["cj5xti3kk0v080160yhwrbdw1"]
}