Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

async/await on graphql query or mutation

I made API server with graphql-yoga. (a nodejs library)

Before searching Google, I just use query/mutation like this.

[First case]

Query: {
    movies: () => { return Movies.all();}
}

But after searching I found some code that use await/async on query/mutation.

[Second case]

Query: {
    movies: async () => { return await Movies.all(); }
}

By my little knowledge, second case is more safe and better case.

But I'm new at graphql and es6.

Is there any process related async/await already defined in graphql?

Or, do not have to consider about it?

Or, use async/await is better?

Any suggestions would be appreciated :)

Thanks.

like image 845
Hide Avatar asked Jul 03 '18 00:07

Hide


1 Answers

async/await is an ES6 paradigm unrelated to GraphQL.

  • It is syntactic sugar supposed to make Promises based code "easier" to read.
  • It doesn't provide better performance nor overhead.

You should keep working with promises until you understand it enough to feel the need for and async/await migration.

like image 63
Glenn Sonna Avatar answered Oct 15 '22 23:10

Glenn Sonna