Quick Intro to
GraphQL
by Tim ScottOctober 5, 2016
• a query language for your API
• a server-side runtime…using a
type system you define
• by Facebook
Source: http://graphql.org/learn/
GraphQL is…
Origins at Facebook
2011 present
committed to
mobile (web)
web to native
(data APIs needed)
ouch !
REST Pains
• multiple round trips - slow, drops
• mis-aligned / overloaded data shapes
• ever enlarging API
• coupling - code, engineers
• version hell
Enter GraphQL
• mind shift:
from resources to graph
• declarative:
types, queries, mutations
• one endpoint:
POST http://www.mysite.com/api/gql
GraphQL
type User {
id: Int
name: String
occupation: String
interests: [String]
}
{
“me”: {
“name”: “Tim Scott”,
“occupation”: “Independent Consultant”
}
}
{
me {
name
occupation
}
}
GraphQL
{
“job”: “Lion Tamer”
}
VARIABLES:
mutation($job: String!) {
me: changeJob(job: $job) {
id
occupation
}
}
MUTATION:
{
“me”: {
“id”: 123,
“occupation”: “Lion Tamer”
}
}
RESULT:
GraphQL
SWAPI !
What’s So Great About It?
• exact shape for the view in one call
• intuitive FE development - query shape == result shape
• performance optimization
• self documenting - always current
• introspection - code gen, code validation, IDE support
• access patterns change much faster than schemas
Status
• mature - over 300B requests per day
• Github just announced GraphQL API rollout
• Server support for most languages
• Relay - React integration, pagination
• PaaS - Reindex, etc.
• client support - GraphiQL, Apollo, etc.
Info
• http://graphql.org
• Introduction To GraphQL by Lee Bryon
https://www.youtube.com/watch?v=Wq02BNrN1dU
• SWAPI playground:
http://graphql-swapi.parseapp.com
{
“me”: {
“name”: “Tim Scott”,
“occupation”: “Independent Consultant”,
“email”: “tscott@lunaversesoftware.com”
}
}

Into to GraphQL

  • 1.
    Quick Intro to GraphQL byTim ScottOctober 5, 2016
  • 2.
    • a querylanguage for your API • a server-side runtime…using a type system you define • by Facebook Source: http://graphql.org/learn/ GraphQL is…
  • 3.
    Origins at Facebook 2011present committed to mobile (web) web to native (data APIs needed) ouch !
  • 4.
    REST Pains • multipleround trips - slow, drops • mis-aligned / overloaded data shapes • ever enlarging API • coupling - code, engineers • version hell
  • 5.
    Enter GraphQL • mindshift: from resources to graph • declarative: types, queries, mutations • one endpoint: POST http://www.mysite.com/api/gql
  • 6.
    GraphQL type User { id:Int name: String occupation: String interests: [String] }
  • 7.
    { “me”: { “name”: “TimScott”, “occupation”: “Independent Consultant” } } { me { name occupation } } GraphQL
  • 8.
    { “job”: “Lion Tamer” } VARIABLES: mutation($job:String!) { me: changeJob(job: $job) { id occupation } } MUTATION: { “me”: { “id”: 123, “occupation”: “Lion Tamer” } } RESULT: GraphQL
  • 9.
  • 10.
    What’s So GreatAbout It? • exact shape for the view in one call • intuitive FE development - query shape == result shape • performance optimization • self documenting - always current • introspection - code gen, code validation, IDE support • access patterns change much faster than schemas
  • 11.
    Status • mature -over 300B requests per day • Github just announced GraphQL API rollout • Server support for most languages • Relay - React integration, pagination • PaaS - Reindex, etc. • client support - GraphiQL, Apollo, etc.
  • 12.
    Info • http://graphql.org • IntroductionTo GraphQL by Lee Bryon https://www.youtube.com/watch?v=Wq02BNrN1dU • SWAPI playground: http://graphql-swapi.parseapp.com { “me”: { “name”: “Tim Scott”, “occupation”: “Independent Consultant”, “email”: “tscott@lunaversesoftware.com” } }