How do I use async/await ?
# prisma-whats-new
f
How do I use async/await ?
Do I have to transpile code with babel? Using "use latest"; is not working for me
n
async/await is only supported out of the box for functions in Framework projects
I believe there is a way to make it work for functions in legacy projects by using some kind of babel polyfill but I am not sure
f
I'm using framework project. And writing my own resolver functions.
Got this simple function
Copy code
"use latest";
const fromEvent = require("graphcool-lib").fromEvent;
const bcrypt = require("bcrypt");

module.exports = async event => {
  const { email } = event.data;
  const graphcool = fromEvent(event);
  const api = graphcool.api("simple/v1");
  console.log("event", event);

  const user = await api.request(
    `
query {
  User(email: "${email}"){
    id
    password,
    confirmed
  }
}`
  );

  console.log(user);

  return event;
};
It's resulting in the following error
Copy code
"error": "Function returned invalid status code: 500. Raw body: {\n  \"code\": 500,\n  \"error\": \"Script generated an unhandled synchronous exception.\",\n  \"details\": \"ReferenceError: regeneratorRuntime is
not defined\",\n  \"name\": \"ReferenceError\",\n  \"message\": \"regeneratorRuntime is not defined\",\n  \"stack\": \"ReferenceError: regeneratorRuntime is not defined\\n    at callee$0$0 (/data/io/b80367683770456
3b1c6cb7e58a4ad02/webtask.js:12:10)\\n    at /data/io/b803676837704563b1c6cb7e58a4ad02/webtask.js:40:24\\n    at Async.series.Request.get.Async.series.Async.forEachOf.createError.code (/data/sandbox/lib/sandbox.js:
808:33)\\n    at /data/sandbox/node_modules/async/dist/async.js:3853:24\\n    at replenish (/data/sandbox/node_modules/async/dist/async.js:946:17)\\n    at iterateeCallback (/data/sandbox/node_modules/async/dist/as
ync.js:931:17)\\n    at /data/sandbox/node_modules/async/dist/async.js:906:16\\n    at /data/sandbox/node_modules/async/dist/async.js:3858:13\\n    at /data/sandbox/lib/sandbox.js:882:24\\n    at invokeCallback (/d
ata/sandbox/node_modules/raw-body/index.js:224:16)\"\n}"
j
@frankspin I've tried using async/await as well but I had a few errors, so I'm using now a custom server and just points the webhook to the api instead, it's imo, better and safer to keep your code since someone might accidentally press delete function in the graph.cool area