【问题标题】:GraphQL type 'Object'?GraphQL 类型“对象”?
【发布时间】:2019-10-15 05:49:54
【问题描述】:

我有一个这样的 MongoDB mongoose 架构:

const playerSchema = Schema({                    
    conditions: { type : Object },                 
    date: String    
}) 

这样的集合:

{
 _id: 5cee935cb56d5f794b452d78,
 conditions:
 { 
    condition_a: [5.9, 6.0],
    condition_b: [6.1, 4.9],
    condition_c: [4.9, 4.0]
 },     
 date: 'Wed May 29 2019 16:45:00 GMT+0200 (GMT+02:00)',
},
{
 _id: 5cee935cb56d5f794b452d70,
 conditions:
 { 
    condition_a: [5.8, 6.1],        
    condition_c: [4.3, 3.0]
 },     
 date: 'Wed May 29 2019 16:47:00 GMT+0200 (GMT+02:00)',
},
[...]

如何为此制作 GraphQL Schema? 我已经尝试过这样的事情

buildSchema(`
 type Player {
    _id: ID!    
    condition: Object         
    date: String         
 }
`)

也试过了:[[String]]{}{String} ... 没有运气

不能选择包含条件和与Player 关系的集合。

【问题讨论】:

    标签: mongodb mongoose graphql express-graphql


    【解决方案1】:

    解决方法:

    type Condition {
        condition_a: [String],
        condition_b: [String],
        condition_c: [String],    
    }
    
    type Player {
        _id: ID!    
        condition: Condition         
        date: String         
     }
    

    【讨论】:

      猜你喜欢
      • 2019-05-17
      • 2018-08-15
      • 2020-05-29
      • 2020-07-02
      • 2021-10-09
      • 2018-04-07
      • 2023-03-03
      • 2021-09-12
      • 2018-02-02
      相关资源
      最近更新 更多