question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nitro Engine does not support Async Higher Order Functions

See original GitHub issue

Environment

  • Operating System: Darwin
  • Node Version: v16.12.0
  • Nuxt Version: 3.0.0-27252861.4f9c87b
  • Package Manager: npm
  • Bundler: Webpack
  • User Config: vite
  • Runtime Modules: -
  • Build Modules: -

Describe the bug

Async Higher-Order Functions on API Routes are not supported always return a handle is not a function.

Reproduction

// api/graphql.ts

async function main() { return function () { return { hello: “World” }; }; }

export default main();

Additional context

No response

Logs

status code: 500

handle is not a function
  at file://./node_modules/h3/dist/index.mjs:111:24  
  at new Promise (<anonymous>)  
  at callHandle (file://./node_modules/h3/dist/index.mjs:108:10)  
  at file://./node_modules/h3/dist/index.mjs:104:12  
  at file://./node_modules/h3/dist/index.mjs:132:34  
  at processTicksAndRejections (node:internal/process/task_queues:96:5)  
  at async handle (file://./node_modules/h3/dist/index.mjs:572:19)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pi0commented, Oct 27, 2021

If you want to avoid top level await as mentioned in earlier example, try this:

import { lazyHandle } from 'h3'

export default lazyHandle(async () => {
  const apollo = await apolloServer.start()
  const handler = apollo.createHandler()
  return handler
})
1reaction
pi0commented, Oct 27, 2021

This is nice with apollo-server-h3 💚

Nitro itself lazy loads API routes on the first call but we can do something like this:

const apolloServer = new ApolloServer({ typeDefs, resolvers })

export default apolloServer.start().then(() => apolloServer.createHandler)

Please don’t hesitate to DM me or open a discussion to continue this 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

async/await not working with with higher order functions #123
I have a function I need to pass arguments to, so I decided to use a higher order function like this const signupController...
Read more >
What happened to async compute? : r/Amd - Reddit
Most games run pretty much the same on GTX 1060 and RX 480/580. Has async compute just not been adopted? This thread is...
Read more >
Async agnostic higher order functions - Stack Overflow
Suppose we have a library that provides a higher order function applyTest . Can this be used with an asynchronous function asyncFunction ......
Read more >
Discussion on Async Compute from AMD Prospective
I want to know more about how AMD uses Async Compute vs how Nvidia does it. With Turing cards released yesterday it's very...
Read more >
AMD Dives Deep On Asynchronous Shading - AnandTech
Key among the latter features set is support for asynchronous shaders ... AMD has offered multiple Asynchronous Compute Engines (ACEs) since ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found