into to graphql

12
Quick Intro to GraphQL by Tim Scott October 5, 2016

Upload: shobot

Post on 07-Jan-2017

69 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Into to GraphQL

Quick Intro to

GraphQLby Tim ScottOctober 5, 2016

Page 2: Into to GraphQL

• a query language for your API

• a server-side runtime…using a type system you define

• by FacebookSource: http://graphql.org/learn/

GraphQL is…

Page 3: Into to GraphQL

Origins at Facebook

2011 present

committed tomobile (web)

web to native(data APIs needed)

ouch !

Page 4: Into to GraphQL

REST Pains• multiple round trips - slow, drops• mis-aligned / overloaded data

shapes• ever enlarging API• coupling - code, engineers• version hell

Page 5: Into to GraphQL

Enter GraphQL• mind shift:

from resources to graph• declarative:

types, queries, mutations• one endpoint:

POST http://www.mysite.com/api/gql

Page 6: Into to GraphQL

GraphQLtype User {

id: Int name: String occupation: String interests: [String]}

Page 7: Into to GraphQL

{ “me”: { “name”: “Tim Scott”, “occupation”: “Independent Consultant” }}

{ me { name occupation }}

GraphQL

Page 8: Into to GraphQL

{ “job”: “Lion Tamer”}

VARIABLES:

mutation($job: String!) { me: changeJob(job: $job) { id occupation }}

MUTATION:

{ “me”: { “id”: 123, “occupation”: “Lion Tamer” }}

RESULT:

GraphQL

Page 9: Into to GraphQL

SWAPI !

Page 10: Into to GraphQL

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

Page 11: Into to GraphQL

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.

Page 12: Into to GraphQL

Info• http://graphql.org

• Introduction To GraphQL by Lee Bryonhttps://www.youtube.com/watch?v=Wq02BNrN1dU

• SWAPI playground:http://graphql-swapi.parseapp.com

{ “me”: { “name”: “Tim Scott”, “occupation”: “Independent Consultant”, “email”: “[email protected]” }}