What is GraphQL?
GraphQL is a query language and is increasingly seen as a more efficient, flexible and powerful way of working with APIs than REST. APIs are a set of rules that allow software programs to talk with each other, and they are a pivotal piece of software technology today, especially for headless CMS platforms.
While GraphQL is a query language, REST is an architectural style for designing web services. GraphQL focuses more on retrieving elements (though it supports more), whereas REST is used to give web services a structure.
Originally developed as an open-source project by Facebook, GraphQL is now maintained by its growing community. Also, GraphQL is both programming language and database agnostic.
So, how did Facebook come up with the idea for GraphQL in the first place?
Let’s hear it from the creators themselves. According to Facebook,
“As we transitioned to natively implemented models and views, we found ourselves for the first time needing an API data version of News Feed — which up until that point had only been delivered as HTML. We evaluated our options for delivering News Feed data to our mobile apps, including RESTful server resources and FQL tables (Facebook’s SQL-like API). We were frustrated with the differences between the data we wanted to use in our apps and the server queries they required.”
The core motivation of Facebook to use GraphQL was that querying for data using REST would have otherwise required more requests, whereas more correlated data could be retrieved with GraphQL.