diff --git a/packages/apollo/lib/drivers/apollo-base.driver.ts b/packages/apollo/lib/drivers/apollo-base.driver.ts index 8ca70c2b8..2f77b0cba 100644 --- a/packages/apollo/lib/drivers/apollo-base.driver.ts +++ b/packages/apollo/lib/drivers/apollo-base.driver.ts @@ -26,7 +26,7 @@ const apolloPredefinedExceptions: Partial< export abstract class ApolloBaseDriver< T extends Record = ApolloDriverConfig, -> extends AbstractGraphQLDriver { +> extends AbstractGraphQLDriver { protected _apolloServer: ApolloServerBase; get instance(): ApolloServerBase { @@ -106,8 +106,7 @@ export abstract class ApolloBaseDriver< 'GraphQLModule', () => require('apollo-server-express'), ); - const path = this.getNormalizedPath(apolloOptions); - const { disableHealthCheck, onHealthCheck, cors, bodyParserConfig } = + const { disableHealthCheck, path, onHealthCheck, cors, bodyParserConfig } = apolloOptions; const httpAdapter = this.httpAdapterHost.httpAdapter; diff --git a/packages/graphql/lib/drivers/abstract-graphql.driver.ts b/packages/graphql/lib/drivers/abstract-graphql.driver.ts index bd8a70024..67c513108 100644 --- a/packages/graphql/lib/drivers/abstract-graphql.driver.ts +++ b/packages/graphql/lib/drivers/abstract-graphql.driver.ts @@ -5,7 +5,6 @@ import { GqlModuleOptions, GraphQLDriver } from '../interfaces'; import { normalizeRoutePath } from '../utils'; export abstract class AbstractGraphQLDriver< - TDriver = unknown, TOptions extends Record = GqlModuleOptions, > implements GraphQLDriver { @@ -32,6 +31,8 @@ export abstract class AbstractGraphQLDriver< ...defaults, ...options, }; + (clonedOptions as Record).path = + this.getNormalizedPath(clonedOptions); return clonedOptions; } diff --git a/packages/graphql/lib/graphql.module.ts b/packages/graphql/lib/graphql.module.ts index dd46abaa6..7eae3223f 100644 --- a/packages/graphql/lib/graphql.module.ts +++ b/packages/graphql/lib/graphql.module.ts @@ -44,15 +44,18 @@ import { extend, generateString } from './utils'; GraphQLFederationFactory, ], }) -export class GraphQLModule implements OnModuleInit, OnModuleDestroy { - get graphQlAdapter(): AbstractGraphQLDriver { - return this._graphQlAdapter; +export class GraphQLModule< + TAdapter extends AbstractGraphQLDriver = AbstractGraphQLDriver, +> implements OnModuleInit, OnModuleDestroy +{ + get graphQlAdapter(): TAdapter { + return this._graphQlAdapter as TAdapter; } constructor( private readonly httpAdapterHost: HttpAdapterHost, @Inject(GRAPHQL_MODULE_OPTIONS) private readonly options: GqlModuleOptions, - private readonly _graphQlAdapter: AbstractGraphQLDriver, + private readonly _graphQlAdapter: AbstractGraphQLDriver, private readonly graphQlTypesLoader: GraphQLTypesLoader, ) {} diff --git a/packages/mercurius/lib/drivers/mercurius-federation.driver.ts b/packages/mercurius/lib/drivers/mercurius-federation.driver.ts index ca2af229d..7af537624 100644 --- a/packages/mercurius/lib/drivers/mercurius-federation.driver.ts +++ b/packages/mercurius/lib/drivers/mercurius-federation.driver.ts @@ -8,10 +8,7 @@ import mercurius from 'mercurius'; import { MercuriusDriverConfig } from '../interfaces/mercurius-driver-config.interface'; @Injectable() -export class MercuriusFederationDriver extends AbstractGraphQLDriver< - FastifyInstance, - MercuriusDriverConfig -> { +export class MercuriusFederationDriver extends AbstractGraphQLDriver { get instance(): FastifyInstance< Server, IncomingMessage, @@ -27,9 +24,9 @@ export class MercuriusFederationDriver extends AbstractGraphQLDriver< super(); } - public async start(mercuriusOptions: MercuriusDriverConfig) { + public async start(options: MercuriusDriverConfig) { const adapterOptions = await this.graphqlFederationFactory.mergeWithSchema( - mercuriusOptions, + options, ); if (adapterOptions.definitions && adapterOptions.definitions.path) { @@ -45,14 +42,9 @@ export class MercuriusFederationDriver extends AbstractGraphQLDriver< if (platformName !== 'fastify') { throw new Error(`No support for current HttpAdapter: ${platformName}`); } - - const path = this.getNormalizedPath(adapterOptions); const app = httpAdapter.getInstance(); - await app.register(mercurius, { ...adapterOptions, - path, - schema: adapterOptions.schema, }); } diff --git a/packages/mercurius/lib/drivers/mercurius-gateway.driver.ts b/packages/mercurius/lib/drivers/mercurius-gateway.driver.ts index 6ed91190e..a34c2abc4 100644 --- a/packages/mercurius/lib/drivers/mercurius-gateway.driver.ts +++ b/packages/mercurius/lib/drivers/mercurius-gateway.driver.ts @@ -4,10 +4,7 @@ import { IncomingMessage, Server, ServerResponse } from 'http'; import mercurius from 'mercurius'; import { MercuriusDriverConfig } from '../interfaces/mercurius-driver-config.interface'; -export class MercuriusGatewayDriver extends AbstractGraphQLDriver< - FastifyInstance, - MercuriusDriverConfig -> { +export class MercuriusGatewayDriver extends AbstractGraphQLDriver { get instance(): FastifyInstance< Server, IncomingMessage, @@ -17,7 +14,7 @@ export class MercuriusGatewayDriver extends AbstractGraphQLDriver< return this.httpAdapterHost?.httpAdapter?.getInstance?.(); } - public async start(mercuriusOptions: MercuriusDriverConfig) { + public async start(options: MercuriusDriverConfig) { const httpAdapter = this.httpAdapterHost.httpAdapter; const platformName = httpAdapter.getType(); @@ -25,12 +22,9 @@ export class MercuriusGatewayDriver extends AbstractGraphQLDriver< throw new Error(`No support for current HttpAdapter: ${platformName}`); } - const path = this.getNormalizedPath(mercuriusOptions); const app = httpAdapter.getInstance(); - await app.register(mercurius, { - ...mercuriusOptions, - path, + ...options, }); } diff --git a/packages/mercurius/lib/drivers/mercurius.driver.ts b/packages/mercurius/lib/drivers/mercurius.driver.ts index 3e906a35c..76b0214d0 100644 --- a/packages/mercurius/lib/drivers/mercurius.driver.ts +++ b/packages/mercurius/lib/drivers/mercurius.driver.ts @@ -6,10 +6,7 @@ import { IncomingMessage, Server, ServerResponse } from 'http'; import mercurius from 'mercurius'; import { MercuriusDriverConfig } from '../interfaces/mercurius-driver-config.interface'; -export class MercuriusDriver extends AbstractGraphQLDriver< - FastifyInstance, - MercuriusDriverConfig -> { +export class MercuriusDriver extends AbstractGraphQLDriver { get instance(): FastifyInstance< Server, IncomingMessage, @@ -38,14 +35,9 @@ export class MercuriusDriver extends AbstractGraphQLDriver< if (platformName !== 'fastify') { throw new Error(`No support for current HttpAdapter: ${platformName}`); } - - const path = this.getNormalizedPath(options); const app = httpAdapter.getInstance(); - await app.register(mercurius, { ...options, - path, - schema: options.schema, }); }