DEV Community

soufianecharkaoui
soufianecharkaoui

Posted on

What is GraphQL ?

Hi everyone, this is my first ever blog. I have been thinking of starting one like 6 months ago. I was short of ideas and unconfident a little bit. So today, I have decided that it is time to write and share with the world my modest knowledge.
The topic is GraphQL. What is GraphQL? Is it some new trend? Is it really worth gambling on it? …
So, before diving in, I admit that you already know what is APIs and especially REST APIs.

What is GraphQL ?

GraphQL is a query language for APIs, which means it helps the user fetch data from the server. And not only that, it also helps mutate data (add, update and delete data). The same as CRUD operations in REST APIs. So GraphQL and REST are doing the same things!! What’s so special about GraphQL?
GraphQL is the future of APIs and is an alternative to REST (sounds like I’m advertising GraphQL XD). Why?

1. Data, data & data problems

One reason is that most of apps nowadays gets more and more complicated, thus, the management and organization the data and the architecture of the app becomes more and more difficult. Sometimes when fetching the data, we want freedom to fetch the most possible necessary data with one call from the server, and that is not possible with REST APIs. Even if we can manage to do it, we will have multiple lines of complicated or incomprehensible code.
Alt Text
Yet, with GraphQL we can fetch whatever data we want without having headache.

2. Endpoints problems

As your app grows, the management of endpoints also becomes more difficult. For example, you may want to search for some comments of a post of a special user in a group. It’s a pain using REST. But trust me, the pain disappears when dealing with such stuff with GraphQL. The fact is there is just one and only one enpoint: http://localhost:4000/graphql (I will get to the technical stuff in a later article).

3. For mobile devs

I am sorry, I’m not one but GraphQL first was made for mobile development to make easier. Then it turned out that is useful for both web and mobile (Please correct me if I am wrong, I am not sure of this point).

4. Simple to use & a fast growing community

GraphQL is open source. It is used by big companies such as Coursera, Github and Twitter. If you are stuck you will surely find help in stackoverflow or github. There lot of tutorials out there, and I recommend howtographql.com or simply the official docs.

Finally, this article comes to an end. In my next article, I will give a real example on how to use GraphQL with NodeJS and MongoDB.
Hope you enjoyed it. Questions or discussions are welcomed.
Here is some ressources and references:
https://graphql.org/learn/
https://www.howtographql.com/basics/0-introduction/
The image is taken from https://undraw.co/

Top comments (0)