diff --git a/lib/federation/graphql-federation.factory.ts b/lib/federation/graphql-federation.factory.ts index 5c30d0718..cd8edbea3 100644 --- a/lib/federation/graphql-federation.factory.ts +++ b/lib/federation/graphql-federation.factory.ts @@ -10,15 +10,15 @@ import { GraphQLInterfaceType, GraphQLObjectType, GraphQLResolveInfo, + GraphQLScalarType, GraphQLSchema, GraphQLUnionType, isEnumType, isInputObjectType, isInterfaceType, isObjectType, - isUnionType, isScalarType, - GraphQLScalarType, + isUnionType, } from 'graphql'; import { mergeSchemas } from 'graphql-tools'; import { forEach, isEmpty } from 'lodash'; @@ -207,22 +207,6 @@ export class GraphQLFederationFactory { }); } - private isIntrospectionType(typename: string): boolean { - return [ - '__Schema', - '__Directive', - '__DirectiveLocation', - '__Type', - '__Field', - '__InputValue', - '__EnumValue', - '__TypeKind', - '_Any', - '_Entity', - '_Service', - ].includes(typename); - } - /** * Ensures that the resolveType method for unions and interfaces in the federated schema * is properly set from the one in the autoGeneratedSchema. diff --git a/lib/federation/graphql-federation.module.ts b/lib/federation/graphql-federation.module.ts index a6f78dd39..167aeecf6 100644 --- a/lib/federation/graphql-federation.module.ts +++ b/lib/federation/graphql-federation.module.ts @@ -151,6 +151,7 @@ export class GraphQLFederationModule implements OnModuleInit { ...this.options, typeDefs: mergedTypeDefs, }); + await this.runExecutorFactoryIfPresent(apolloOptions); if (this.options.definitions && this.options.definitions.path) { await this.graphqlFactory.generateDefinitions( @@ -271,4 +272,12 @@ export class GraphQLFederationModule implements OnModuleInit { ? normalizeRoutePath(prefix) + gqlOptionsPath : gqlOptionsPath; } + + private async runExecutorFactoryIfPresent(apolloOptions: GqlModuleOptions) { + if (!apolloOptions.executorFactory) { + return; + } + const executor = await apolloOptions.executorFactory(apolloOptions.schema); + apolloOptions.executor = executor; + } } diff --git a/lib/graphql.module.ts b/lib/graphql.module.ts index d1947fbb6..f2eab1cc3 100644 --- a/lib/graphql.module.ts +++ b/lib/graphql.module.ts @@ -137,6 +137,7 @@ export class GraphQLModule implements OnModuleInit { ...this.options, typeDefs: mergedTypeDefs, }); + await this.runExecutorFactoryIfPresent(apolloOptions); if (this.options.definitions && this.options.definitions.path) { await this.graphqlFactory.generateDefinitions( @@ -235,4 +236,12 @@ export class GraphQLModule implements OnModuleInit { ? normalizeRoutePath(prefix) + gqlOptionsPath : gqlOptionsPath; } + + private async runExecutorFactoryIfPresent(apolloOptions: GqlModuleOptions) { + if (!apolloOptions.executorFactory) { + return; + } + const executor = await apolloOptions.executorFactory(apolloOptions.schema); + apolloOptions.executor = executor; + } } diff --git a/lib/interfaces/gql-module-options.interface.ts b/lib/interfaces/gql-module-options.interface.ts index 41bcc61f9..8e04ff697 100644 --- a/lib/interfaces/gql-module-options.interface.ts +++ b/lib/interfaces/gql-module-options.interface.ts @@ -1,6 +1,6 @@ import { Type } from '@nestjs/common'; import { ModuleMetadata } from '@nestjs/common/interfaces'; -import { Config } from 'apollo-server-core'; +import { Config, GraphQLExecutor } from 'apollo-server-core'; import { GraphQLSchema } from 'graphql'; import { DefinitionsGeneratorOptions } from '../graphql-ast.explorer'; import { BuildSchemaOptions } from './build-schema-options.interface'; @@ -39,6 +39,9 @@ export interface GqlModuleOptions typeDefs?: string | string[]; typePaths?: string[]; include?: Function[]; + executorFactory?: ( + schema: GraphQLSchema, + ) => GraphQLExecutor | Promise; installSubscriptionHandlers?: boolean; resolverValidationOptions?: IResolverValidationOptions; directiveResolvers?: any;