Benefits of GraphQL
- Avoid over-fetching and under-fetching
 - Reduce payload, increase efficiency
 - Strongly typed, use Schema
 
The Schema Definiation Language (SDL)
Defining simple types (! represents not null)
1  | type Person {  | 
Adding a relation
1  | type Person {  | 
1  | {  | 
Will return
1  | {  | 
1  | {  | 
Will return
1  | {  | 
1  | {  | 
Will return
1  | {  | 
Mutations
3 kinds of mutations:
- Creating new data
 - Updating existing data
 - Deleting existing data
 
1  | mutation {  | 
The GraphQL Schema
- Defines capabilities of the API by specifying how a client fetch and update data
 - Represents contract between client and server
 - Collection of GraphQL types with special root types
 
Root types
Defines the entry point of query.
1  | type Query {  | 
Example:
To enable:1
2
3
4
5{
    allPersons {
        name
    }
}
We’ll need Schema:1
2
3type Query {
    allPersons(last: Int): [Person!]!
}
1  | mutation {  | 
1  | type Mutation {  | 
1  | subscription {  | 
1  | type Subscription {  | 
More CRUD to the Schema
1  | type Person {  |