node.js - 语法错误 GraphQL 预期名称,找到字符串
问题描述
我正在尝试在 GraphQL 中实现突变。我正在使用 GraphQL Play Ground Ui 进行查询。
这是我的突变:
mutation{
createProduct (data :{
product: "abc",
product_status : {
"1" : {
order : "done"
}
}
这是我的 TypeDef
type Product {
product : String,
product_status : JSON
}
但是我在 product_status exceptioned Name 中遇到错误,但发现 String as object contains 1 as string。我该如何解决这个问题。我需要将这种类型的对象存储在我的数据库中。有人可以帮我解决这个问题。
解决方案
GraphQL 支持严格的数据类型。所以基本上你不能将字符串作为属性键,因为这意味着它不知道要反序列化成什么。另外我不确定 JSON 是否是一种数据类型。我知道字符串和类型,但不知道 JSON。你可以有一个像这样的对象:
type Product {
product : String,
product_status : ProductStatus
}
type ProductStatus {
id: ID,
order: String,
}
这就是你可以设计它的方式。
推荐阅读
- python - 在 end=' ' 之后打印语句
- dictionary - 如何在实际地图中转换字符串“key:value”?
- python - 我在做什么错以及如何使用 python 的 asyncio 调试内存泄漏?
- python - mypy:多种类型的类型注释列表的正确方法
- python - 从 csv 文件中获取数据
- kotlin - Kotlin:Ktor 如何将文本响应为 html
- java - JavaFX - 键盘事件不处理
- c - C“'struct.pointer''.'中的结构错误中的指针 出乎意料的“
- c++ - 为什么这个程序对 throw 不做任何事情?
- c++ - C++ 线程找不到函数作为参数(链接器)