APIs & Authentication
What is GraphQL?
A query language for APIs that lets the client specify exactly the fields it wants from a typed graph of data, returned in one round trip.
GraphQL was released by Facebook in 2015. Instead of REST's many endpoints with fixed shapes, GraphQL exposes a single endpoint and a typed schema. The client sends a query naming the fields it wants, possibly traversing relationships, and the server returns exactly those fields, no more, no less.
The headline benefit is over-fetching elimination: a mobile app can ask for user { id, name, avatar.url } and skip the 30 other user fields a REST endpoint would return. The cost is operational complexity: query caching, depth limits, and N+1 resolution all become server-side problems that REST never had.
GraphQL is dominant inside large product orgs (GitHub, Shopify, Airbnb) where many clients hit the same data. For public APIs and small teams, REST plus careful field selection often wins on simplicity.
In the wild
- →
query { user(id: 42) { name, posts { title } } } - →Mutations:
mutation { createPost(input: {...}) { id } } - →Subscriptions over WebSocket for live updates
FAQ
GraphQL vs REST?
REST is many endpoints with fixed shapes; GraphQL is one endpoint with client-specified shapes. GraphQL solves over- and under-fetching at the cost of harder caching and more server-side work.
Is GraphQL faster than REST?
Per request, sometimes, fewer round trips, less data over the wire. Per server, often slower, resolvers have to be careful to avoid N+1 queries against the database.
When should I avoid GraphQL?
Public APIs where caching matters more than flexibility, or small teams that don't want to operate the toolchain.
Related terms
An API that follows REST conventions, using HTTP methods on resource URLs to model create/read/update/delete operations.
An Application Programming Interface, a contract that lets one program request actions or data from another in a stable, documented way.
JavaScript Object Notation, a lightweight text format for representing structured data, supported natively by every modern language.
A protocol for full-duplex, persistent communication between a browser (or other client) and a server over a single long-lived TCP connection.