如何使用装饰器 ObjectType 正确定义类并扩展 PickType?

时间:2021-05-11 13:27:17

标签: graphql nestjs

我只想创建 ObjectType 类,它只是由 TranslationImportBase 在 nestjs 中使用 graphql 创建的 PickType。

@Entity()
@ObjectType({ isAbstract: true })
export class TranslationImportBase {
  @Field(() => Int)
  @PrimaryGeneratedColumn({ type: 'int', name: 'id' })
  id: number;

  @Field(() => User, { nullable: true })
  @ManyToOne(() => User)
  importedBy: User;

  @Field(() => GraphQLISODateTime, { nullable: true })
  @Column({ type: 'datetime' })
  imported: Date;

  @Field(() => String)
  @Column('varchar', { length: 20, nullable: true })
  sourceLanguage: string;

  @Field(() => String)
  @Column('varchar', { length: 20, nullable: true })
  targetLanguage: string;
}

export class LastTranslationsImport 
  extends PickType(
    TranslationImportBase, 
    ['imported', 'importedBy', 'targetLanguage', 'sourceLanguage'],
  ) 
  {}

在这种情况下,我遇到了错误: Error: Cannot determine a GraphQL output type for the "lastTranslationImport". Make sure your class is decorated with an appropriate decorator

但是当我添加 @ObjectType() 装饰器时,我收到了这个错误: GraphQLError: Type LastTranslationsImport must define one or more fields

所以我有点卡住了。您知道如何正确定义 LastTranslationsImport 吗?

0 个答案:

没有答案