toi bi ngu
This commit is contained in:
@@ -41,6 +41,7 @@ import { WorkshopSubscriptionModule } from '../WorkshopSubscription/workshopsubs
|
||||
import { initContextCache } from '@pothos/core'
|
||||
import { PubSub } from 'graphql-subscriptions'
|
||||
import { DocumentModule } from 'src/Document/document.module'
|
||||
import { Context } from 'graphql-ws'
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
@@ -90,25 +91,43 @@ import { DocumentModule } from 'src/Document/document.module'
|
||||
debug: process.env.NODE_ENV === 'development' || false,
|
||||
playground: process.env.NODE_ENV === 'development' || false,
|
||||
introspection: process.env.NODE_ENV === 'development' || false,
|
||||
installSubscriptionHandlers: true,
|
||||
subscriptions: {
|
||||
'graphql-ws': true,
|
||||
'graphql-ws': {
|
||||
onConnect: (ctx: Context<Record<string, unknown>>) => {
|
||||
if (!ctx.connectionParams) {
|
||||
throw new Error('No connectionParams provided')
|
||||
}
|
||||
if (!ctx.extra) {
|
||||
throw new Error('No extra provided')
|
||||
}
|
||||
// @ts-expect-error: TODO
|
||||
ctx.extra.request.headers['x-session-id'] = ctx.connectionParams['x-session-id']
|
||||
},
|
||||
},
|
||||
},
|
||||
context: async ({
|
||||
req,
|
||||
subscriptions,
|
||||
extra,
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
}: { req?: Request; subscriptions?: any; extra?: any }) => {
|
||||
}: {
|
||||
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,
|
||||
req: extra?.request,
|
||||
pubSub: pubsub,
|
||||
me: await graphqlService.acquireContext(
|
||||
extra.request.headers['x-session-id'],
|
||||
),
|
||||
// @ts-expect-error: TODO
|
||||
me: await graphqlService.acquireContextFromSessionId(extra.request.headers['x-session-id']),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -118,10 +137,7 @@ import { DocumentModule } from 'src/Document/document.module'
|
||||
req,
|
||||
me: req ? await graphqlService.acquireContext(req) : null,
|
||||
pubSub: pubsub,
|
||||
invalidateCache: () =>
|
||||
graphqlService.invalidateCache(
|
||||
req?.headers['x-session-id'] as string,
|
||||
),
|
||||
invalidateCache: () => graphqlService.invalidateCache(req?.headers['x-session-id'] as string),
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -132,8 +148,7 @@ import { DocumentModule } from 'src/Document/document.module'
|
||||
RedisService,
|
||||
{
|
||||
provide: GraphqlService,
|
||||
useFactory: (prisma: PrismaService, redis: RedisService) =>
|
||||
new GraphqlService(prisma, redis),
|
||||
useFactory: (prisma: PrismaService, redis: RedisService) => new GraphqlService(prisma, redis),
|
||||
inject: [PrismaService, 'REDIS_CLIENT'],
|
||||
},
|
||||
{
|
||||
@@ -151,12 +166,6 @@ import { DocumentModule } from 'src/Document/document.module'
|
||||
useFactory: () => new PubSub(),
|
||||
},
|
||||
],
|
||||
exports: [
|
||||
Builder,
|
||||
PrismaCrudGenerator,
|
||||
GraphqlService,
|
||||
RedisService,
|
||||
'PUB_SUB',
|
||||
],
|
||||
exports: [Builder, PrismaCrudGenerator, GraphqlService, RedisService, 'PUB_SUB'],
|
||||
})
|
||||
export class GraphqlModule {}
|
||||
|
||||
Reference in New Issue
Block a user