export function mergeGQLSchemas()

in src/cli.ts [25:61]


export function mergeGQLSchemas(schemaPattern: string): Promise<GraphQLSchema> {
  return new Promise((resolve, reject) => {
    console.log(`\nLoading schema from ${schemaPattern}`);
    utils.readGlob(schemaPattern).then((files) => {
      if (!files.length) {
        const noFilesMatching = `No matching files were found with Glob: ${schemaPattern}.`;
        console.error(noFilesMatching);
        reject(new Error(noFilesMatching));
      }
      Promise.all(
        files.map((file) =>
          utils
            .readFile(file)
            .then((subSchema: string) => subSchema)
            .catch((error) => {
              console.error(
                `An error occurred while trying to read your graphql schemas in ${schemaPattern}. \n`,
                error,
              );
              reject(error);
            }),
        ),
      ).then((listOfSchemas: string[]) => {
        try {
          const map = new Map();
          files.forEach((fileName, index) => {
            map.set(fileName, listOfSchemas[index]);
          });
          const mergedSchema = validateSchemaWithSourceMap(map);
          resolve(mergedSchema);
        } catch (errs) {
          reject(errs);
        }
      });
    });
  });
}