2
我有以下的GraphQL架構。它有Books
和Authors
與多對多的關係。如何爲現有作者創建新的書籍變體?Graphcool/GraphQL創建關係的變異
模式
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 CreateBook($title: String!, $authors: [Author!]) {
createBook(
title: $title,
authors: $authors,
) {
id
title
}
}
變量
{
"title": "Ryans Book",
"authors": ["cj5xti3kk0v080160yhwrbdw1"]
}
這顯然被稱爲連接變異。可以在這裏找到答案:https://www.graph.cool/docs/reference/simple-api/nested-connect-mutations-tu9ohwa1ui/ –
請注意,這是特定於Graphcool API :)此外,請隨時[回答你自己的問題](https://stackoverflow.com/help/self-answer)。 – marktani