Restful APIs Are Good, But GraphQL APIs Are Usually Better
Tags: graphql
Published: 2021-04-26 19:37:15

According to the GraphQL Foundation, GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. Like many influential technologies, GraphQL was developed by Facebook in 2012. In their own words they “needed a data-fetching API powerful enough to describe all of Facebook, yet simple enough to be easy to learn” by their developers.

For a few years, GraphQL was used internally for their mobile applications. The first GraphQL repos were open sourced in 2015. One of the Github repos contained the GraphQL specification and another contained a GraphQL JavaScript reference implementation. 
GraphQL APIs draw a natural comparison and contrast to Restful APIs. I should mention in the very beginning there are benefits to both approaches.
 
Don’t force adopt GraphQL when REST makes more sense. Even if you do decide to go with GraphQL APIs, be sure to continue REST-based best practices. For example, optimize for reusability.
   
A core distinction of GraphQL is it is optimized for performance and flexibility. A big part of this is instead of returning a complete dataset, GraphQL allows you to tailor the request to just give you the data you need. This is a notable change from RESTful APIs, since REST endpoints don’t allow you to tailor the data that is returned. Another advantage is operations that would require multiple RESTful API calls can be simplified to a single GraphQL API call.

One of the downsides of GraphQL is there is generally a learning curve. A lot of this has to do with the GraphQL schema. The GraphQL schema defines a collection of types and the relationship between those types.

The GraphQL ecosystem is large. One place you’ll see it used often is integrated with headless CMSs. Examples of such CMSs are Sanity IO, GraphCMS, and Sitecore.

You also not only have GraphQL reference implementations for many programming languages, you also have frameworks that work well with or are a part of some of the popular service and app development frameworks. This list of frameworks includes NestJS, Quarkus, and GatsbyJS.

Hopefully, we can follow up this conversation with one of at least one of the GraphQL servers.

*View the original article and more at: [Hassan River](https://www.hassanriver.com/2021/04/article/restful-apis-are-good-but-graphql-apis-are-usually-better/).*

## References:
1. GraphQL: Core Features, Architecture, Pros & Cons. https://www.altexsoft.com/blog/engineering/graphql-core-features-architecture-pros-and-cons/. Accessed 20 Apr 2021.
2. GraphQL: A data query language. https://engineering.fb.com/2015/09/14/core-data/graphql-a-data-query-language/. Accessed 20 Apr 2021.
3. GraphQL vs REST: What you need to know. https://www.rubrik.com/en/blog/technology/19/11/graphql-vs-rest-apis. Accessed 20 Apr 2021.
4. Schema Basics - Apollo Server - Apollo GraphQL Docs. https://www.apollographql.com/docs/apollo-server/schema/schema/. Accessed 20 Apr 2021.
5. What is GraphQL? https://www.redhat.com/en/topics/api/what-is-graphql. Accessed 20 Apr 2021.
6. Interacting with APIs: Rest and GraphQL. https://cloud.google.com/blog/products/api-management/interacting-with-apis-rest-and-graphql. Accessed 20 Aor 2021.