Caching @nestjs/graphql resolver response

Viewed 330

I have graphql config:

export const graphQLConfig: GqlModuleAsyncOptions = {
    imports: [ConfigModule],
    useFactory: (configService: ConfigService) => ({
        autoSchemaFile: 'schema.graphql',
        cacheControl: {
            defaultMaxAge: 60,
            stripFormattedExtensions: false,
            calculateHttpHeaders: true.
        },
        ...
    }),
    inject: [ConfigService],
}

And now I want to cache my response from resolver sending large amount of data:

@Query(() => [ConvertRateType])
async getRates(
     @Args('input') input: GetConvertRatesInput,
): Promise<ConvertRateType[]> {
     const rates = await this._ratesService.getRates(input)
     return rates
}

How can I do this using @nestjs/graphql? I'm using redis as a storage.

0 Answers
Related