I am trying to bundle my graphql server using esbuild.
The problem Im having is when everything is bundled together graphql-tools cant find resolvers and typeDefs due to the file running in a diffrent directory meaning a diffrent __dirname.
My schema.js file:
import { makeExecutableSchema } from '@graphql-tools/schema';
import { loadFilesSync } from '@graphql-tools/load-files';
import { mergeResolvers, mergeTypeDefs } from '@graphql-tools/merge';
import path from "path";
const typesArray = mergeTypeDefs(loadFilesSync(path.join(__dirname, '/types') , {extensions:['gql']}))
const resolversArray = mergeResolvers(loadFilesSync(path.join(__dirname, './resolvers') , { recursive: true }))
export const schema = makeExecutableSchema({
resolvers: resolversArray,
typeDefs: typesArray
})
I tried copying the resolvers and typedefs to the dist folder prebuild but im looking for a better solution.
I also tried using absolute paths but that won’t work if i create an image out of the dist folder since it wont recognize the folder ‘src’ anymore.