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

Viewed 10

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:

import { Types, Document } from 'mongoose';

export class User {
  _id: Types.ObjectId;

What causes the compiler to try to import mongoose from '../../../../../mongoose?

1 Answers

Apparently the GQL Cli Plugin had issues resolving the mongoose type.

Adding @HideField before the mongoose type resolved the issue:

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