Skip to content

Commit

Permalink
fix(federation): use type merger from 'merge-graphql-schemas'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick Dutour Geerling committed Jan 20, 2020
1 parent 32f395b commit 77ae270
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/graphql-definitions.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class GraphQLDefinitionsFactory {
outputAs: 'class' | 'interface',
isDebugEnabled: boolean,
) {
const typeDefs = await this.gqlTypesLoader.getTypesFromPaths(typePaths);
const typeDefs = await this.gqlTypesLoader.mergeTypesByPaths(typePaths);

const { buildFederatedSchema } = loadPackage('@apollo/federation', 'ApolloFederation');
const { printSchema } = loadPackage('@apollo/federation', 'ApolloFederation');
Expand Down
7 changes: 3 additions & 4 deletions lib/graphql-federation.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { GraphQLTypesLoader } from './graphql-types.loader';
import { GraphQLSchemaBuilder } from './graphql-schema-builder';
import { GRAPHQL_MODULE_ID, GRAPHQL_MODULE_OPTIONS } from './graphql.constants';
import { GqlModuleAsyncOptions, GqlModuleOptions, GqlOptionsFactory } from './interfaces';
import { generateString, extend, mergeDefaults, normalizeRoutePath } from './utils';
import { generateString, mergeDefaults, normalizeRoutePath } from './utils';
import { GraphQLFactory } from './graphql.factory';

@Module({
Expand Down Expand Up @@ -112,12 +112,11 @@ export class GraphQLFederationModule implements OnModuleInit {
const { printSchema } = loadPackage('@apollo/federation', 'ApolloFederation');

const { typePaths } = this.options;
const typeDefs = await this.graphqlTypesLoader.getTypesFromPaths(typePaths);
const mergedTypeDefs = extend(typeDefs, this.options.typeDefs);
const typeDefs = await this.graphqlTypesLoader.mergeTypesByPaths(typePaths);

const apolloOptions = await this.graphqlFederationFactory.mergeOptions({
...this.options,
typeDefs: mergedTypeDefs,
typeDefs,
});

if (this.options.definitions && this.options.definitions.path) {
Expand Down
6 changes: 2 additions & 4 deletions lib/graphql-types.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ export class GraphQLTypesLoader {
return mergeTypes(flatTypes, { all: true }) as any;
}

async getTypesFromPaths(paths: string | string[]): Promise<string[]> {
paths = util.isArray(paths)
? paths.map(path => normalize(path))
: normalize(paths);
private async getTypesFromPaths(paths: string | string[]): Promise<string[]> {
paths = util.isArray(paths) ? paths.map(path => normalize(path)) : normalize(paths);

const filePaths = await glob(paths, {
ignore: ['node_modules'],
Expand Down

0 comments on commit 77ae270

Please sign in to comment.