fix: schema builder use same type definitions storage across tenant (#2525)
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { GraphQLModule } from '@nestjs/graphql';
|
import { GraphQLModule } from '@nestjs/graphql';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
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 { YogaDriver, YogaDriverConfig } from '@graphql-yoga/nestjs';
|
||||||
import GraphQLJSON from 'graphql-type-json';
|
import GraphQLJSON from 'graphql-type-json';
|
||||||
@ -37,11 +37,6 @@ import { ExceptionFilter } from './filters/exception.filter';
|
|||||||
include: [CoreModule],
|
include: [CoreModule],
|
||||||
conditionalSchema: async (request) => {
|
conditionalSchema: async (request) => {
|
||||||
try {
|
try {
|
||||||
// Get the SchemaGenerationService from the AppModule
|
|
||||||
const tenantService = AppModule.moduleRef.get(TenantService, {
|
|
||||||
strict: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get the JwtAuthStrategy from the AppModule
|
// Get the JwtAuthStrategy from the AppModule
|
||||||
const jwtStrategy = AppModule.moduleRef.get(JwtAuthStrategy, {
|
const jwtStrategy = AppModule.moduleRef.get(JwtAuthStrategy, {
|
||||||
strict: false,
|
strict: false,
|
||||||
@ -74,6 +69,18 @@ import { ExceptionFilter } from './filters/exception.filter';
|
|||||||
decoded as JwtPayload,
|
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);
|
return await tenantService.createTenantSchema(workspace.id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof JsonWebTokenError) {
|
if (error instanceof JsonWebTokenError) {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Scope } from '@nestjs/common';
|
||||||
|
|
||||||
import { GraphQLInputObjectType, GraphQLObjectType } from 'graphql';
|
import { GraphQLInputObjectType, GraphQLObjectType } from 'graphql';
|
||||||
|
|
||||||
@ -12,7 +12,8 @@ import {
|
|||||||
ObjectTypeDefinitionKind,
|
ObjectTypeDefinitionKind,
|
||||||
} from 'src/tenant/schema-builder/factories/object-type-definition.factory';
|
} from 'src/tenant/schema-builder/factories/object-type-definition.factory';
|
||||||
|
|
||||||
@Injectable()
|
// Must be scoped on REQUEST level
|
||||||
|
@Injectable({ scope: Scope.REQUEST })
|
||||||
export class TypeDefinitionsStorage {
|
export class TypeDefinitionsStorage {
|
||||||
private readonly objectTypeDefinitions = new Map<
|
private readonly objectTypeDefinitions = new Map<
|
||||||
string,
|
string,
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
import { GraphQLSchema, printSchema } from 'graphql';
|
import { GraphQLSchema, printSchema } from 'graphql';
|
||||||
|
|||||||
Reference in New Issue
Block a user