NestJS query + Mongoose bugs? #208
-
Hi there, I've been trying to use this lib with Mongoose and followed the documentation and official examples but I'm struggling with a few things that I'd appreciate getting some help on from someone more experienced to see if I'm doing something wrong or if I'm running into a bug: 1. Mongoose + Offset pagination works with caveatsPagination works in general but whenever I request the // broker.module.ts
import { Module } from '@nestjs/common';
import { NestjsQueryGraphQLModule } from '@ptc-org/nestjs-query-graphql';
import { NestjsQueryMongooseModule } from '@ptc-org/nestjs-query-mongoose';
import { Broker, BrokerSchema } from '@app/persistence/models';
import { BrokerDto } from './dto/broker.dto';
import { CreateBrokerDto } from './dto/broker-create.dto';
import { UpdateBrokerDto } from './dto/broker-update.dto';
import { BrokerResolver } from './broker.resolver';
import { BrokerService } from './broker.service';
@Module({
providers: [BrokerResolver],
imports: [
NestjsQueryGraphQLModule.forFeature({
imports: [
NestjsQueryMongooseModule.forFeature([
{ document: Broker, name: Broker.name, schema: BrokerSchema },
]),
],
services: [BrokerService],
resolvers: [
{
DTOClass: BrokerDto,
CreateDTOClass: CreateBrokerDto,
UpdateDTOClass: UpdateBrokerDto,
EntityClass: Broker,
ServiceClass: BrokerService,
enableTotalCount: true,
enableAggregate: true,
},
],
}),
],
})
export class BrokerModule {} // broker.dto.ts
import { Field, ID, ObjectType } from '@nestjs/graphql';
import type {
CreateManyInputType,
CreateOneInputType, UpdateManyInputType, UpdateOneInputType} from '@ptc-org/nestjs-query-graphql';
import {
FilterableField,
IDField,
ObjectId,
PagingStrategies,
QueryOptions,
} from '@ptc-org/nestjs-query-graphql';
import mongoose from 'mongoose';
@ObjectType('Broker')
@QueryOptions({
pagingStrategy: PagingStrategies.OFFSET,
enableTotalCount: true,
})
export class BrokerDto {
@ObjectId()
_id: mongoose.Types.ObjectId;
@IDField(() => ID)
id!: string;
@FilterableField()
firstName: string;
@FilterableField()
lastName: string;
} 2. Mongoose + Custom CRUD resolverWhen I remove the auto-generated resolver from the module and replace it with a barebones custom resolver with no extra methods, I get a similar error where the fields aren't being retrieved anymore: // broker.module.ts
import { Module } from '@nestjs/common';
import { NestjsQueryGraphQLModule } from '@ptc-org/nestjs-query-graphql';
import { NestjsQueryMongooseModule } from '@ptc-org/nestjs-query-mongoose';
import { Broker, BrokerSchema } from '@app/persistence/models';
import { BrokerDto } from './dto/broker.dto';
import { BrokerResolver } from './broker.resolver';
import { BrokerService } from './broker.service';
@Module({
providers: [BrokerResolver],
imports: [
NestjsQueryGraphQLModule.forFeature({
imports: [
NestjsQueryMongooseModule.forFeature([
{ document: Broker, name: Broker.name, schema: BrokerSchema },
]),
],
dtos: [{ DTOClass: BrokerDto }],
services: [BrokerService],
],
})
export class BrokerModule {} // broker.resolver.ts
import { InjectQueryService, QueryService } from '@ptc-org/nestjs-query-core';
import { CRUDResolver } from '@ptc-org/nestjs-query-graphql';
import { Resolver } from '@nestjs/graphql';
import { Broker } from '@app/persistence/models';
import { BrokerDto } from './dto/broker.dto';
@Resolver(() => BrokerDto)
export class BrokerResolver extends CRUDResolver(BrokerDto) {
constructor(
@InjectQueryService(Broker) service: QueryService<BrokerDto>
) {
super(service);
} // package.json
"@nestjs/mongoose": "10.0.2",
"@ptc-org/nestjs-query-core": "4.3.3",
"@ptc-org/nestjs-query-graphql": "4.3.3",
"@ptc-org/nestjs-query-mongoose": "4.3.3",
"mongodb": "5.9.2",
"mongoose": "7.6.7", |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Could be a bug inside the |
Beta Was this translation helpful? Give feedback.
@TriPSs while creating a minimum reproducible example, I figured out what was causing the errors - it was the global
ClassSerializerInterceptor
Once commented out. Everything started working as expected including the
totalCount
and custom resolvers + custom services.