reactjs - prisma中嵌套类型的相应graphql-tag突变
问题描述
我想知道如何在嵌套类型中应用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
}
}
解决方案
create
我确实通过用word更新状态来使它工作
state = {
title: '',
price: 0,
laptop: {
create: {
brand: ''
}
},
description: '',
};
推荐阅读
- javascript - 这个解决方案可以替代 O(n^2) 或 O(n*m) 算法还是仍然是 O(n^2) 或 O(n*m) 算法?
- php - Laravel 8 Livewire 搜索过滤器不适用于第一个 where 子句
- visual-studio - Visual Studio 2010 中有用的多行字符串监视窗口在较新版本中的位置在哪里?
- html - 离子标签按钮在选择时不会改变颜色
- postgresql - Postgres 获取足够的视图信息来重现它
- python - 为数据点查找集群的简单方法是什么?
- codesign - 公证和签名后无法运行应用程序
- azure-application-insights - 应用程序洞察警报与可配置的电子邮件收件人和电子邮件正文的通知?
- arrays - 在 C 上处理 CSV 存档和结构数组时出现问题
- latitude-longitude - 在 OSRM 查询中查找无效坐标(纬度和经度)