GraphQL类型为“对象”?

时间:2019-05-29 15:02:46

标签: mongodb mongoose graphql express-graphql

我有一个像这样的MongoDB猫鼬模式:

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模式? 我已经尝试过这样的事情

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

也尝试过:[[String]]{}{String}……没有运气

使用具有与Player的条件和关系的集合是不可选项。

1 个答案:

答案 0 :(得分:0)

解决了:

type Condition {
    condition_a: [String],
    condition_b: [String],
    condition_c: [String],    
}

type Player {
    _id: ID!    
    condition: Condition         
    date: String         
 }