Skip to content

Commit

Permalink
feat(): add executor factory to module options
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jul 10, 2020
1 parent d2d4a81 commit 1c8d821
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
20 changes: 2 additions & 18 deletions lib/federation/graphql-federation.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions lib/federation/graphql-federation.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
}
9 changes: 9 additions & 0 deletions lib/graphql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
}
5 changes: 4 additions & 1 deletion lib/interfaces/gql-module-options.interface.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -39,6 +39,9 @@ export interface GqlModuleOptions
typeDefs?: string | string[];
typePaths?: string[];
include?: Function[];
executorFactory?: (
schema: GraphQLSchema,
) => GraphQLExecutor | Promise<GraphQLExecutor>;
installSubscriptionHandlers?: boolean;
resolverValidationOptions?: IResolverValidationOptions;
directiveResolvers?: any;
Expand Down

0 comments on commit 1c8d821

Please sign in to comment.