Why use GraphQL?

Vesna Vucinic
2 min readAug 1, 2021

GraphQL is composed of two main parts, the query language, which is used to request data, and the framework that processes these queries.

GraphQL’s unique language allows us to specify the exact format that we want to receive our data in. Other benefits of GraphQL will include self documenting APIs, the ability to fetch deeply nested data in a single request and the ability to mount GraphQL in front of any existing API. What do we mean by self documenting API? This just mean that by looking at the API’s schema, it’s easy to understand what the data coming out of it will look like. Let’s take a quick look at an example schema.

type Movie {
id: ID!
title: String!
tagline: String
studio: Studio
}

The schema looks a lot like JSON. We can guess that this movie object will have an ID field, a title field, a tagline field, and the studio field. Since the schema is expressed in a format we’re familiar with, we can easily predict which queries will work and which ones won’t. Building on this concept makes fetching deeply nested data very easy. If we need data that is nested inside of another object, like Studio for example, we can just look at the schema for the nested object. Which in this case, is the Studio type and we know which fields are available for our response.

type Studio {
name: String!
location: String!
}

GraphQL is flexible as a backend. When it comes to developing new APIs, we can start from scratch with a GraphQL server that communicates directly with database. However, if we already have an API that’s responsible for communicating with database, we can just bolt GraphQL right in front of that API. GraphQL doesn’t care where the data comes from which makes it useful for a wide variety of applications. GraphQL can be implemented in just about any environment.

--

--