Introduction to GraphQL
1/11/2025
Introduction to GraphQL
GraphQL is a query language for APIs and a runtime for executing those queries.
What is GraphQL?
GraphQL provides a complete description of the data in your API, giving clients the power to ask for exactly what they need.
Why GraphQL?
- Ask for what you need: Get exactly the data you request
- Single request: Get many resources in one query
- Type system: Strong typing with schema
- Introspection: Query the schema itself
GraphQL vs REST
| GraphQL | REST |
|---|---|
| Single endpoint | Multiple endpoints |
| Client specifies data | Server determines response |
| No over/under-fetching | Often over/under-fetches |
Basic Query
graphql
query {
user(id: "1") {
name
email
posts {
title
}
}
}Schema Definition
graphql
type User {
id: ID!
name: String!
email: String!
posts: [Post!]!
}
type Post {
id: ID!
title: String!
content: String
author: User!
}
type Query {
user(id: ID!): User
users: [User!]!
}
Monkey Knows Wiki