Into to GraphQL
-
Upload
shobot -
Category
Technology
-
view
69 -
download
0
Transcript of Into to GraphQL
Quick Intro to
GraphQLby Tim ScottOctober 5, 2016
• a query language for your API
• a server-side runtime…using a type system you define
• by FacebookSource: http://graphql.org/learn/
GraphQL is…
Origins at Facebook
2011 present
committed tomobile (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
GraphQLtype 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 Bryonhttps://www.youtube.com/watch?v=Wq02BNrN1dU
• SWAPI playground:http://graphql-swapi.parseapp.com
{ “me”: { “name”: “Tim Scott”, “occupation”: “Independent Consultant”, “email”: “[email protected]” }}