Skip to content

Commit

Permalink
Merge branch 'leerw4-feature/gql-schema-from-nodemodules'
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jul 9, 2020
2 parents 080670e + d78bff5 commit 552f602
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/graphql-types.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export class GraphQLTypesLoader {
}

private async getTypesFromPaths(paths: string | string[]): Promise<string[]> {
paths = util.isArray(paths)
const includeNodeModules = this.includeNodeModules(paths);

paths = Array.isArray(paths)
? paths.map((path) => normalize(path))
: normalize(paths);

const filePaths = await glob(paths, {
ignore: ['node_modules'],
ignore: includeNodeModules ? [] : ['node_modules'],
});
if (filePaths.length === 0) {
throw new Error(
Expand All @@ -44,4 +46,11 @@ export class GraphQLTypesLoader {

return Promise.all(fileContentsPromises);
}

private includeNodeModules(pathOrPaths: string | string[]): boolean {
if (Array.isArray(pathOrPaths)) {
return pathOrPaths.some((path) => path.includes('node_modules'));
}
return pathOrPaths.includes('node_modules');
}
}

0 comments on commit 552f602

Please sign in to comment.