What is GraphQL?

Learn about the origins of GraphQL and how it is structured.

We'll cover the following

What is GraphQL?

On the GraphQL website, GraphQL is described as:

…a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

It was created by Facebook back in 2012 for use in their mobile applications, but it was made open source in 2015 and has grown in popularity ever since.

Facebook started working on GraphQL to overcome perceived weaknesses in the REST API format. This is the API format that you have most likely already interacted with. Each object is accessed by a URI address, or ‘endpoint,’ and interacted with via HTTP. For example, you retrieve information via a GET request and create content via a POST request. An illustration of this can be seen on the right:

Illustration of typical REST operation

Why GraphQL?

We will discuss the pros and cons of GraphQL vs REST later, but it is worth knowing now that REST APIs required you to make multiple round-trips to retrieve all the information you want And even when you had done so, you ended up with lots of fields that you did not actually need, so you had unnecessarily large payloads.

For a large company such as Facebook, which was also noticing an increase in mobile-first traffic, it became a priority to optimize the way that they were approaching their APIs. Thus, GraphQL was created.

Although the GraphQL website describes it as a language, it can be argued that it is neither a library nor a tool. It is a specification. There are implementations of GraphQL in nearly every language that you can think of.

Now that you have the context, let’s dig a bit deeper.