无服务器离线不将 graphql 处理程序识别为函数
Serverless-offline does not recognize graphql handler as a function
我正在尝试将我的无服务器 nodejs graphql api 转换为使用打字稿,但无服务器抛出一个错误,指出 graphql 处理程序不是一个函数。
错误信息:
Error: Serverless-offline: handler for 'hello' is not a function
at Object.createHandler (/home/savnik/serverless-webpack-typescript-apollo/node_modules/serverless-offline/src/functionHelper.js:221:11)
at handler (/home/savnik/serverless-webpack-typescript-apollo/node_modules/serverless-offline/src/ApiGateway.js:485:40)
at module.exports.internals.Manager.execute (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/toolkit.js:41:33)
at Object.internals.handler (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/handler.js:46:48)
at exports.execute (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/handler.js:31:36)
at Request._lifecycle (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/request.js:312:68)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at Request._execute (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/request.js:221:9)
objective是创建一个apollo graphql api,它使用typescript,可以离线用于开发目的。
我在这里重现了这个问题:
https://github.com/savnik/serverless-webpack-typescript-apollo
想知道这个问题的根本原因是什么吗?
这是因为您仍在为 js 模块使用 'export' 语法。
在src/handler.ts中,将最后一行从exports.graphqlHandler = server.createHandler()
改为export const graphqlHandler = server.createHandler()
我正在尝试将我的无服务器 nodejs graphql api 转换为使用打字稿,但无服务器抛出一个错误,指出 graphql 处理程序不是一个函数。
错误信息:
Error: Serverless-offline: handler for 'hello' is not a function
at Object.createHandler (/home/savnik/serverless-webpack-typescript-apollo/node_modules/serverless-offline/src/functionHelper.js:221:11)
at handler (/home/savnik/serverless-webpack-typescript-apollo/node_modules/serverless-offline/src/ApiGateway.js:485:40)
at module.exports.internals.Manager.execute (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/toolkit.js:41:33)
at Object.internals.handler (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/handler.js:46:48)
at exports.execute (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/handler.js:31:36)
at Request._lifecycle (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/request.js:312:68)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at Request._execute (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/request.js:221:9)
objective是创建一个apollo graphql api,它使用typescript,可以离线用于开发目的。
我在这里重现了这个问题: https://github.com/savnik/serverless-webpack-typescript-apollo
想知道这个问题的根本原因是什么吗?
这是因为您仍在为 js 模块使用 'export' 语法。
在src/handler.ts中,将最后一行从exports.graphqlHandler = server.createHandler()
改为export const graphqlHandler = server.createHandler()