freecoding.school100% FREE · NO SIGNUP
Endpoint BayISSUE #22 of 45

graphql · schema · resolvers · types

RestaVSThe 401 Bandit
Resta saysA GraphQL server is a schema of types plus resolvers that fetch each field’s data.

You define a schema with types (type User { name: String, posts: [Post] }) and a resolver function per field that knows how to fetch it. The engine walks the query, calling resolvers to assemble exactly the requested shape. The schema is the contract; resolvers are the implementation that can pull from databases, other APIs, anywhere.

Power-ups you unlock

The 401 Bandit attacks — common mistakes

Boss battleSketch a User type and a resolver for its posts field.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>type User { name: String, posts: [Post] }

resolvers = {
  User: { posts: (u) => db.posts.byUser(u.id) }
}</pre></body></html>
▶ Open the interactive comic issue
‹ Graphql · Queries · Mutations · SubscriptionsGraphql Vs Rest · When Each Wins ›