GraphQL, from zero to governance — part 4
Every single field has its own little function behind it. This is the fact the rest of the series hangs on.
This is a deeper look for anyone who’s been told GraphQL “gets your data” and wants to know what that actually means. It assumes you can read a query — part 3, “Asking for exactly what you want” walks through one if you want the refresher. It doesn’t cover writing a resolver yourself; the goal is knowing they exist, and knowing why they reorganize everything that comes after.
And if you build APIs for a living and skipped the on-ramp, this is your entry point. Parts 1 through 3 are for everyone else. Start here.
Walk the query down the tree
Back to the product page from part 3, the one with 9 things on it: a photo, a name and description, a price, a discount badge, the “3 left in stock” line, a star rating, the review count, a delivery estimate, and your saved address. The query you wrote asked for those and nothing else, and the response came back in the same shape.
But shape-matching is the client’s half of the story. Something on the server still has to produce each of those values. So let’s look through the query, field by field, and see what actually happens.
You ask for product. On the server, product is a function. It runs, and it returns something – a product – in whatever form the server keeps products.
After that, you asked for that product’s name. That’s a different function. It takes the thing product handed back and produces the name. price is a function too, same product in, a number out. reviews is a function that returns a list. And for each review in that list, rating is (you can see where this is going) another function that produces a number.
So far, functions all the way through. One per field, each one waiting on the field above it and handed its result, until every branch bottoms out in a plain value with nothing left to compute (these are called leaf fields).
The word for one of these functions is a resolver.
A resolver for the price field does a few things: it takes the product it was handed, reads its id, asks the pricing service for that product’s price, waits for the number to come back, and returns it. Written out, in no particular language:
resolve price for a product:
take the product you were handed
call the pricing service
ask it for the price of this product's id
wait for the number to come back
hand that number to whoever asked
Four steps, then hand it back. Every field on that screen has a resolver behind it, even the ones that look like static text, though most are far simpler than this one.
Plenty of resolvers barely do anything. If the product function already handed back an object with the name sitting right on it, the name resolver just reads that property off and returns it, and most GraphQL libraries fill those trivial ones in for you without anyone writing a line. Some resolvers have to call another service, open a database connection, wait on a network round trip.
[ screen ] ── query ──▶ schema ── resolvers ──▶ [ data ]
^
you are here
The series diagram, state 4. Resolvers are the arrow from the schema to the data: how each field actually gets its value.
GraphQL is not a database
This post exists to knock down a common misconception. People hear “GraphQL,” see the word “graph,” and picture a graph database — some special store the data lives inside, some engine you’re querying directly.
But it isn’t one. graphql.org says so about as plainly as an official site ever says anything. From the intro: “GraphQL isn’t tied to any specific database or storage engine—it is backed by your existing code and data.” When asked whether GraphQL is a database language like SQL, the answer opens: “No, but this is a common misconception.”
The “graph” is your business domain, not your storage. From the same site: “With GraphQL, you model your business domain as a graph…” Products relate to reviews, reviews relate to authors, orders relate to saved addresses, and more. That web of relationships is the graph. Where any of it physically lives, GraphQL neither knows nor cares.
Which is why “what database does GraphQL use?” and “do we need to move our data into GraphQL?” are incorrect questions. There’s nothing to move into. The data stays exactly where it already sits, and GraphQL learns how to ask each place for it.
So a resolver is the thing that actually goes and gets it. It might read a row from Postgres, call a REST endpoint two teams over, check a cache, or hand back a value that was sitting in memory the whole time. The reviews resolver on our product page might open one database; the price resolver listed right next to it might call a service that has nothing to do with that database. GraphQL’s job is to coordinate all those functions and assemble their answers into the single shape you asked for. It’s a layer between the asker and wherever the data really lives. Not a database. Not magic. A stack of functions somebody wrote.
data and errors ride together
One thing that was interesting to me coming over from REST.
Because every field is its own function, every field can fail on its own. The reviews resolver can blow up while name and price work just fine. So a GraphQL response has room for both outcomes at once: a data object holding everything that worked, and an errors array listing what didn’t, and where.
They arrive together, in the same response. Half the screen can render — photo, name, price, stock — while the star rating comes back empty and an entry in the errors array explains why. Each entry carries a plain message and a path: the exact route through your query to the field that broke, so you’re never left guessing which one it was. Partial data is the intended behavior here, not a glitch.
And the HTTP status is still a 2xx, usually 200 OK, because the transport call itself succeeded. Technically, the server did answer. The failure is one or more fields deep and reported inside the body.
Where does that function live?
Every field has a resolver. Great. Where does that resolver run?
So far, the easy answer: one codebase. The product function and the price function and the reviews function all sit in the same repository, written by the same people, deployed together. You could open the project and read every one of them in an afternoon.
That afternoon-readable codebase is how a lot of GraphQL APIs start. It stays true right up until the company gets big enough that the price logic, the review data, and the live inventory count stop living anywhere near each other.
But look at what each resolver actually has to do to earn its value. The reviews resolver has to reach a store of reviews, however and wherever that’s kept. The price resolver has to reach whatever system knows current prices. It is its own moving thing with its own rules about discounts and currencies and rounding. The stock number comes from something counting warehouse inventory close to real time.
Each of those systems answers to someone. Somebody decides what a “price” is and when it’s allowed to change. Somebody owns the review data and what counts as a valid rating. The resolvers all look uniform sitting there in one schema — same syntax, same shape, listed one after another — but the systems they reach into don’t share an owner.
So back to the question: who owns each of these 9 values?
The cliff
A resolver runs somewhere real. It runs inside some team’s service, with that team’s database access, that team’s deploy schedule, that team’s on-call rotation.
A function running in the catalog service can call the pricing service, but it can’t own a field the pricing team owns. It doesn’t hold that database, set those rules, or get the call when they break. That boundary was never technical in the first place.
That is a limit of the org chart.
So look at the screen again, with the owners filled in.
1. Product photo (Field Runner 3) ...... Catalog 2. Name + description: Field Runner 3 .. Catalog 3. Price: $129 ......................... Pricing 4. Discount badge: 15% off ............. Pricing 5. "3 left in stock" ................... Inventory 6. Star rating: 4.6 .................... Reviews 7. "412 reviews" count ................. Reviews 8. Delivery estimate ................... Shipping 9. "Deliver to your saved address" ..... Accounts
(ASCII can’t carry the color — picture each row tinted its team’s shade. 6 shades. 1 screen.)
One page the customer thinks of as a single thing is actually 9 values and 6 teams. Every resolver behind those values runs on somebody’s turf, and no team’s function owns a field on another team’s turf.
N+1, named and deferred
Because every field runs a function, asking for 100 products with their prices can turn into one call for the list and then 100 more calls, one price at a time. There’s a name for that failure and a well-known fix, and the name is N+1. We’ll get back to that later.
Read it in the wild
Want to see the envelope for real? The GraphQL spec includes a response with both data and errors populated, sitting right in Section 7. A query asks for a hero and the hero’s friends. The response comes back with the hero, R2-D2, and the list of friends — but one friend’s name is null, and up in the errors array there’s a single entry: “Name for character with ID 1002 could not be fetched,” with a path pointing at that field.
Check it out, see which fields survived. Everything resolved except one name, and the response tells you which one, because behind that one field was a function, and that function is the only thing that failed.

Leave a Reply