Created
April 5, 2021 21:58
-
-
Save MohammedALREAI/025cf757bd31db442472495bee7b20bf to your computer and use it in GitHub Desktop.
useSchema
This file contains hidden or 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 { mergeTypes, mergeResolvers } from "merge-graphql-schemas"; | |
| import * as path from "path"; | |
| import * as fs from "fs"; | |
| import { makeExecutableSchema } from "graphql-tools"; | |
| import * as glob from "glob"; | |
| export const useSchema = () => { | |
| const pathToModules = path.join(__dirname); | |
| const graphqlTypes = glob | |
| .sync(`${pathToModules}/api/**/*.graphql`) | |
| .map(x => fs.readFileSync(x, { encoding: "utf8" })); | |
| const resolvers = glob | |
| .sync(`${pathToModules}/api/**/*.resolvers.ts`) | |
| .map(resolver => require(resolver).resolvers); | |
| return makeExecutableSchema({ | |
| typeDefs: mergeTypes(graphqlTypes), | |
| resolvers: mergeResolvers(resolvers), | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment