Skip to content

Instantly share code, notes, and snippets.

@neerajkumar161
Created December 29, 2021 14:48
Show Gist options
  • Save neerajkumar161/56df1dde2206f0857f31667fc193bf9d to your computer and use it in GitHub Desktop.
Save neerajkumar161/56df1dde2206f0857f31667fc193bf9d to your computer and use it in GitHub Desktop.
/src/schema-loader.ts
import {loadFilesSync} from '@graphql-tools/load-files'
import {mergeTypeDefs} from '@graphql-tools/merge'
import {makeExecutableSchema} from '@graphql-tools/schema'
import * as path from 'path'
import { getUserByIdResolver } from './resolvers/get-user'
import { createUserResolver } from './resolvers/create-user'
const ROOT_SCHEMA_PATH = loadFilesSync(path.join(__dirname, './schemas'))
const TypeDefinition = mergeTypeDefs(ROOT_SCHEMA_PATH)
const resolvers = () => {
return {
Query: {
getUser: getUserByIdResolver,
},
Mutation: {
createUser: createUserResolver,
}
}
}
const schema = () =>
makeExecutableSchema({
typeDefs: [TypeDefinition],
resolvers: resolvers()
})
export const mainSchema = schema()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment