Skip to content

Instantly share code, notes, and snippets.

@ericnograles
Created January 18, 2018 15:01
Show Gist options
  • Save ericnograles/d59e32f244c9ea04e69f66a7caa96940 to your computer and use it in GitHub Desktop.
Save ericnograles/d59e32f244c9ea04e69f66a7caa96940 to your computer and use it in GitHub Desktop.
Dynamic construction of .graphql files as one schema text file to load to makeExecutableSchema
const path = require('path');
const fs = require('fs');
const topLevelQuery = fs.readFileSync(
path.resolve(__dirname, 'Query.graphql'),
{ encoding: 'UTF-8' }
);
let types = fs
.readdirSync(__dirname)
.filter(fileName => {
return (
fileName.indexOf('.graphql') > -1 && fileName.indexOf('Query.graphql') < 0
);
})
.map(graphQLFile => {
return fs.readFileSync(path.resolve(__dirname, graphQLFile), {
encoding: 'UTF-8'
});
})
.reduce((prevValue, currentValue, currentIndex) => {
return prevValue.concat(`${currentValue}\r\n`);
}, '');
module.exports = types.concat(`${topLevelQuery}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment