Files
2026-11-02 15:53:54 +00:00

44 lines
1.1 KiB
Markdown

# GraphQL
GraphQL is an FOSS agnostic query adaptor that allows you to query data from many different data sources. GraphQL is used to build APIs where clients will send a query for nested data. GraphQL mitigates the issue of versioned or rapidly changing APIs compared to REST APIs because you can request the data you want.
GraphQL schemas are written in the GraphQL SDL (Schema Definition Language) composed on:
- **Types**. Represent objects and their **fields**:
```graphql
type Query {
me: User
}
type User {
id: ID
name: String
}
```
- **Fields**
- **Queries**. Define the exact shape of the data needed by the client:
```graphql
query CurrentUser {
currentUser {
name
age
}
}
```
- **Mutations**. Allow for data to be create, updated or deleted:
```graphql
mutation CreateUser($name: String!, $age: Int!) {
createUser(userName: $name, age: $age) {
name
age
}
}
```
- **Subscriptions**. Supports live updates sent from the server to the client:
```graphql
subscription {
newPerson {
name
age
}
}
```