我想知道如何在嵌套类型中应用mutation
,graphql-tag
因为在 prisma 中我create
用来分配字段
我的datamodel.graphql
type Item {
id: ID! @id @unique
title: String
description: String
price: Int
laptop: Laptop @relation(link: INLINE)
}
type Laptop {
id: ID! @id
brand: String
}
我的schema.graphql
type Mutation {
createItem(
title: String
description: String
price: Int
laptop: LaptopCreateOneInput
): Item!
}
到目前为止我确实尝试过,但它没有用
const CREATE_ITEM_MUTATION = gql`
mutation CREATE_ITEM_MUTATION(
$title: String!
$description: String!
$price: Int!
$laptop: LaptopCreateOneInput
) {
createItem(
title: $title
description: $description
price: $price
laptop:$laptop
) {
id
}
}
`;
我可以像这样在graphql操场上应用突变
mutation {
createItem(
title: "computer"
description: "some computer"
price: 1000
laptop: { create: { brand: "some brand" } }
) {
title
description
}
}