GETTING STARTED
WITH GraphQL
Agilize Cloud Accounting, 24/11/2017
Weekly company-internal DevTalks
1.
DEFINE: GraphQL
WHAT IS GRAPHQL
○ Declarative data fetching
○ Alternative to REST
○ Single endpoint → responds to queries
/authors/<id>
/authors/<id>/books
/authors/<id>/followers
3 ENDPOINTS
query
query
query
1 SINGLE
ENDPOINT
DEMO 1
2.
CHARACTERISTICS
GraphQL TIMELINE
○ Developed by Facebook on 2012
○ Presented → React.js Conf 2015
○ Is not for React Developers
○ Other companies had the same initiative
○ Netflix → Falcor
○ Cousera → Now uses GraphQL
REST CHALLENGES
○ Need for efficient data loading (mobile)
○ Variety of different frontend frameworks
○ Rapid feature development
GraphQL BENEFITS
○ No mover over or underfetching
○ Almost non API if the interface changes
○ Faster feedbacks cycles
INSIGHTFUL ANALYTICS
○ Fine-grained info about what read data
○ Evolving and deprecating API
3.
KEY CONCEPTS
type Query {
...
}
type Mutation {
...
}
type Subscription {
...
}
ROOT TYPE
query {
User(id: 123) {
name
posts {
title
}
}
}
QUERY
HTTP POST
{
"data": {
"User": {
"name": "Joston Muriel",
"posts": [
{title: "Hello, it's me"}
{title: "Lines in the sand"}
]
}
}
}
RESPONSE
RESPONSE
SCHEMA
○ Strong type system
○ Schema as client-server contract
○ Client and server can work independently
○ Schema Definition Language
type Person {
name: String!
age: Int!
}
DEFINING SIMPLE TYPES
! → required
type Person {
name: String!
age: Int!
}
ADDING A RELATION
type Post {
title: String!
author: Person!
}
type Person {
name: String!
age: Int!
posts: [Post!]!
}
ADDING A HAS-MANY RELATION
type Post {
title: String!
author: Person!
}
DEMO 2
4.
MUTATIONS
WRITING DATA WITH MUTATIONS
○ A query too
○ You can ask for the returning fields
○ Even nested ones
3 KINDS OF MUTATIONS
○ creating new data
○ updating existing data
○ deleting existing data
A MUTATION
mutation {
createPerson(name: "Bob", age: 36) {
name
age
}
}
Similar syntax. Mutation keyword. Special root field.
DEFINING A MUTATION
type Mutation {
createPerson(name: String!, age: String!) Person!
...
}
5.
NODE EXAMPLE
DEMO 3
“
Nescit cedere
Any questions?

Getting started with GraphQL