Skip to content

Instantly share code, notes, and snippets.

@xoor-io
Created June 12, 2018 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xoor-io/2c231561251ac78ff3e05c7cb3c57611 to your computer and use it in GitHub Desktop.
Save xoor-io/2c231561251ac78ff3e05c7cb3c57611 to your computer and use it in GitHub Desktop.
graphql-schema-index
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