GraphQL as a pizza menu

tatchi
Texidi: Your Journey Into Tech
3 min readDec 10, 2019

GraphQL is a query language created by Facebook. It’s a way for an entity to request and get back exactly the data it needs.

Sounds like Chinese? No worries, we’ve got you covered.

GraphQL logo

Imagine you want to order a pizza, but you have a really specific taste for toppings: tomato sauce, cheese, onions, capsicum, olives, and an egg. The way you would go with a traditional restaurant (or a Rest API in IT terms) is to browse the menu and select the pizza that resembles your preferred pizza the most. You might get some ingredients that you did not ask for, but at least it contains the main toppings you wanted.

With GraphQL, however, instead of asking for a pizza on the menu, you can order a pizza with exactly the ingredients that you want. This saves you time looking for a pizza on the menu and helps you to get rid of the ingredients you didn’t really want.

Pizza menu

For development, we could imagine a web application, Medium for example, that should display the name of an author and the title of the articles this author has written.

Typically, the client (the Medium frontend) would ask the server (the Medium backend) via a Rest API for the details of the specific author. The server then sends all the author’s details back to the client. So much like the pizza, the client will receive a lot of ingredients (data) it doesn’t need to show in this page. This could be the publication date of the articles, the author’s date of birth, etc.

With GraphQL, however, the client can ask exactly the information he needs on that page. In our case, the Medium frontend could just ask for the name of the author and the titles of the articles he has written. Needless to say, GraphQL allows to have more control over what information is sent, which means that we can optimise the amount of data which is transferred between these entities and get a more efficient communication.

Hope you liked it! Do not hesitate to clap away and comment if you have questions!

This blogpost is part of Texidi’s mission to make tech understandable for non-tech profiles. Check out other blogposts explaining tech terms in an easy and fun way.

Download now the Texidi app on the Google Play Store and Apple’s App Store to discover more tech terms! More planets will be added soon — so stay tuned!

--

--