Nestjs-Mongoose-虚拟字段-无法在graphql游乐场中查询



我正试图在nestjs mongoose中创建一个虚拟字段。代码没有显示任何错误,但我无法查询graphql游乐场中的虚拟字段。

我厌倦了使用schema.virtual("virtualFieldName"(添加虚拟字段。然后,我为相应的模式启用了{virtuals:true}。但仍然无法查询此字段。

我是否需要在DTO文件中添加任何内容?

实体.ts/架构文件

@Schema({
collection: 'v3_customer_account_selectors',
timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
toJSON: { virtuals: true },
})
@Injectable({ scope: Scope.TRANSIENT })
export class AccountSelectorEntity extends BaseEntity {
@AliasableProp({ alias: '_type', type: AccountSelectorType })
type: AccountSelectorType;
@Prop()
name?: string;
@AliasableProp({ alias: 'last_checked', type: Date })
lastChecked?: Date;
@AliasableProp({
type: SchemaTypes.ObjectId,
alias: 'customer_id',
})
customerId?: Types.ObjectId;
}
export const AccountSelectorEntitySchema = SchemaFactory.createForClass(
AccountSelectorEntity
);
AccountSelectorEntitySchema.set('toJSON', { getters: true, virtual: true });
AccountSelectorEntitySchema.set('toObject', { getters: true, virtual: true });
AccountSelectorEntitySchema.virtual('selector_type').get(function () {
return 'TestReturn';
});```

您必须创建一个类型或另一个类,而不是使用实体。实体虚拟不在实体文档类中。

最新更新