DEV Community

Discussion on: Explain GraphQL like I'm five.

ben profile image
Ben Halpern • Edited

It's lunchtime at school and they're serving your favorite meal: Meatloaf and mashed potatoes.

You really like the meatloaf and mashed potatoes part the most, but you're a good kid so you know you need to eat your peas and carrots. You are excited about the corn and of course, the gravy.

But you don't want your plate to be covered in veggies, yuck! So you need to be specific about what you ask for. You need two scoops of mashed potatoes, a big slice of meatloaf, half an ear of corn, and about a fistful of peas and carrots. But communicating all this to the cafeteria chef is a mouthful.

That's why you use one of these:

It's a GraphQL tray. It shows the chef exactly the portions you need and all you have to do is hand over the tray. The chef is going to then scoop out the portions from their big Mongo vats of meat, potatoes and the rest. Some chefs use Postgres tubs. Maria and Cassandra brand tubs are also popular in some school districts. But none of that really matters to you. It might matter if you had to give the chef specific instructions, but it's his job to figure out how to scoop out the mashed potatoes and fit the into the shape of your tray.

Some cafeterias don't let you use a tray to get your food, and you have to come back for each thing you want.

For a while the cafeteria workers were RESTing easy with this system which was simpler than other SOAPy systems and is still perfectly useful for a lot of cafeterias. But this district thought that that was getting a bit chaotic and that's why they started letting kids bring trays to get all the food they need without having to make a bunch of trips or have to explain to the chef exactly how much of each they need.

The kids seem to be happy with the new system.

defman profile image
Sergey Kislyakov

I guess you have to explain a lot to 5 year old kids? :D Great comment though!

ben profile image
Ben Halpern

Your comment in the other thread got me thinking GraphQL and motivated me to answer this one 😊

johnpaulada profile image
John Paul Ada

Sounds awesome! Thanks! :D

greenled profile image
Juan Carlos Mejías Rodríguez

Awesome answer. Thanks a lot!

_bigblind profile image
Frederik 👨‍💻➡️🌐 Creemers

Maybe I'm stretching the analogy too far here, but the compartiments in your tray can have little labels to indicate what should go where. So if, like me, you prefer carrots over peas, the server can just pick those delicious sweet things out for you, you don't want the peas taking up space in your tray, as that makes it heavier to carry back to your table.

binarydigit profile image

This is an awesome explanation! adding to Pocket

viniciuscamargo profile image
Vinicius Camargo

One must have a bunch of kids to come up with such a cool intro to GraphQL! <3

bhagatparwinder profile image
Parwinder 👨🏻‍💻

Very well done 👏🏼

annarankin profile image
Anna Rankin

Omg, I love this 😂 awesome explanation!

tenthyoung profile image
Izzy Young

Wow, this was a great explanation, thanks man

khawar_jatoi profile image
Khawar Jatoi

I was very confused about GraphQL before reading this. It all makes sense now. Thanks @ben

spences10 profile image
Scott Spence

Imagine you have a Lego set, let's say a StarWars Tie Bomer Classic and you want to make the wings first, using REST will dump the whole Lego set on your lap whilst using GraphQL you will only get the pieces you need to make the wings.

Make sense?