Slide 1

Slide 1 text

GraphQL

Slide 2

Slide 2 text

Hi, I’m Brooks

Slide 3

Slide 3 text

I work at !

Slide 4

Slide 4 text

Launching GitHub’s GraphQL API

Slide 5

Slide 5 text

March 2008 API v1 April 2009 API v2 April 2011 API v3 May 2017 API v4

Slide 6

Slide 6 text

March 2008 API v1 April 2009 API v2 April 2011 API v3 May 2017 API v4

Slide 7

Slide 7 text

March 2008 API v1 April 2009 API v2 April 2011 API v3 May 2017 API v4

Slide 8

Slide 8 text

March 2008 API v1 April 2009 API v2 April 2011 API v3 May 2017 API v4

Slide 9

Slide 9 text

https://api.github.com/user GET

Slide 10

Slide 10 text

!"""# verb https://api.github.com/user GET

Slide 11

Slide 11 text

!"""""""""""""""""""""""""""# endpoint !"""# verb https://api.github.com/user GET

Slide 12

Slide 12 text

{ "login": "bswinnerton", "id": 934497, "avatar_url": "https://avatars1.githubusercontent.com/u/934497?v=4", "url": "https://api.github.com/users/bswinnerton", "html_url": "https://github.com/bswinnerton", "site_admin": true, "name": "Brooks Swinnerton", "location": "Brooklyn, NY", "email": "[email protected]", "bio": ":octocat:", "public_repos": 32, "public_gists": 55, "followers": 231, "following": 60, "created_at": "2011-07-23T17:44:47Z", "updated_at": "2017-10-02T17:38:48Z", "private_gists": 172, "total_private_repos": 9, "owned_private_repos": 8, "disk_usage": 87918, "collaborators": 7, "plan": { "name": "developer", "space": 976562499, "collaborators": 0, "private_repos": 9999 } } https://api.github.com/user GET

Slide 13

Slide 13 text

REST APIs return resources

Slide 14

Slide 14 text

{ "login": "bswinnerton", "id": 934497, "avatar_url": "https://avatars1.githubusercontent.com/u/934497?v=4", "url": "https://api.github.com/users/bswinnerton", "html_url": "https://github.com/bswinnerton", "site_admin": true, "name": "Brooks Swinnerton", "location": "Brooklyn, NY", "email": "[email protected]", "bio": ":octocat:", "public_repos": 32, "public_gists": 55, "followers": 231, "following": 60, "created_at": "2011-07-23T17:44:47Z", "updated_at": "2017-10-02T17:38:48Z", "private_gists": 172, "total_private_repos": 9, "owned_private_repos": 8, "disk_usage": 87918, "collaborators": 7, "plan": { "name": "developer", "space": 976562499, "collaborators": 0, "private_repos": 9999 } } https://api.github.com/user GET

Slide 15

Slide 15 text

{ "login": "bswinnerton", "id": 934497, "name": "Brooks Swinnerton", "location": "Brooklyn, NY", "email": "[email protected]", "bio": ":octocat:", ... } https://api.github.com/user GET

Slide 16

Slide 16 text

https://api.github.com/user GET { "login": "bswinnerton", "id": 934497, "name": "Brooks Swinnerton", "location": "Brooklyn, NY", "email": "[email protected]", "bio": ":octocat:", "public_repos": 32, "public_gists": 55, "private_gists": 172, "owned_private_repos": 8, ... }

Slide 17

Slide 17 text

but how do we access those other resources?

Slide 18

Slide 18 text

✨ hypermedia ✨

Slide 19

Slide 19 text

https://api.github.com/user GET { "login": "bswinnerton", "id": 934497, "name": "Brooks Swinnerton", "location": "Brooklyn, NY", "email": "[email protected]", "bio": ":octocat:", "public_repos": 32, "public_gists": 55, "private_gists": 172, "owned_private_repos": 8, "url": "https://api.github.com/users/bswinnerton", "gists_url": "https://api.github.com/users/bswinnerton/gists{/ gist_id}", "repos_url": "https://api.github.com/users/bswinnerton/repos", ... }

Slide 20

Slide 20 text

https://api.github.com/user GET { "login": "bswinnerton", "id": 934497, "name": "Brooks Swinnerton", "location": "Brooklyn, NY", "email": "[email protected]", "bio": ":octocat:", "public_repos": 32, "public_gists": 55, "private_gists": 172, "owned_private_repos": 8, "url": "https://api.github.com/users/bswinnerton", "gists_url": "https://api.github.com/users/bswinnerton/gists{/ gist_id}", "repos_url": "https://api.github.com/users/bswinnerton/repos", ... }

Slide 21

Slide 21 text

https://api.github.com/users/bswinnerton/repos GET

Slide 22

Slide 22 text

https://api.github.com/users/bswinnerton/repos GET [ { "id": 82398282, "name": "launchbar-github", "private": false, "description": "A LaunchBar action for GitHub", "language": "JavaScript", "homepage": "http://launchbar-github.com", "owner": { "login": "bswinnerton", "id": 934497, "url": "https://api.github.com/users/bswinnerton", ... }, "url": "https://api.github.com/repos/bswinnerton/launchbar-github", "issues_url": "https://api.github.com/repos/bswinnerton/launchbar-github/ issues{/number}" }, ... ]

Slide 23

Slide 23 text

https://api.github.com/users/bswinnerton/repos GET [ { "id": 82398282, "name": "launchbar-github", "private": false, "description": "A LaunchBar action for GitHub", "language": "JavaScript", "homepage": "http://launchbar-github.com", "owner": { "login": "bswinnerton", "id": 934497, "url": "https://api.github.com/users/bswinnerton", ... }, "url": "https://api.github.com/repos/bswinnerton/launchbar-github", "issues_url": "https://api.github.com/repos/bswinnerton/launchbar-github/ issues{/number}" }, ... ]

Slide 24

Slide 24 text

https://api.github.com/repos/bswinnerton/launchbar-github/issues GET

Slide 25

Slide 25 text

https://api.github.com/repos/bswinnerton/launchbar-github/issues GET [ { "id": 246489445, "number": 83, "title": "Error when viewing Gists of another user", "state": "open", "body": "I can't reproduce this in every case...", "user": { "login": "bswinnerton", "id": 934497, "url": "https://api.github.com/users/bswinnerton", ... }, "url": "https://api.github.com/repos/bswinnerton/launchbar-github/issues/ 83", "repository_url": "https://api.github.com/repos/bswinnerton/launchbar- github", ... }, ... ]

Slide 26

Slide 26 text

API Server /user /repositories /issues

Slide 27

Slide 27 text

API Server /user /repositories /issues

Slide 28

Slide 28 text

"RESTful APIs are optimized for servers, not clients." - Mark Twain (I think)

Slide 29

Slide 29 text

how can we put API consumers first?

Slide 30

Slide 30 text

March 2008 API v1 April 2009 API v2 April 2011 API v3 Early 2016 ?

Slide 31

Slide 31 text

Enter GraphQL

Slide 32

Slide 32 text

a data query language

Slide 33

Slide 33 text

think SQL

Slide 34

Slide 34 text

not Neo4j

Slide 35

Slide 35 text

GraphQL is a specification

Slide 36

Slide 36 text

{ viewer { name email } }

Slide 37

Slide 37 text

{ viewer { name email } }

Slide 38

Slide 38 text

{ viewer { name email } }

Slide 39

Slide 39 text

{ viewer { name email } }

Slide 40

Slide 40 text

{ viewer { name email } } { "data": { "viewer": { "name": "Brooks Swinnerton", "email": "[email protected]" } } }

Slide 41

Slide 41 text

https://api.github.com/graphql POST

Slide 42

Slide 42 text

!"""# verb https://api.github.com/graphql POST

Slide 43

Slide 43 text

!"""# verb !""""""""""""""""""""""""""""""# endpoint https://api.github.com/graphql POST

Slide 44

Slide 44 text

https://api.github.com/graphql POST { user(login:"defunkt") { name bio } } { "data": { "user": { "name": "Chris Wanstrath", "bio": """ } } }

Slide 45

Slide 45 text

features of the query language

Slide 46

Slide 46 text

GraphQL is typed

Slide 47

Slide 47 text

{ viewer { name email } }

Slide 48

Slide 48 text

{ viewer { name email } } type RootQuery { viewer: User } type User { name: String email: String }

Slide 49

Slide 49 text

{ viewer { name email } } type RootQuery { viewer: User } type User { name: String email: String }

Slide 50

Slide 50 text

{ viewer { name email } } type RootQuery { viewer: User } type User { name: String email: String }

Slide 51

Slide 51 text

{ user(login:"defunkt") { name bio } }

Slide 52

Slide 52 text

type RootQuery { user(login: String): User } type User { name: String bio: String } { user(login:"defunkt") { name bio } }

Slide 53

Slide 53 text

{ user(login:"defunkt") { name bio } } type RootQuery { user(login: String): User } type User { name: String bio: String }

Slide 54

Slide 54 text

type RootQuery { user(login: String): User } type User { name: String bio: String } { user(login:"defunkt") { name bio } }

Slide 55

Slide 55 text

type RootQuery { user(login: String): User } type User { name: String bio: String } { user(login:"defunkt") { name bio } }

Slide 56

Slide 56 text

{ licenses { name nickname url } }

Slide 57

Slide 57 text

{ licenses { name nickname url } }

Slide 58

Slide 58 text

{ licenses { name nickname url } } type RootQuery { licenses: [License]! } type License { name: String! nickname: String url: URL! }

Slide 59

Slide 59 text

{ licenses { name nickname url } } type RootQuery { licenses: [License]! } type License { name: String! nickname: String url: URL! }

Slide 60

Slide 60 text

{ licenses { name nickname url } } type RootQuery { licenses: [License]! } type License { name: String! nickname: String url: URL! }

Slide 61

Slide 61 text

aliases

Slide 62

Slide 62 text

{ user(login: "defunkt") { name bio } user(login: "bswinnerton") { name bio } }

Slide 63

Slide 63 text

{ user(login: "defunkt") { name bio } user(login: "bswinnerton") { name bio } } { "data": { "user": { "name": "Chris Wanstrath", "bio": """ }, "user": { "name": "Brooks Swinnerton", "bio": "#$" } } }

Slide 64

Slide 64 text

{ user(login: "defunkt") { name bio } user(login: "bswinnerton") { name bio } } { "data": { "user": { "name": "Chris Wanstrath", "bio": """ }, "user": { "name": "Brooks Swinnerton", "bio": "#$" } } }

Slide 65

Slide 65 text

{ chris: user(login: "defunkt") { name bio } brooks: user(login: "bswinnerton") { name bio } }

Slide 66

Slide 66 text

{ "data": { "chris": { "name": "Chris Wanstrath", "bio": """ }, "brooks": { "name": "Brooks Swinnerton", "bio": "#$" } } }

Slide 67

Slide 67 text

{ "data": { "chris": { "name": "Chris Wanstrath", "bio": """ }, "brooks": { "name": "Brooks Swinnerton", "bio": "#$" } } }

Slide 68

Slide 68 text

fragments

Slide 69

Slide 69 text

{ chris: user(login: "defunkt") { name bio } brooks: user(login: "bswinnerton") { name bio } }

Slide 70

Slide 70 text

{ chris: user(login: "defunkt") { ...UserInfo } brooks: user(login: "bswinnerton") { ...UserInfo } } fragment UserInfo on User { name bio }

Slide 71

Slide 71 text

variables

Slide 72

Slide 72 text

{ user(login:"defunkt") { name bio } }

Slide 73

Slide 73 text

query { user(login:"defunkt") { name bio } }

Slide 74

Slide 74 text

query($login:String!) { user(login:$login) { name bio } }

Slide 75

Slide 75 text

{ "login": "defunkt" } query($login:String!) { user(login:$login) { name bio } }

Slide 76

Slide 76 text

{ "data": { "user": { "name": "Chris Wanstrath", "bio": """ } } } { "login": "defunkt" } query($login:String!) { user(login:$login) { name bio } }

Slide 77

Slide 77 text

mutations

Slide 78

Slide 78 text

mutation { createProject(input:{ownerId:"1234",name:"to do"}) { project { url } } }

Slide 79

Slide 79 text

mutation { createProject(input:{ownerId:"1234",name:"to do"}) { project { url } } }

Slide 80

Slide 80 text

mutation { createProject(input:{ownerId:"1234",name:"to do"}) { project { url } } }

Slide 81

Slide 81 text

mutation { createProject(input:{ownerId:"1234",name:"to do"}) { project { url } } }

Slide 82

Slide 82 text

{ "data": { "createProject": { "project": { "url": "https://github.com/rails/rails/projects/1" } } } }

Slide 83

Slide 83 text

Relay

Slide 84

Slide 84 text

{ viewer { repositories { totalCount } } }

Slide 85

Slide 85 text

{ viewer { repositories { totalCount } } } { "data": { "viewer": { "repositories": { "totalCount": 65 } } } }

Slide 86

Slide 86 text

{ viewer { repositories(first:2) { edges { node { name } } } } }

Slide 87

Slide 87 text

{ viewer { repositories(first:2) { edges { node { name } } } } }

Slide 88

Slide 88 text

viewer dotfiles failed startup code resume blog million dollar idea code

Slide 89

Slide 89 text

User Repository Repository Repository Repository Repository Edges

Slide 90

Slide 90 text

User Repository Repository Repository Repository Repository Nodes

Slide 91

Slide 91 text

{ viewer { repositories(first:2) { edges { node { name } } } } }

Slide 92

Slide 92 text

{ viewer { repositories(first:2) { edges { node { name } } } } }

Slide 93

Slide 93 text

{ viewer { repositories(first:2) { edges { node { name } } } } } { "data": { "viewer": { "repositories": { "edges": [ { "node": { "name": "nyc-restaurant-grades" } }, { "node": { "name": "launchbar-github" } } ] } } } }

Slide 94

Slide 94 text

{ viewer { repositories(first:2) { edges { cursor node { name } } } } } { "data": { "viewer": { "repositories": { "edges": [ { "cursor": "Y3Vyc29yOnYyOpHOA5rd9g==", "node": { "name": "nyc-restaurant-grades" } }, { "cursor": "Y3Vyc29yOnYyOpHOBOlMSg==", "node": { "name": "launchbar-github" } } ] } } } }

Slide 95

Slide 95 text

{ viewer { repositories(first:2) { edges { cursor node { name } } } } } { "data": { "viewer": { "repositories": { "edges": [ { "cursor": "Y3Vyc29yOnYyOpHOA5rd9g==", "node": { "name": "nyc-restaurant-grades" } }, { "cursor": "Y3Vyc29yOnYyOpHOBOlMSg==", "node": { "name": "launchbar-github" } } ] } } } }

Slide 96

Slide 96 text

{ viewer { repositories(first:2) { edges { cursor node { name } } } } } { "data": { "viewer": { "repositories": { "edges": [ { "cursor": "Y3Vyc29yOnYyOpHOA5rd9g==", "node": { "name": "nyc-restaurant-grades" } }, { "cursor": "Y3Vyc29yOnYyOpHOBOlMSg==", "node": { "name": "launchbar-github" } } ] } } } }

Slide 97

Slide 97 text

{ viewer { repositories(first:2, after:"Y3Vyc29yOnYyOpHOBOlMSg==") { edges { node { name } } } } }

Slide 98

Slide 98 text

{ "data": { "viewer": { "repositories": { "edges": [ { "cursor": "Y3Vyc29yOnYyOpHOAIibww==", "node": { "name": "bswinnerton.github.io" } }, { "cursor": "Y3Vyc29yOnYyOpHOArDTpw==", "node": { "name": "dotfiles" } } ] } } } }

Slide 99

Slide 99 text

GraphQL is introspectable

Slide 100

Slide 100 text

documentation and client generation, are free

Slide 101

Slide 101 text

https://developer.github.com/v4/explorer/

Slide 102

Slide 102 text

https://developer.github.com/v4/explorer/

Slide 103

Slide 103 text

https://developer.github.com/v4/explorer/

Slide 104

Slide 104 text

https://developer.github.com/v4/explorer/

Slide 105

Slide 105 text

https://developer.github.com/v4/explorer/

Slide 106

Slide 106 text

https://developer.github.com/v4/explorer/

Slide 107

Slide 107 text

https://developer.github.com/v4/explorer/

Slide 108

Slide 108 text

https://developer.github.com/v4/explorer/

Slide 109

Slide 109 text

https://developer.github.com/v4/explorer/

Slide 110

Slide 110 text

https://developer.github.com/v4/explorer/

Slide 111

Slide 111 text

https://developer.github.com/v4/explorer/

Slide 112

Slide 112 text

https://developer.github.com/v4/explorer/

Slide 113

Slide 113 text

https://developer.github.com/v4/explorer/

Slide 114

Slide 114 text

https://developer.github.com/v4/explorer/

Slide 115

Slide 115 text

https://developer.github.com/v4/explorer/

Slide 116

Slide 116 text

https://developer.github.com/v4/explorer/

Slide 117

Slide 117 text

multiple resources in one round trip

Slide 118

Slide 118 text

API Server /user /repositories /issues

Slide 119

Slide 119 text

API Server /graphql

Slide 120

Slide 120 text

how can we put API consumers first?

Slide 121

Slide 121 text

March 2008 API v1 April 2009 API v2 April 2011 API v3 Early 2016 ?

Slide 122

Slide 122 text

March 20, 2016: Proposal submitted April 6, 2016: Proof of concept April 12, 2016: New team created September 4th, 2016: Early access May 22, 2017: API v4

Slide 123

Slide 123 text

March 20, 2016: Proposal submitted April 6, 2016: Proof of concept April 12, 2016: New team created September 4th, 2016: Early access May 22, 2017: API v4

Slide 124

Slide 124 text

March 20, 2016: Proposal submitted April 6, 2016: Proof of concept April 12, 2016: New team created September 4th, 2016: Early access May 22, 2017: API v4

Slide 125

Slide 125 text

March 20, 2016: Proposal submitted April 6, 2016: Proof of concept April 12, 2016: New team created September 4th, 2016: Early access May 22, 2017: API v4

Slide 126

Slide 126 text

March 20, 2016: Proposal submitted April 6, 2016: Proof of concept April 12, 2016: New team created September 4th, 2016: Early access May 22, 2017: API v4

Slide 127

Slide 127 text

March 20, 2016: Proposal submitted April 6, 2016: Proof of concept April 12, 2016: New team created September 4th, 2016: Early access May 22, 2017: API v4 Today: 200 million queries/day

Slide 128

Slide 128 text

Rate Limiting

Slide 129

Slide 129 text

REST API: 5,000 req/hour

Slide 130

Slide 130 text

GraphQL: ?

Slide 131

Slide 131 text

GraphQL: 500,000 node count

Slide 132

Slide 132 text

GraphQL: 5,000 point score

Slide 133

Slide 133 text

{ viewer { repositories(last:100) { edges { node { name issues(last:50) { edges { node { title } } } } } } } rateLimit(dryRun:true) { nodeCount } }

Slide 134

Slide 134 text

{ viewer { repositories(last:100) { edges { node { name issues(last:50) { edges { node { title } } } } } } } rateLimit(dryRun:true) { nodeCount } }

Slide 135

Slide 135 text

{ viewer { repositories(last:100) { edges { node { name issues(last:50) { edges { node { title } } } } } } } rateLimit(dryRun:true) { nodeCount } } { "data": { "rateLimit": { "nodeCount": 5100 } } }

Slide 136

Slide 136 text

{ viewer { repositories(last:100) { edges { node { name issues(last:50) { edges { node { title } } } } } } } rateLimit(dryRun:true) { cost } } { "data": { "rateLimit": { "cost": 1 } } }

Slide 137

Slide 137 text

Schema Driven Development

Slide 138

Slide 138 text

UI Development Staff Ship Production REST API

Slide 139

Slide 139 text

but today…

Slide 140

Slide 140 text

all new features are built with GraphQL

Slide 141

Slide 141 text

from the start

Slide 142

Slide 142 text

GraphQL Staff Ship Production REST API UI Development

Slide 143

Slide 143 text

this allows us to build a true public API

Slide 144

Slide 144 text

this allows us to build a true public API

Slide 145

Slide 145 text

this allows us to build a true platform

Slide 146

Slide 146 text

github/graphql-client

Slide 147

Slide 147 text

exchange a query for Ruby objects

Slide 148

Slide 148 text

collocate our queries in our views

Slide 149

Slide 149 text

@result = GraphQL::Client.query(ProjectsQuery) <% @result.data.projects.each do |project| %>

<%= project.name %>

<% project.columns.each do |column| %>

<%= column.name %>

<%= column.cards.total_count %>

<% column.cards.each do |card| %> <% card.title %>

Opened by <%= card.owner.login %>

<% end %> <% end %> <% end %> Controller View

Slide 150

Slide 150 text

GraphQL-backed REST APIs

Slide 151

Slide 151 text

Staff Ship Production GraphQL UI Development REST API

Slide 152

Slide 152 text

github/scientist

Slide 153

Slide 153 text

https://api.github.com/user Legacy REST New GraphQL Return result Compare return values

Slide 154

Slide 154 text

ensures data accuracy

Slide 155

Slide 155 text

provides speed comparisons

Slide 156

Slide 156 text

gjtorikian/graphql-docs

Slide 157

Slide 157 text

https://github.com/gjtorikian/graphql-docs

Slide 158

Slide 158 text

https://github.com/gjtorikian/graphql-docs

Slide 159

Slide 159 text

automated changelog

Slide 160

Slide 160 text

https://developer.github.com/v4/changelog

Slide 161

Slide 161 text

community site

Slide 162

Slide 162 text

No content

Slide 163

Slide 163 text

What’s next for the GraphQL API

Slide 164

Slide 164 text

confidence in schema coverage

Slide 165

Slide 165 text

GitHub Apps integration

Slide 166

Slide 166 text

More information

Slide 167

Slide 167 text

https://developer.github.com

Slide 168

Slide 168 text

http://graphql.org

Slide 169

Slide 169 text

http://platform.github.community

Slide 170

Slide 170 text

thank you @bswinnerton