|
|
@@ -1,12 +1,8 @@
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
-import { GqlModuleOptions, GqlOptionsFactory } from '@nestjs/graphql';
|
|
|
+import { GqlModuleOptions, GqlOptionsFactory, GraphQLTypesLoader } from '@nestjs/graphql';
|
|
|
import { GraphQLUpload } from 'apollo-server-core';
|
|
|
-import * as fs from 'fs';
|
|
|
-import * as glob from 'glob';
|
|
|
import { GraphQLDateTime } from 'graphql-iso-date';
|
|
|
import * as GraphQLJSON from 'graphql-type-json';
|
|
|
-import { flatten } from 'lodash';
|
|
|
-import { mergeTypes } from 'merge-graphql-schemas';
|
|
|
import * as path from 'path';
|
|
|
|
|
|
import { ConfigService } from '../../config/config.service';
|
|
|
@@ -19,7 +15,11 @@ import { addGraphQLCustomFields } from './graphql-custom-fields';
|
|
|
export class GraphqlConfigService implements GqlOptionsFactory {
|
|
|
readonly typePaths = path.join(__dirname, '/../../**/*.graphql');
|
|
|
|
|
|
- constructor(private i18nService: I18nService, private configService: ConfigService) {}
|
|
|
+ constructor(
|
|
|
+ private i18nService: I18nService,
|
|
|
+ private configService: ConfigService,
|
|
|
+ private typesLoader: GraphQLTypesLoader,
|
|
|
+ ) {}
|
|
|
|
|
|
createGqlOptions(): GqlModuleOptions {
|
|
|
// Prevent `Type "Node" is missing a "resolveType" resolver.` warnings.
|
|
|
@@ -54,22 +54,7 @@ export class GraphqlConfigService implements GqlOptionsFactory {
|
|
|
|
|
|
private createTypeDefs(): string {
|
|
|
const customFields = this.configService.customFields;
|
|
|
- const typeDefs = mergeTypesByPaths(this.typePaths);
|
|
|
+ const typeDefs = this.typesLoader.mergeTypesByPaths(this.typePaths);
|
|
|
return addGraphQLCustomFields(typeDefs, customFields);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-/**
|
|
|
- * Copied directly from Nest's GraphQLFactory source, since there is currently an issue
|
|
|
- * with injecting the service itself. See https://github.com/nestjs/graphql/issues/52
|
|
|
- * TODO: These 2 functions rely on transitive dep (of @nestjs/graphql) and are just a
|
|
|
- * temp fix until the issue linked above is resolved.
|
|
|
- */
|
|
|
-function mergeTypesByPaths(...pathsToTypes: string[]): string {
|
|
|
- return mergeTypes(flatten(pathsToTypes.map(pattern => loadFiles(pattern))));
|
|
|
-}
|
|
|
-
|
|
|
-function loadFiles(pattern: string): any[] {
|
|
|
- const paths = glob.sync(pattern);
|
|
|
- return paths.map(p => fs.readFileSync(p, 'utf8'));
|
|
|
-}
|