graphql-community / koa-graphql

Create a GraphQL HTTP server with Koa.
MIT License
843 stars 61 forks source link

async function in compiled version 0.7.0 #88

Closed sibelius closed 6 years ago

sibelius commented 7 years ago

in koa-graphql 0.7.0, the compiled version has async syntax

we are using node 6.10.0 LTS (https://github.com/nodejs/LTS)

node_modules/koa-graphql/dist/index.js:38
  return async function middleware(ctx) {
               ^^^^^^^^
SyntaxError: Unexpected token function
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Module._extensions..js (module.js:579:10)
chentsulin commented 7 years ago

It's intentional, because native async function (node >= v7.6) is faster than which compiled by regenerator. But maybe we should somehow support node < 7.6.

karladler commented 7 years ago

What would be the workaround for this? Is it possible to compile it in babel for node6 support?

sibelius commented 7 years ago

maybe babel-preset-env could help us on this

is there an option to transpile from node_modules with babel as well?

ptmccarthy commented 6 years ago

We are running into this same error message trying to set up koa-graphql with karma+jasmine and typescript.

TS is configured to support ES2017, but it seems that no amount of configuration tweaking is getting us around this error.

Versions: Node: 8.x Typescript: 2.6.2 koa-graphql: 0.7.3 karma: 2.0 karma-typescript: 3.0.11

31 01 2018 15:12:40.482:ERROR [source-reader.karma-typescript]: Error parsing code: Unexpected token (41:15)
in .../node_modules/koa-graphql/dist/index.js
at line 41, column 15:

... function middleware(ctx) {
    var req = ctx.req;
 ...
sibelius commented 6 years ago

Use node 8

ptmccarthy commented 6 years ago

We are using node 8...