implement redis cache for context

This commit is contained in:
2024-10-29 00:56:23 +07:00
parent ae1aa64b41
commit 34cea2ccd3
18 changed files with 477 additions and 55 deletions

View File

@@ -1,11 +1,11 @@
import { Global, Module } from '@nestjs/common';
import { AppConfigSchema } from './appconfig.schema';
import { AppConfigService } from './appconfig.service';
@Global()
@Module({
imports: [AppConfigSchema],
providers: [AppConfigSchema],
exports: [AppConfigSchema],
providers: [AppConfigSchema, AppConfigService],
exports: [AppConfigSchema, AppConfigService],
})
export class AppConfigModule {}

View File

@@ -26,8 +26,12 @@ export class AppConfigSchema extends PothosSchema {
id: t.exposeID('id', {
description: 'The unique identifier for the config',
}),
name: t.exposeString('name', { description: 'The name of the config' }),
key: t.exposeString('key', { description: 'The key of the config' }),
name: t.exposeString('name', {
description: 'The name of the config',
}),
key: t.exposeString('key', {
description: 'The key of the config',
}),
value: t.exposeString('value', {
description: 'The value of the config',
}),
@@ -45,7 +49,7 @@ export class AppConfigSchema extends PothosSchema {
type: [this.appConfig()],
description: 'Get all app configs',
args: this.builder.generator.findManyArgs('Config'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.config.findMany({
...query,
where: args.filter ?? undefined,
@@ -56,6 +60,53 @@ export class AppConfigSchema extends PothosSchema {
});
},
}),
appConfig: t.prismaField({
type: this.appConfig(),
description: 'Get an app config by key',
args: this.builder.generator.findUniqueArgs('Config'),
resolve: async (query, root, args) => {
return await this.prisma.config.findUnique({
...query,
where: args.where ?? undefined,
});
},
}),
}));
// Mutations
this.builder.mutationFields((t) => ({
createAppConfig: t.prismaField({
type: this.appConfig(),
description: 'Create an app config',
args: {
input: t.arg({
type: this.builder.generator.getCreateInput('Config'),
required: true,
}),
},
resolve: async (query, root, args) => {
return await this.prisma.config.create({
...query,
data: args.input,
});
},
}),
createAppConfigs: t.prismaField({
type: [this.appConfig()],
description: 'Create multiple app configs',
args: {
input: t.arg({
type: this.builder.generator.getCreateManyInput('Config'),
required: true,
}),
},
resolve: async (query, root, args) => {
return await this.prisma.config.createManyAndReturn({
...query,
data: args.input,
});
},
}),
}));
}
}