* feat: rename tenant into workspace * fix: missing some files and reset not working * fix: wrong import * Use link in company seeds * Use link in company seeds --------- Co-authored-by: Charles Bochet <charles@twenty.com>
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
import { Injectable, Logger } from '@nestjs/common';
|
|
|
|
import { GraphQLSchema } from 'graphql';
|
|
|
|
import { WorkspaceResolverBuilderMethods } from 'src/workspace/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
|
|
|
|
import { TypeDefinitionsGenerator } from './type-definitions.generator';
|
|
|
|
import { WorkspaceBuildSchemaOptions } from './interfaces/workspace-build-schema-optionts.interface';
|
|
import { QueryTypeFactory } from './factories/query-type.factory';
|
|
import { MutationTypeFactory } from './factories/mutation-type.factory';
|
|
import { ObjectMetadataInterface } from './interfaces/object-metadata.interface';
|
|
import { OrphanedTypesFactory } from './factories/orphaned-types.factory';
|
|
|
|
@Injectable()
|
|
export class WorkspaceGraphQLSchemaFactory {
|
|
private readonly logger = new Logger(WorkspaceGraphQLSchemaFactory.name);
|
|
|
|
constructor(
|
|
private readonly typeDefinitionsGenerator: TypeDefinitionsGenerator,
|
|
private readonly queryTypeFactory: QueryTypeFactory,
|
|
private readonly mutationTypeFactory: MutationTypeFactory,
|
|
private readonly orphanedTypesFactory: OrphanedTypesFactory,
|
|
) {}
|
|
|
|
async create(
|
|
objectMetadataCollection: ObjectMetadataInterface[],
|
|
workspaceResolverBuilderMethods: WorkspaceResolverBuilderMethods,
|
|
options: WorkspaceBuildSchemaOptions = {},
|
|
): Promise<GraphQLSchema> {
|
|
// Generate type definitions
|
|
this.typeDefinitionsGenerator.generate(objectMetadataCollection, options);
|
|
|
|
// Generate schema
|
|
const schema = new GraphQLSchema({
|
|
query: this.queryTypeFactory.create(
|
|
objectMetadataCollection,
|
|
[...workspaceResolverBuilderMethods.queries],
|
|
options,
|
|
),
|
|
mutation: this.mutationTypeFactory.create(
|
|
objectMetadataCollection,
|
|
[...workspaceResolverBuilderMethods.mutations],
|
|
options,
|
|
),
|
|
types: this.orphanedTypesFactory.create(),
|
|
});
|
|
|
|
return schema;
|
|
}
|
|
}
|