Hide
Hide

Reputation: 3317

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.

Upvotes: 5

Views: 9589

Answers (1)

Glenn Sonna
Glenn Sonna

Reputation: 1931

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.

Upvotes: 4

Related Questions