Mongoose 将Typegoose与GraphQL结合使用

Mongoose 将Typegoose与GraphQL结合使用,mongoose,graphql,nestjs,typegoose,Mongoose,Graphql,Nestjs,Typegoose,我正在尝试将typegoose与graphql结合使用。我在另一个对象中有一个嵌套对象列表。我对这些类的定义如下 @ObjectType() export class ChildClass { @prop() @Field({ nullable: true }) someField: string; @prop() @Field({ nullable: true }) anotherField: string; } @ObjectType() @modelOption

我正在尝试将typegoose与graphql结合使用。我在另一个对象中有一个嵌套对象列表。我对这些类的定义如下

@ObjectType()
export class ChildClass {
  @prop()
  @Field({ nullable: true })
  someField: string;

  @prop()
  @Field({ nullable: true })
  anotherField: string;
}

@ObjectType()
@modelOptions()
export class ParentClass extends Typegoose {
  @prop()
  @Field(() => String)
  someField: string;

  @prop()
  @Field(() => [ChildClass], { nullable: 'itemsAndList' })
  children: ChildClass[];
}
当我调用下面的查询时

query {
  parentClass {
    someField
    children {
      someField
      anotherField
    }
  }
}
对于孩子们的
someField
anotherField
,它总是给我
null
。但是,如果我使用mongoose而不是typegoose,它会正常工作。MongoDb在使用typegoose时恢复良好。到graphql的转换是不可靠的


我在这里遗漏了什么?

经过一番修改,终于明白了为什么会发生这种情况。将模型更新为

  @prop( { type: () => [ChildClass] } )
  @Field(() => [ChildClass], { nullable: 'itemsAndList' })
  children: ChildClass[];
他会变魔术。按照