- Updated biome.json to include "graphql.d.ts" in the ignored files list. - Updated subproject commit reference in epess-database to the latest version. - Removed unused script from package.json and streamlined module file extensions in tsconfig.json. - Consolidated exclude patterns in tsconfig.build.json for clarity. - Refactored imports across multiple schema files for consistency and improved readability. - Enhanced various schema files by ensuring proper import order and removing redundant code. - Improved error handling and data integrity checks in several service and schema files.
186 lines
7.0 KiB
TypeScript
186 lines
7.0 KiB
TypeScript
import { Global, Logger, Module } from '@nestjs/common'
|
|
|
|
import { ApolloDriverConfig } from '@nestjs/apollo'
|
|
import { ConfigModule } from '@nestjs/config'
|
|
import { GraphQLModule } from '@nestjs/graphql'
|
|
import { initContextCache } from '@pothos/core'
|
|
import { PothosModule } from '@smatch-corp/nestjs-pothos'
|
|
import { PothosApolloDriver } from '@smatch-corp/nestjs-pothos-apollo-driver'
|
|
import { Request } from 'express'
|
|
import { RedisPubSub } from 'graphql-redis-subscriptions'
|
|
import { Context } from 'graphql-ws'
|
|
import { PersonalMilestoneModule } from 'src/PersonalMilestone/personalmilestone.module'
|
|
import { AdminNoteModule } from '../AdminNote/adminnote.module'
|
|
import { AnalyticModule } from '../Analytic/analytic.module'
|
|
import { AppConfigModule } from '../AppConfig/appconfig.module'
|
|
import { CategoryModule } from '../Category/category.module'
|
|
import { CenterModule } from '../Center/center.module'
|
|
import { CenterMentorModule } from '../CenterMentor/centermentor.module'
|
|
import { ChatroomModule } from '../ChatRoom/chatroom.module'
|
|
import { CollaborationSessionModule } from '../CollaborationSession/collaborationsession.module'
|
|
import { DocumentModule } from '../Document/document.module'
|
|
import { ManagedServiceModule } from '../ManagedService/managedservice.module'
|
|
import { MeetingRoomModule } from '../MeetingRoom/meetingroom.module'
|
|
import { MessageModule } from '../Message/message.module'
|
|
import { OrderModule } from '../Order/order.module'
|
|
import { PaymentModule } from '../Payment/payment.module'
|
|
import { PrismaModule } from '../Prisma/prisma.module'
|
|
import { PrismaService } from '../Prisma/prisma.service'
|
|
import { PubSubModule } from '../PubSub/pubsub.module'
|
|
import { PubSubService } from '../PubSub/pubsub.service'
|
|
import { QuizModule } from '../Quiz/quiz.module'
|
|
import { RedisModule } from '../Redis/redis.module'
|
|
import { RedisService } from '../Redis/redis.service'
|
|
import { RefundTicketModule } from '../RefundTicket/refundticket.module'
|
|
import { ResumeModule } from '../Resume/resume.module'
|
|
import { ScheduleModule } from '../Schedule/schedule.module'
|
|
import { ServiceModule } from '../Service/service.module'
|
|
import { ServiceAndCategoryModule } from '../ServiceAndCategory/serviceandcategory.module'
|
|
import { ServiceFeedbackModule } from '../ServiceFeedback/servicefeedback.module'
|
|
import { UploadedFileModule } from '../UploadedFile/uploadedfile.module'
|
|
import { UserModule } from '../User/user.module'
|
|
import { WorkshopModule } from '../Workshop/workshop.module'
|
|
import { WorkshopMeetingRoomModule } from '../WorkshopMeetingRoom/workshopmeetingroom.module'
|
|
import { WorkshopOrganizationModule } from '../WorkshopOrganization/workshoporganization.module'
|
|
import { WorkshopSubscriptionModule } from '../WorkshopSubscription/workshopsubscription.module'
|
|
import { CommonModule } from '../common/common.module'
|
|
import { Builder } from './graphql.builder'
|
|
import { PrismaCrudGenerator } from './graphql.generator'
|
|
import { GraphqlService } from './graphql.service'
|
|
|
|
@Global()
|
|
@Module({
|
|
imports: [
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
}),
|
|
CommonModule,
|
|
PrismaModule,
|
|
RedisModule,
|
|
AppConfigModule,
|
|
UserModule,
|
|
CenterModule,
|
|
ServiceModule,
|
|
ChatroomModule,
|
|
CenterMentorModule,
|
|
ResumeModule,
|
|
WorkshopModule,
|
|
WorkshopOrganizationModule,
|
|
WorkshopSubscriptionModule,
|
|
PaymentModule,
|
|
OrderModule,
|
|
RefundTicketModule,
|
|
ServiceAndCategoryModule,
|
|
CategoryModule,
|
|
ServiceFeedbackModule,
|
|
ScheduleModule,
|
|
MessageModule,
|
|
CollaborationSessionModule,
|
|
UploadedFileModule,
|
|
ManagedServiceModule,
|
|
WorkshopMeetingRoomModule,
|
|
AdminNoteModule,
|
|
DocumentModule,
|
|
AnalyticModule,
|
|
MeetingRoomModule,
|
|
PersonalMilestoneModule,
|
|
PubSubModule,
|
|
QuizModule,
|
|
PothosModule.forRoot({
|
|
builder: {
|
|
inject: [PrismaService],
|
|
useFactory: (prisma: PrismaService) => new Builder(prisma),
|
|
},
|
|
}),
|
|
GraphQLModule.forRootAsync<ApolloDriverConfig>({
|
|
driver: PothosApolloDriver,
|
|
inject: [GraphqlService, 'PUB_SUB_REDIS'],
|
|
useFactory: async (graphqlService: GraphqlService, pubsub: RedisPubSub) => ({
|
|
path: process.env.API_PATH + '/graphql',
|
|
debug: process.env.NODE_ENV === 'development' || false,
|
|
playground: process.env.NODE_ENV === 'development' || false,
|
|
introspection: process.env.NODE_ENV === 'development' || false,
|
|
logger: {
|
|
debug: (...args) => Logger.debug(...args, 'GraphqlModule'),
|
|
info: (...args) => Logger.log(...args, 'GraphqlModule'),
|
|
warn: (...args) => Logger.warn(...args, 'GraphqlModule'),
|
|
error: (...args) => Logger.error(...args, 'GraphqlModule'),
|
|
},
|
|
installSubscriptionHandlers: true,
|
|
subscriptions: {
|
|
'graphql-ws': {
|
|
onConnect: (ctx: Context<Record<string, unknown>>) => {
|
|
if (!ctx.connectionParams) {
|
|
Logger.log('No connectionParams provided', 'GraphqlModule')
|
|
}
|
|
if (!ctx.extra) {
|
|
Logger.log('No extra provided', 'GraphqlModule')
|
|
}
|
|
// @ts-expect-error: Request is not typed
|
|
ctx.extra.request.headers['x-session-id'] = ctx.connectionParams['x-session-id']
|
|
},
|
|
},
|
|
},
|
|
context: async ({
|
|
req,
|
|
subscriptions,
|
|
extra,
|
|
}: {
|
|
req?: Request
|
|
subscriptions?: Record<string, never>
|
|
extra?: Record<string, never>
|
|
}) => {
|
|
initContextCache()
|
|
if (subscriptions) {
|
|
// @ts-expect-error: TODO
|
|
if (!extra?.request?.headers['x-session-id']) {
|
|
throw new Error('No sessionId provided')
|
|
}
|
|
return {
|
|
isSubscription: true,
|
|
websocket: {
|
|
req: extra?.request,
|
|
pubSub: pubsub,
|
|
me: await graphqlService.acquireContextFromSessionId(
|
|
// @ts-expect-error: TODO
|
|
extra.request.headers['x-session-id'],
|
|
),
|
|
},
|
|
}
|
|
}
|
|
return {
|
|
isSubscription: false,
|
|
http: {
|
|
req,
|
|
me: req ? await graphqlService.acquireContext(req) : null,
|
|
pubSub: pubsub,
|
|
invalidateCache: () => graphqlService.invalidateCache(req?.headers['x-session-id'] as string),
|
|
},
|
|
}
|
|
},
|
|
}),
|
|
}),
|
|
],
|
|
providers: [
|
|
RedisService,
|
|
{
|
|
provide: GraphqlService,
|
|
useFactory: (prisma: PrismaService, redis: RedisService) => new GraphqlService(prisma, redis),
|
|
inject: [PrismaService, 'REDIS_CLIENT'],
|
|
},
|
|
{
|
|
provide: Builder,
|
|
useFactory: (prisma: PrismaService) => new Builder(prisma),
|
|
inject: [PrismaService],
|
|
},
|
|
{
|
|
provide: PrismaCrudGenerator,
|
|
useFactory: (builder: Builder) => new PrismaCrudGenerator(builder),
|
|
inject: [Builder],
|
|
},
|
|
PubSubService,
|
|
],
|
|
exports: [Builder, PrismaCrudGenerator, GraphqlService, RedisService],
|
|
})
|
|
export class GraphqlModule {}
|