语法错误GraphQL预期名称,找到的字符串

问题描述 投票:-1回答:1

我正在尝试在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中出现错误例外名称,但是找到了字符串,因为对象包含1作为字符串。我该如何解决。我需要将这种类型的对象存储在“我的数据库”中。有人可以帮我吗?

Error Image

node.js graphql syntax-error apollo apollo-server
1个回答
0
投票

GraphQL支持严格的数据键入。因此,基本上,您不能将字符串作为属性键,因为那将意味着它不知道要反序列化的内容。另外我不确定JSON是否是数据类型。我知道字符串和类型,但不知道JSON。您可能有一个类似的对象:

type Product { 
    product : String,
    product_status : ProductStatus
}

type ProductStatus {
    id: ID,
    order: String,
}

这是您如何设计它的方法。

© www.soinside.com 2019 - 2024. All rights reserved.