The Shastra of Macrometa - Download the eBook

What is GraphQL?

GraphQL is a query language for implementing web service architectures based on graph-structured data. It is used as a query language for an API, it retrieves only desired information from an API, no more no less. It was developed by engineers at Facebook as a solution to several problems faced by them when using standard architectural styles, such as REST.

The language started to gain popularity when Facebook declared it as a completely open-sourced project in 2015 and it is now supported by major Web APIs, including the ones provided by GitHub, Airbnb, Netflix, and Twitter.

Finally, in 2018 it was shifted to The GraphQL foundation “as a neutral, non-profit home for the GraphQL assets and ongoing collaboration, and hosted by The Linux Foundation”.

How does GraphQL work?

GraphQL allows you to send a request to an API endpoint and get data in a single run. For example, one can use the IMDB API to find movies or IMDB ratings, consider the following database:


type Movie {
 title: String
 rating: Float
 cast: [Actors]
}

type Actor {
 name: String
 age: Float
}

Now let’s suppose you want to find out the rating for the movie “Man of Steel”, the following query is the way to go about it:


{
 Movie(name: "Man of Steel") {
   rating
 }
}

Which should give the following result:


{
 "movie": {
   "rating": 7.0 }
}

Similarly, we could also execute a query for only the list of actors from the movie:


{
 Movie(name: "Man of Steel") {
   cast{
name
}
 }
}

Resulting in a list of the cast members but only the name, instead of the entire personal information:


{
 "movie": {
   "cast": [
{“name” : “Henry Cavill”},
{“name” : “Amy Adams”},
{“name” : “Michael Shannon”},
{“name” : “Russel Crowe”},
{“name” : “Harry Lennix”}
]  }
}

What is the difference between REST vs GraphQL?

In many cases, GraphQL is a great alternative to REST which is a traditional server-driven architecture due to no over or under-fetching of data and less complexity.

A study concluded that as the number of parameters in the query increases, REST becomes more complicated, hence GraphQL requires less effort.

Moreover, GraphQL is relatively easy-to-use as developers with no prior experience with the framework required less effort to implement and execute queries. GraphiQL, a tool which supports debugging as-you-type, provides hints and highlights errors thus increasing the ease of use significantly.

Developers at Workday Technology preferred GraphQL because of the client-driven API which allowed client development to “move faster and more independently “ 

Another study showed that for IoT (Internet of Things) applications involving sensor networks, GraphQL integrated framework yielded at least 52% reduction in data delivery delay and increased energy efficiency by 53% against REST frameworks.

How Macrometa can help?

Macrometa’s dynamic content engine delivers instant database results via GraphQL which has been shown to enhance static CDN for a wide range of applications such as e-commerce, mobile, IoT, gaming apps and interactive web experiences.

Closing thoughts

GraphQL is a client-driven query language API that extracts only the data requested by the query. It has a simple syntax and support tools which enhance developer experience and boosts productivity and hence, can be an alternative to REST API in many applications.

Platform

Global Data Network
Join the Newsletter