Created
June 12, 2018 13:26
-
-
Save xoor-io/2c231561251ac78ff3e05c7cb3c57611 to your computer and use it in GitHub Desktop.
graphql-schema-index
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
import fs from 'fs'; | |
import path from 'path'; | |
import { makeExecutableSchema } from 'graphql-tools'; | |
import { merge } from 'lodash'; | |
const Query = ` | |
type Query { | |
status: String | |
} | |
`; | |
const Mutation = ` | |
type Mutation { | |
_empty: String | |
} | |
`; | |
let resolvers = { | |
Query: { | |
status: () => 'ok' | |
} | |
}; | |
const typeDefs = [Query, Mutation]; | |
// Read the current directory and load types and resolvers automatically | |
fs.readdirSync(__dirname) | |
.filter(dir => (dir.indexOf('.') < 0)) | |
.forEach((dir) => { | |
const tmp = require(path.join(__dirname, dir)).default; // eslint-disable-line | |
resolvers = merge(resolvers, tmp.resolvers); | |
typeDefs.push(tmp.types); | |
}); | |
export default makeExecutableSchema({ | |
typeDefs, | |
resolvers | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment