fix: schema builder use same type definitions storage across tenant (#2525)

This commit is contained in:
Jérémy M
2023-11-15 17:23:30 +01:00
committed by GitHub
parent 66051fa077
commit c02717c1e3
3 changed files with 16 additions and 9 deletions

View File

@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ConfigModule } from '@nestjs/config';
import { APP_FILTER, ModuleRef } from '@nestjs/core';
import { APP_FILTER, ContextIdFactory, ModuleRef } from '@nestjs/core';
import { YogaDriver, YogaDriverConfig } from '@graphql-yoga/nestjs';
import GraphQLJSON from 'graphql-type-json';
@ -37,11 +37,6 @@ import { ExceptionFilter } from './filters/exception.filter';
include: [CoreModule],
conditionalSchema: async (request) => {
try {
// Get the SchemaGenerationService from the AppModule
const tenantService = AppModule.moduleRef.get(TenantService, {
strict: false,
});
// Get the JwtAuthStrategy from the AppModule
const jwtStrategy = AppModule.moduleRef.get(JwtAuthStrategy, {
strict: false,
@ -74,6 +69,18 @@ import { ExceptionFilter } from './filters/exception.filter';
decoded as JwtPayload,
);
const contextId = ContextIdFactory.create();
AppModule.moduleRef.registerRequestByContextId(request, contextId);
// Get the SchemaGenerationService from the AppModule
const tenantService = await AppModule.moduleRef.resolve(
TenantService,
contextId,
{
strict: false,
},
);
return await tenantService.createTenantSchema(workspace.id);
} catch (error) {
if (error instanceof JsonWebTokenError) {