Skip to content

What is GraphQL

Key idea:

GraphQL — a query language for APIs + runtime, built by Facebook (2015). A single endpoint /graphql, clients specify which fields to return — no over-fetching / under-fetching like REST. Typed schema. Pros: exact data shape, versionless API. Cons: harder caching (single endpoint), N+1 queries without DataLoader.

Below: details, example, related terms, FAQ.

Details

  • Schema: types + queries + mutations + subscriptions
  • Query: read, GET-like. Mutation: write. Subscription: websocket for realtime
  • Resolvers: functions fetching data per field
  • Introspection: schema.json for all fields
  • Tooling: GraphiQL (browser playground), Apollo Client/Server, Relay

Example

query GetUser($id: ID!) {
  user(id: $id) {
    name
    email
    posts(first: 10) {
      title
    }
  }
}

Related Terms

Learn more

Frequently Asked Questions

GraphQL vs REST — which is faster?

GraphQL is faster for complex UIs (fewer round-trips). REST — for simple CRUD (better caching).

How to solve the N+1 problem?

DataLoader (Facebook): batching + caching per-request. Or persistent queries + query whitelisting.

Is caching harder than REST?

Yes. REST — HTTP cache by URL. GraphQL — application-level cache by query needed. Apollo Client handles this out of the box.