enabled context and fix some api
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Global, Logger, MiddlewareConsumer, Module } from '@nestjs/common';
|
||||
import { Global, MiddlewareConsumer, Module } from '@nestjs/common';
|
||||
|
||||
import { AdminNoteModule } from '../AdminNote/adminnote.module';
|
||||
import { ApolloDriverConfig } from '@nestjs/apollo';
|
||||
@@ -71,19 +71,22 @@ import { initContextCache } from '@pothos/core';
|
||||
useFactory: (prisma: PrismaService) => new Builder(prisma),
|
||||
},
|
||||
}),
|
||||
GraphQLModule.forRoot<ApolloDriverConfig>({
|
||||
GraphQLModule.forRootAsync<ApolloDriverConfig>({
|
||||
driver: PothosApolloDriver,
|
||||
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,
|
||||
installSubscriptionHandlers: true,
|
||||
subscriptions: {
|
||||
'graphql-ws': true,
|
||||
},
|
||||
context: async ({ req }: { req: Request }) => ({
|
||||
...initContextCache(),
|
||||
me: await new GraphqlService(new PrismaService()).acquireContext(req),
|
||||
inject: [GraphqlService],
|
||||
useFactory: async (graphqlService: GraphqlService) => ({
|
||||
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,
|
||||
installSubscriptionHandlers: true,
|
||||
subscriptions: {
|
||||
'graphql-ws': true,
|
||||
},
|
||||
context: async ({ req }: { req: Request }) => ({
|
||||
...initContextCache(),
|
||||
me: await graphqlService.acquireContext(req),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
@@ -104,7 +107,7 @@ import { initContextCache } from '@pothos/core';
|
||||
inject: [Builder],
|
||||
},
|
||||
],
|
||||
exports: [Builder, PrismaCrudGenerator],
|
||||
exports: [Builder, PrismaCrudGenerator, GraphqlService],
|
||||
})
|
||||
export class GraphqlModule {
|
||||
configure(consumer: MiddlewareConsumer) {
|
||||
|
||||
@@ -14,8 +14,8 @@ export class GraphqlService {
|
||||
const disableAuth = process.env.DISABLE_AUTH === 'true';
|
||||
try {
|
||||
sessionId = req.headers['x-session-id'] as string;
|
||||
//eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch (error) {
|
||||
Logger.error('Error acquiring context', error);
|
||||
if (disableAuth) {
|
||||
return null;
|
||||
}
|
||||
@@ -35,6 +35,7 @@ export class GraphqlService {
|
||||
if (!user) {
|
||||
throw new UnauthorizedException('User not found');
|
||||
}
|
||||
Logger.log(`User ${user.name} with id ${user.id} acquired context`);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user