fix some bug and produce many problem to solve later
This commit is contained in:
@@ -39,6 +39,8 @@ import { WorkshopModule } from '../Workshop/workshop.module'
|
||||
import { WorkshopOrganizationModule } from '../WorkshopOrganization/workshoporganization.module'
|
||||
import { WorkshopSubscriptionModule } from '../WorkshopSubscription/workshopsubscription.module'
|
||||
import { initContextCache } from '@pothos/core'
|
||||
import { PubSub } from 'graphql-subscriptions'
|
||||
import { isSubscription } from 'rxjs/internal/Subscription'
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
@@ -81,8 +83,8 @@ import { initContextCache } from '@pothos/core'
|
||||
}),
|
||||
GraphQLModule.forRootAsync<ApolloDriverConfig>({
|
||||
driver: PothosApolloDriver,
|
||||
inject: [GraphqlService],
|
||||
useFactory: async (graphqlService: GraphqlService) => ({
|
||||
inject: [GraphqlService, 'PUB_SUB'],
|
||||
useFactory: async (graphqlService: GraphqlService, pubsub: PubSub) => ({
|
||||
path: process.env.API_PATH + '/graphql',
|
||||
debug: process.env.NODE_ENV === 'development' || false,
|
||||
playground: process.env.NODE_ENV === 'development' || false,
|
||||
@@ -91,18 +93,36 @@ import { initContextCache } from '@pothos/core'
|
||||
subscriptions: {
|
||||
'graphql-ws': true,
|
||||
},
|
||||
context: async ({ req }: { req: Request }) => ({
|
||||
...initContextCache(),
|
||||
isSubscription: false,
|
||||
http: {
|
||||
req,
|
||||
me: await graphqlService.acquireContext(req),
|
||||
invalidateCache: () =>
|
||||
graphqlService.invalidateCache(
|
||||
req.headers['x-session-id'] as string,
|
||||
),
|
||||
},
|
||||
}),
|
||||
context: async ({
|
||||
req,
|
||||
subscriptions,
|
||||
extra,
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
}: { req?: Request; subscriptions?: any; extra?: any }) => {
|
||||
if (subscriptions) {
|
||||
return {
|
||||
isSubscription: true,
|
||||
websocket: {
|
||||
req: extra.request,
|
||||
pubSub: pubsub,
|
||||
me: await graphqlService.acquireContext(
|
||||
extra.request.headers['x-session-id'],
|
||||
),
|
||||
generator: extra.schemaBuilder,
|
||||
},
|
||||
}
|
||||
}
|
||||
return {
|
||||
isSubscription: false,
|
||||
http: {
|
||||
req,
|
||||
me: req ? await graphqlService.acquireContext(req) : null,
|
||||
pubSub: pubsub,
|
||||
invalidateCache: () => Promise.resolve(),
|
||||
generator: extra.schemaBuilder,
|
||||
},
|
||||
}
|
||||
},
|
||||
}),
|
||||
}),
|
||||
],
|
||||
@@ -124,7 +144,17 @@ import { initContextCache } from '@pothos/core'
|
||||
useFactory: (builder: Builder) => new PrismaCrudGenerator(builder),
|
||||
inject: [Builder],
|
||||
},
|
||||
{
|
||||
provide: 'PUB_SUB',
|
||||
useFactory: () => new PubSub(),
|
||||
},
|
||||
],
|
||||
exports: [
|
||||
Builder,
|
||||
PrismaCrudGenerator,
|
||||
GraphqlService,
|
||||
RedisService,
|
||||
'PUB_SUB',
|
||||
],
|
||||
exports: [Builder, PrismaCrudGenerator, GraphqlService, RedisService],
|
||||
})
|
||||
export class GraphqlModule {}
|
||||
|
||||
Reference in New Issue
Block a user