在 Vercel 上部署 Next.js 应用程序时构建 Graphql 架构和解析器时出错

时间:2021-05-30 14:21:11

标签: node.js reactjs graphql next.js vercel

我正在使用 graphql-tools 来合并类型和模式。我的graphql服务器运行在端点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);

graphql 端点在本地工作,但是在部署到 Vercel 后,当对 api/graphql 进行 API 调用时,Serverless Function 出现以下错误

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)

我相信这与 loadFilesSync 的路径混乱有关。我尝试用 __dirname 替换 process.cwd(),但没有用。我几乎浏览了互联网上的每一个资源,但没有运气。任何帮助将不胜感激。

0 个答案:

没有答案