Apollo Server的无服务器处理程序抛出错误,无法识别Netlify上的事件



上下文:我正试图通过Netlify使用Apollo Server Lambda部署GraphQL。我的处理程序如下:

代码:

exports.handler = server.createHandler({
cors: {
origin: '*'
}
});

我能够在Netlify上成功构建和部署,但服务器在启动时出现了错误。Netlify正在寻找一个事件来触发,但我使用的Apollo Server处理程序没有提供。我们如何将此处理程序连接到使用事件的处理程序?

错误消息:

{"errorType":"Error","errorMessage":"Unable to determine event source based on event.","trace":["Error: Unable to determine event source based on event.","    at getEventSourceNameBasedOnEvent (/var/task/node_modules/@vendia/serverless-express/src/event-sources/utils.js:88:9)","    at proxy (/var/task/node_modules/@vendia/serverless-express/src/configure.js:38:51)","    at handler (/var/task/node_modules/@vendia/serverless-express/src/configure.js:99:12)","    at Runtime.handler (/var/task/node_modules/apollo-server-lambda/dist/ApolloServer.js:51:27)"]}

当使用Netlify CLI时,请求似乎不包含某些特定于AWS lambda的事件参数,而@vendia/serverless-express需要这些参数。我能够在本地开发环境中修复类似的情况:

const serverHandler = server.createHandler({
cors: {
origin: '*'
}
});
exports.handler = (event, context, callback) => {
return serverHandler(
{
...event,
requestContext: event.requestContext || {},
},
context,
callback
);
}

相关内容

  • 没有找到相关文章

最新更新