'Error in constructing Graphql schema and resolvers in deployment of Next.js app on Vercel
I am using graphql-tools to merge Types and Schemas. My graphql server runs on the end point api/graphql
import { mergeTypeDefs, mergeResolvers } from "@graphql-tools/merge";
import { loadFilesSync } from "@graphql-tools/load-files";
import path from "path";
const typesArray = loadFilesSync(path.join(process.cwd(), "./**/*.graphql"));
export const types = mergeTypeDefs(typesArray);
const resolversArray = loadFilesSync(
path.join(process.cwd(), "./**/*.resolvers.*")
);
export const resolvers = mergeResolvers(resolversArray);
The graphql endpoint works locally, however upon deployment to Vercel, I get the following error with Serverless Function when an API call is made to api/graphql
ERROR Unhandled error during request: Error: Query root type must be provided.
at assertValidSchema (/var/task/node_modules/graphql/type/validate.js:69:11)
at assertValidExecutionArguments (/var/task/node_modules/graphql/execution/execute.js:150:35)
at executeImpl (/var/task/node_modules/graphql/execution/execute.js:98:3)
at Object.execute (/var/task/node_modules/graphql/execution/execute.js:60:63)
at Object.generateSchemaHash (/var/task/node_modules/apollo-server-core/dist/utils/schemaHash.js:15:32)
at ApolloServer.generateSchemaDerivedData (/var/task/node_modules/apollo-server-core/dist/ApolloServer.js:269:41)
at new ApolloServerBase (/var/task/node_modules/apollo-server-core/dist/ApolloServer.js:161:38)
at new ApolloServer (/var/task/node_modules/apollo-server-micro/dist/ApolloServer.js:18:1)
at Module.dCYn (/var/task/.next/serverless/pages/api/graphql.js:490:22)
at __webpack_require__ (/var/task/.next/serverless/pages/api/graphql.js:23:31)
at Module.GfcW (/var/task/.next/serverless/pages/api/graphql.js:251:23)
at __webpack_require__ (/var/task/.next/serverless/pages/api/graphql.js:23:31)
at /var/task/.next/serverless/pages/api/graphql.js:91:18
at Object.<anonymous> (/var/task/.next/serverless/pages/api/graphql.js:94:10)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
I believe it has to do with a mess up in the path for loadFilesSync. I tried replacing process.cwd() with __dirname, but it didn't work. I pretty much have scoured through every single resource on the internet but no luck. Any help would be greatly appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
