Skip to content

Instantly share code, notes, and snippets.

@neerajkumar161
Created January 4, 2022 13:39
Show Gist options
  • Save neerajkumar161/dac6747cbfc54bb6b6ef39606bbcacf2 to your computer and use it in GitHub Desktop.
Save neerajkumar161/dac6747cbfc54bb6b6ef39606bbcacf2 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'
import { updateUserResolver } from './resolvers/update-user'
import { deleteUserResolver } from './resolvers/delete-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,
updateUser: updateUserResolver,
deleteUser: deleteUserResolver,
}
}
}
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