Introduction to GraphQL: Why It Is a Game Changer
Comments
Sign in to join the conversation
Sign in to join the conversation
GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. It provides a complete and understandable description of the data in your API.
In a typical REST API, you might have multiple endpoints:
/users/<id> to get user data./users/<id>/posts to get posts for that user.This often leads to over-fetching (getting more data than you need) or under-fetching (not getting enough data in a single request, requiring multiple round trips.
GraphQL solves this by allowing the client to request exactly what it needs.
GraphQL is strongly typed. You define a schema:
type User {
id: ID!
name: String
posts: [Post]
}
type Post {
title: String
}
type Query {
user(id: ID!): User
}
Resolvers are functions that provide the instructions for turning a GraphQL operation into data. They resolve the query to real data, whether that's from a database, a microservice, or a REST API.
/graphql.GraphQL empowers frontend developers to build faster and more flexible applications.