简体   繁体   English

NestJs Graphql(CLI 插件代码优先)+ Mongoose 无法解析“../../../../mongoose”

[英]NestJs Graphql (Code first with CLI Plugin)+ Mongoose cannot resolve "../../../../mongoose"

Im posting this here since i spent half a day finding this bug.因为我花了半天时间找到这个错误,所以我在这里发布这个。

When using GQL Code First approach + MongoDB Schemas in the same file you can run into an issue where the project cant compile as soon as you define a type from mongoose like this:当在同一个文件中使用 GQL 代码优先方法 + MongoDB 模式时,您可能会遇到这样的问题:一旦您从 mongoose 定义类型,项目就无法编译,如下所示:

import { Types, Document } from 'mongoose';

export class User {
  _id: Types.ObjectId;

What causes the compiler to try to import mongoose from '../../../../../mongoose ?是什么导致编译器尝试从'../../../../../mongoose导入 mongoose ?

Apparently the GQL Cli Plugin had issues resolving the mongoose type.显然 GQL Cli 插件在解决 mongoose 类型时存在问题。

Adding @HideField before the mongoose type resolved the issue:在 mongoose 类型之前添加 @HideField 可以解决问题:

export class User {
  @HideField()
  _id: Types.ObjectId;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM