1

I'm trying to convert my serverless nodejs graphql api to use typescript but serverless throws an error stating that the graphql handler is not a function.

Error message:

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)

The objective is to create an apollo graphql api which uses typescript and can be used offline for development purpose.

I have reproduced the issue here: https://github.com/savnik/serverless-webpack-typescript-apollo

Any thoughts on what is the root cause for this issue?

3
  • Did you ever find an answer for this? I'm having the same issue... Commented Dec 28, 2020 at 1:26
  • Yes the problem is a stated in the comment of pd76 a issue with exports.graphqlHandler = server.createHandler(); Commented Dec 30, 2020 at 6:59
  • 1
    Oh, OK.. for me that wasn't the issue. I was exporting an async function call, so the exported thing was not a function but a promise instead. Thanks anyways! Commented Dec 30, 2020 at 15:32

1 Answer 1

2

This is because you are still using 'export' syntax for a js module.

In src/handler.ts, change the last line from exports.graphqlHandler = server.createHandler() to export const graphqlHandler = server.createHandler()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.