๐ฑ GraphQL: cheat sheet
๐จ The analogyOrdering a custom bento box on one form: tick exactly what you want, and kitchen stations fill each compartment.
๐ The regular explanationA query language and runtime for APIs. A typed schema describes all the data, and each client sends one request, usually a POST to a single endpoint, naming exactly the fields it wants back.
- Mia only wants some rice. But the rice counter sells one fixed tray, so she gets soup, pickles and salad too.
- She still wants fish and a sweet, so she queues at two more counters. Three queues for one lunch.
- Now the bento shop opens one order window. Mia ticks rice, fish and a sweet on a single form and hands it in.
- Behind the window, helpers collect each item from its counter.
- One box comes back with exactly the three things she ticked. Nothing missing, nothing extra.
- Mia asks the window for a copy of the printed menu, so she can see every box and item that exists.
- She ticks "dragon roll", which isn't on the menu. The window hands the form straight back before anyone cooks.
- The menu also has a section for changes. Mia asks to save her box as a favourite, and the shop writes it down.
- Last, Mia asks to hear about every new special. Each time one comes out, the shop calls it out to her.
- Mia's form arrives. The head cook reads it from the top and checks it against the menu.
- First, someone finds Mia's account. Everything else in the box depends on it.
- Each station is told "this is for Mia" and fills its own compartment, at the same time.
- Her name on the lid needs no station, it's already on her account card. The full box goes out.
- Ten customers each order a box with fish. Finding the ten orders takes one trip to the storeroom.
- A careless cook walks to the storeroom for each piece of fish, one at a time. Ten more trips.
- A smart shop has a runner. Each ticket tells the runner which fish it needs, and the runner waits to collect them all.
- The runner makes one trip with one list and hands each station its piece. Two trips instead of eleven.
- Mia's order is a folded form. The ready-made shelf can't see inside it, so it just passes it on to the window.
- There's no fish today. The box still comes, with that compartment empty and a note inside saying why.
- Next time she orders "the usual, number 12". A number on the outside is easy to recognise, so the shelf keeps a packed copy.
- Ordering number 12 again, she gets it straight off the shelf. The window isn't even bothered.
- Someone orders a box inside a box inside a box, a hundred times over. The window refuses it before any cooking starts.
- The manager pins the printed menu on the wall and puts a label on each cook. Mia's order arrives at the window.
- The cook labelled "you make the boxes" makes three boxes.
- The cook labelled "all the fish at once" gets all three boxes together and fills every fish compartment in one go.
- The window packs the three boxes, each with its fish, and hands them to Mia.
๐งฉ Key questions
- At the old food hall, Mia gets soup and salad she never asked for, then queues at two more counters. What does the bento form fix?
- She ticks exactly what she wants and gets it all in one box. One form, one box, nothing missing and nothing extra. Keeping copies on the shelf actually gets harder.
- Ten boxes each need fish, and the cook walks to the storeroom once per box. What's the fix?
- A runner who collects every request and makes one trip with one list. One trip for the orders and one for all the fish: two trips instead of eleven.
- Mia's box arrives, but one compartment is empty. What should she do?
- Read the note inside, which says what went wrong. The shop sends what it could and tucks a note in for what it couldn't.
- Mia ticks a dragon roll, which isn't on the printed menu. What happens?
- The window hands the form back before anyone starts cooking. The menu lists everything that exists, so the window checks every form against it first.
- Why does the window refuse a box inside a box inside a box, a hundred times over?
- Because one silly form could keep every station busy all day. Customers write their own forms, so the shop must turn down the ones that would swamp the kitchen.