SHA256
GraphQL
This commit is contained in:
1 parent
0ac6d3ca2a
commit
36b5f096e2
1 file changed
+43
@@ -0,0 +1,43 @@
|
|||||||
|
# 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
Reference in new issue
Block a user