Apollo 3 使用 Common JS 样式导入,而 Apollo 4 使用 ECMA 样式。正确的导入语句是:
import addOpenings from "./impl/addOpenings.js"; //the extension is required
事实证明我的路径中缺少一个子目录。代替
project/netlify/functions
它应该是 project/netlify/functions/server
,这是 server.js 所在的文件夹。
但是我现在从该模块收到导入错误:
✖ Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/me/project/netlify/functions/server/impl/addOpenings' imported from /home/me/project/netlify/functions/server/resolvers.js
这是与 Apollo 3 一起使用,我没有更改文件夹结构。进口正在抱怨这一点:
// resolver.js
import addOpenings from "./impl/addOpenings";
阿波罗 4 号的相对路径有什么不同吗?这是我的服务器文件夹结构:正如我所料。
结束
// server.js
import { ApolloServer } from "@apollo/server";
import { startServerAndCreateLambdaHandler, handlers } from '@as-integrations/aws-lambda';
// ...
const graphqlHandler = startServerAndCreateLambdaHandler(
server,
// We will be using the Proxy V2 handler
handlers.createAPIGatewayProxyEventV2RequestHandler(),
);
export { graphqlHandler as handler }
Netlify 函数保存在 `project/netlify/functions' 中所以现在我想使用
serverless 来测试它。
在我的 serverless.yml 文件中,我将 graphql 函数配置为:
functions:
graphql:
handler: netlify/functions/server.handler
但是路径是错误的。从我的根项目文件夹启动无服务器时,我看到此错误:
> serverless invoke local -f graphql -p testQuery.json
Error: Cannot find module '/home/me/project/netlify/functions/server'
什么需要纠正?
更新中所述。
结束。