I'm using Nest and Mercurius to create a GraphQL API. So far I was able to create queries and resolvers, but now I want to enable Loaders and Cache to improve performance. The documentation is not clear on Nest on how to do that with GraphQL. On the other side, I don't know how to enable mercurius-cache properly with Nest. Same things with loaders.
Here is my app.module.ts
import { MercuriusDriver, MercuriusDriverConfig } from '@nestjs/mercurius';
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ProjectsModule } from './projects/projects.module';
@Module({
imports: [
ProjectsModule,
GraphQLModule.forRoot<MercuriusDriverConfig>({
driver: MercuriusDriver,
autoSchemaFile: 'schema.gql',
subscription: true,
graphiql: true,
}),
],
})
export class AppModule {}
In projetcsModule, I have my resolvers like this :
import { Args, Query, Resolver } from '@nestjs/graphql';
import { Project } from './models/project.model';
import { ProjectsService } from './projects.service';
@Resolver(of => Project)
export class ProjectsResolver {
constructor(
private authorsService: ProjectsService,
) {}
@Query(returns => Project)
async project(@Args('id') id: number) {
return this.authorsService.findOneById(id);
}
}
My feeling it there is something to add in one of those file (maybe in GraphQLModule options) but I don't know what. FYI, I'm fairly new to TypeScript.