Add Pothos-generated User GraphQL schema and resolver

This commit adds the Pothos-generated User GraphQL schema and resolver. The schema is defined in the `src/graphql/graphql.schema.ts` file, and the resolver is defined in the `src/graphql/graphql.resolver.ts` file. The schema includes the `User` object type with fields for `id`, `name`, and `email`. The resolver includes a query field `users` that resolves to fetch all users from the Prisma database.
This commit is contained in:
2024-09-24 16:52:09 +07:00
parent 118e33884c
commit 4747fca4a4
12 changed files with 458 additions and 400 deletions

View File

@@ -0,0 +1,9 @@
import { Global, Module } from '@nestjs/common';
import { PrismaService } from './prisma.service';
@Global()
@Module({
providers: [PrismaService],
exports: [PrismaService],
})
export class PrismaModule {}

View File

@@ -1,15 +1,16 @@
import { Injectable, OnModuleInit, INestApplication } from '@nestjs/common';
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
async onModuleInit() {
await this.$connect();
}
async enableShutdownHooks(app: INestApplication) {
this.$on('beforeExit', async () => {
await app.close();
});
async onModuleDestroy() {
await this.$disconnect();
}
}