Skip to content

Commit

Permalink
feat(facade): support extra external gql services
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Aug 21, 2024
1 parent 67fce15 commit 2eac414
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/facade/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface RestoreCommerceFacadeImplConfig {
kafka?: KafkaProviderConfig['kafka'];
fileUploadOptions?: FileUploadOptionsConfig['fileUploadOptions'];
jsonLimit?: string;
extraServices?: { name: string, url: string }[];
}

interface FacadeApolloServiceMap {
Expand All @@ -72,11 +73,12 @@ export class RestoreCommerceFacade<TModules extends FacadeModuleBase[] = []> imp
readonly kafkaConfig?: KafkaProviderConfig['kafka'];
readonly fileUploadOptionsConfig?: FileUploadOptionsConfig['fileUploadOptions'];
readonly jsonLimit?: string;
readonly extraServices?: { name: string, url: string }[];

private startFns: Array<(() => Promise<void>)> = [];
private stopFns: Array<(() => Promise<void>)> = [];

constructor({ koa, logger, port, hostname, env, kafka, fileUploadOptions, jsonLimit }: RestoreCommerceFacadeImplConfig) {
constructor({ koa, logger, port, hostname, env, kafka, fileUploadOptions, jsonLimit, extraServices }: RestoreCommerceFacadeImplConfig) {
this.logger = logger;
this.port = port ?? 5000;
this.hostname = hostname ?? '127.0.0.1';
Expand All @@ -85,6 +87,7 @@ export class RestoreCommerceFacade<TModules extends FacadeModuleBase[] = []> imp
this.kafkaConfig = kafka;
this.fileUploadOptionsConfig = fileUploadOptions;
this.jsonLimit = jsonLimit ? jsonLimit : '50mb';
this.extraServices = extraServices;

setUseSubscriptions(!!kafka);
}
Expand Down Expand Up @@ -205,13 +208,20 @@ export class RestoreCommerceFacade<TModules extends FacadeModuleBase[] = []> imp
}

private async mountApolloServer() {
const serviceList = Object.keys(this.apolloServices).map(key => {
let serviceList = Object.keys(this.apolloServices).map(key => {
return {
name: key,
url: this.apolloServices[key].url ?? `local`,
};
});

if (this.extraServices) {
serviceList = [
...serviceList,
...this.extraServices,
];
}

const gateway = new ApolloGateway({
logger: this.logger,
// serviceList,
Expand Down Expand Up @@ -346,6 +356,7 @@ export interface FacadeConfig {
kafka?: KafkaProviderConfig['kafka'];
fileUploadOptions?: FileUploadOptionsConfig['fileUploadOptions'];
jsonLimit?: string;
extraServices?: { name: string, url: string }[];
}

export const createFacade = (config: FacadeConfig): Facade => {
Expand Down Expand Up @@ -378,6 +389,7 @@ export const createFacade = (config: FacadeConfig): Facade => {
env: config.env,
kafka: config.kafka,
fileUploadOptions: config.fileUploadOptions,
jsonLimit: config.jsonLimit
jsonLimit: config.jsonLimit,
extraServices: config.extraServices
}).useModule(facadeStatusModule);
};

0 comments on commit 2eac414

Please sign in to comment.