GraphQL is a query language and runtime for APIs that lets clients request exactly the data they need. Unlike REST with multiple endpoints, GraphQL uses a single endpoint and a strongly typed schema to describe available data.
GraphQL was developed by Meta (Facebook) in 2012 and open-sourced in 2015. It addresses REST's over-fetching and under-fetching problems by allowing clients to specify their exact data requirements in a declarative query. The schema is self-documenting via introspection.
Clients send queries (read), mutations (write), or subscriptions (real-time) to a single GraphQL endpoint (/graphql). The query specifies exactly which fields to return, including nested relations. The server resolves each field with resolver functions, fetching data from databases, REST APIs, or other sources.
REST uses multiple endpoints (GET /users, GET /users/:id) with fixed responses. GraphQL uses a single endpoint where the client specifies the exact fields needed. GraphQL excels for complex nested data.
Not necessarily. REST is simpler and more mature with better caching. GraphQL is better for complex, client-driven data needs. Many teams use both — REST for simple CRUD, GraphQL for complex queries.