What is GraphQL?

GraphQL is a query language for APIs. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need, makes it easier to evolve APIs over time. When compared to REST APIs, this has a few advantages.

You can either stick to REST APIs or go with Graph QL; or you can even do a hybrid approach.

What problems GraphQL solve?

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL was created by Facebook in 2012 and open sourced in 2015.

GraphQL allows you only to query the data you want as well as it allows querying for all relationships (i.e the graph) of an entity. For example on a social network, when you fetch the user's record, you probably want to fetch details of all friends and their interests. With GraphQL, this can be just one query. On the other hand, with REST APIs, this can be a lot of API calls.

Is GraphQL better than REST?

As a developer you must know the advantages and disadvantages of both. These are different ways to query for data. If someone says either Graph or REST is always better than the other, then their understanding of technology is limited.

Advantages: What are the advantages of using GraphQL?

  • Save Data
  • Faster Response Times (for user)
  • Simple Queries
  • Easier to work with NoSQL layers (such as NoSQL Databases)

Disadvantages: What are the disadvantages of using GraphQL?

  • Error handling can become complex
  • You may need to code a lot of business rules, logic at application level
  • Can be difficult for beginners to understand
  • API versionning and documentation can become complex as it grows