What Is GraphQL? A Practical Beginner’s Tutorial

GraphQL is a query language and server-side runtime for APIs, released by Facebook in 2015. Instead of calling many fixed endpoints, a client sends one request describing exactly the fields it needs, and the server returns only that data. It is transport-agnostic and typically served over a single HTTP endpoint.

GraphQL vs. REST

REST exposes many URLs, each returning a fixed shape. That causes over-fetching (extra fields) or under-fetching (extra round trips). GraphQL exposes one endpoint backed by a typed schema, so clients ask for precisely what they want—fewer requests and predictable responses.

Article illustration

The Core Building Blocks

  • Schema: a typed contract defining every query and type.
  • Query: a read request shaped like the response.
  • Mutation: a write operation.
  • Resolver: a function that fetches data for each field.

A Five-Minute Example

A simple query looks like query { user(id: 1) { name posts { title } } }. The server walks the resolvers, gathers the user and their posts, and returns JSON matching the query exactly.

When to Use It

GraphQL shines with mobile clients, fast-changing UIs, and multiple data sources. It adds complexity—caching, rate limiting, and query depth limits need attention—so simple CRUD APIs may still be better served by REST.

Conclusion

GraphQL is not a database or a REST replacement, but a flexible query layer. Start with one endpoint, define a small schema, and grow from there.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *