[英]corresponding graphql-tag mutation of nested types in prisma
i wonder how you can apply mutation
using graphql-tag
in nested types because in prisma i use create
to assign fields我想知道如何在嵌套类型中使用graphql-tag
应用mutation
,因为在 prisma 中我使用create
来分配字段
my datamodel.graphql
我的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
}
my schema.graphql
我的schema.graphql
type Mutation {
createItem(
title: String
description: String
price: Int
laptop: LaptopCreateOneInput
): Item!
}
i did try this so far but it didnt work到目前为止我确实尝试过,但它没有用
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
}
}
`;
i can apply mutation in graphql playground like this我可以像这样在 graphql 操场上应用突变
mutation {
createItem(
title: "computer"
description: "some computer"
price: 1000
laptop: { create: { brand: "some brand" } }
) {
title
description
}
}
i did make it work by updating the state with create
word我确实通过使用create
word 更新 state 使它工作
state = {
title: '',
price: 0,
laptop: {
create: {
brand: ''
}
},
description: '',
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.