graphql icon indicating copy to clipboard operation
graphql copied to clipboard

`GraphQLFactory.mergeTypesByPaths` not working with multiple patterns

Open ph55 opened this issue 8 years ago • 3 comments

Following code

    const typeDefs = this.graphQLFactory.mergeTypesByPaths(
      `src/@core/**/*.graphqls`,
      `src/${process.env.APP_NAME}/**/*.graphqls`
    );

will only generate type definitions for first pattern: src/@core/**/*.graphqls, all next patterns not merged.

Manual merging fixes this issue:

    import { fileLoader, mergeTypes } from 'merge-graphql-schemas';

    const coreTypes = fileLoader(`src/@core/**/*.graphqls`);
    const appTypes = fileLoader(`src/${process.env.APP_NAME}/**/*.graphqls`);

    const types = coreTypes.concat(appTypes);

    const typeDefs = mergeTypes(types);

ph55 avatar Jun 12 '18 11:06 ph55

@ph55 I found the same issue. Having a look at the source code https://github.com/nestjs/graphql/blob/master/lib/graphql.factory.ts#L43 seems to be the cause of the problem: a pattern potentially matches many files, which are then read and returned as an array of strings. A simple solution is just to deep flatten the argument to mergeTypes instead of simply spreading it. I hope this is an easy fix for you, @kamilmysliwiec 😄

matcic avatar Sep 01 '18 17:09 matcic

Fixed in 5.1.0

kamilmysliwiec avatar Sep 02 '18 12:09 kamilmysliwiec

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Apr 25 '20 15:04 lock[bot]