Created
January 18, 2018 15:01
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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