Slide 1

Slide 1 text

+ a

Slide 2

Slide 2 text

Hi, I’m Brooks

Slide 3

Slide 3 text

I work at !

Slide 4

Slide 4 text

let’s talk about launching the GitHub GraphQL API

Slide 5

Slide 5 text

How our GraphQL API came to be

Slide 6

Slide 6 text

March 20th, 2016 proposal submitted

Slide 7

Slide 7 text

we had dreams of APIv4

Slide 8

Slide 8 text

multiple resources in one roundtrip

Slide 9

Slide 9 text

schema introspection

Slide 10

Slide 10 text

April 6th, 2016 proof of concept done

Slide 11

Slide 11 text

{ current_user { login repositories(affiliation: "owner") { id name } } }

Slide 12

Slide 12 text

April 12th, 2016 New team created

Slide 13

Slide 13 text

September 14th, 2016 early access

Slide 14

Slide 14 text

Today >100 million queries/day

Slide 15

Slide 15 text

We learned some things along the way

Slide 16

Slide 16 text

Tooling

Slide 17

Slide 17 text

documentation

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

GraphiQL all-in-one

Slide 20

Slide 20 text

"but we’re going to need a Ruby client"

Slide 21

Slide 21 text

github/graphql-client

Slide 22

Slide 22 text

objects in exchange for a query

Slide 23

Slide 23 text

collocate our queries with our views

Slide 24

Slide 24 text

but in Rails

Slide 25

Slide 25 text

query profiling

Slide 26

Slide 26 text

query { repository(owner:"rails", name:"rails") { viewerHasStarred } }

Slide 27

Slide 27 text

{ "data": { "repository": { "viewerHasStarred": false } }, "extensions": { "totalDuration": 42.06737782806158, "trackedAssociations": {}, "profiling": { "Repository:viewerHasStarred": { "type": "Boolean!", "sql": [ { "duration": 2.07, "sql": "SELECT 1 AS one FROM `repositories` INNER JOIN `stars` ON `repositories`.`id` = `stars`.`starrable_id` WHERE `stars`.`user_id` = 934497 AND `stars`.`starrable_type` = 'Repository' AND `repositories`.`id` = 8514 LIMIT 1 " } ] } } } }

Slide 28

Slide 28 text

Authorization

Slide 29

Slide 29 text

reusing the OAuth logic from our REST API

Slide 30

Slide 30 text

OAuth scopes are granted to a token

Slide 31

Slide 31 text

token is used to make a request

Slide 32

Slide 32 text

familiar to our users

Slide 33

Slide 33 text

less for us to build

Slide 34

Slide 34 text

Organization = GraphQL::ObjectType.define do name "Organization" accepted_scopes ["read:org", "admin:org"] end

Slide 35

Slide 35 text

Organization = GraphQL::ObjectType.define do name "Organization" accepted_scopes ["read:org", "admin:org"] end

Slide 36

Slide 36 text

but with ✨ GraphQL ✨…

Slide 37

Slide 37 text

we can analyze the query before resolution

Slide 38

Slide 38 text

query { organization(login:"github") { members { totalCount } } }

Slide 39

Slide 39 text

query { organization(login:"github") { members { totalCount } } }

Slide 40

Slide 40 text

Organization = GraphQL::ObjectType.define do name "Organization" accepted_scopes ["read:org", "admin:org"] end

Slide 41

Slide 41 text

but this isn’t perfect

Slide 42

Slide 42 text

in some cases you need to perform resolution first

Slide 43

Slide 43 text

repo vs public_repo

Slide 44

Slide 44 text

we’ve introduced an authz layer for resolution

Slide 45

Slide 45 text

Schema design

Slide 46

Slide 46 text

first off

Slide 47

Slide 47 text

there’s more than one

Slide 48

Slide 48 text

one for new & sensitive features

Slide 49

Slide 49 text

one for everyone else

Slide 50

Slide 50 text

Organization = GraphQL::ObjectType.define do name "Organization" accepted_scopes ["read:org"] end

Slide 51

Slide 51 text

Organization = GraphQL::ObjectType.define do name "Organization" accepted_scopes ["read:org"] visibility :public end

Slide 52

Slide 52 text

Organization = GraphQL::ObjectType.define do name "Organization" accepted_scopes ["read:org"] visibility :public end

Slide 53

Slide 53 text

CoolNewFeature = GraphQL::ObjectType.define do name "CoolNewFeature" accepted_scopes ["repo"] visibility :internal end

Slide 54

Slide 54 text

mandatory first/last arguments on connections

Slide 55

Slide 55 text

query { viewer { repositories(last:30) { edges { node { name } } } } }

Slide 56

Slide 56 text

query { viewer { repositories(last:30) { edges { node { name } } } } }

Slide 57

Slide 57 text

is/has/can prefix

Slide 58

Slide 58 text

query { repository(owner:"rails", name:"rails") { isFork hasIssuesEnabled viewerCanAdminister } }

Slide 59

Slide 59 text

query { repository(owner:"rails", name:"rails") { isFork hasIssuesEnabled viewerCanAdminister } }

Slide 60

Slide 60 text

avoiding fields that should be types

Slide 61

Slide 61 text

query { repository(owner:"rails", name:"rails") { ownerLogin } }

Slide 62

Slide 62 text

query { repository(owner:"rails", name:"rails") { ownerLogin } }

Slide 63

Slide 63 text

query { repository(owner:"rails",name:"rails") { owner { login } } }

Slide 64

Slide 64 text

Feature Parity

Slide 65

Slide 65 text

schema driven development* *stay tuned!

Slide 66

Slide 66 text

with our REST API

Slide 67

Slide 67 text

new features were developed for the UI

Slide 68

Slide 68 text

then staff-shipped

Slide 69

Slide 69 text

then released

Slide 70

Slide 70 text

REST API work started after the ship

Slide 71

Slide 71 text

but, today…

Slide 72

Slide 72 text

all new features are built with GraphQL

Slide 73

Slide 73 text

from the start

Slide 74

Slide 74 text

CoolNewFeature = GraphQL::ObjectType.define do name "CoolNewFeature" accepted_scopes ["repo"] visibility :internal end

Slide 75

Slide 75 text

CoolNewFeature = GraphQL::ObjectType.define do name "CoolNewFeature" accepted_scopes ["repo"] visibility :internal end

Slide 76

Slide 76 text

CoolNewFeature = GraphQL::ObjectType.define do name "CoolNewFeature" accepted_scopes ["repo"] visibility :public end

Slide 77

Slide 77 text

this allows us to build a true public API

Slide 78

Slide 78 text

this allows us to build a true public API

Slide 79

Slide 79 text

this allows us to build a true platform

Slide 80

Slide 80 text

shared between GitHubbers and integrators

Slide 81

Slide 81 text

but change is scary

Slide 82

Slide 82 text

GraphQL-backed REST APIs

Slide 83

Slide 83 text

this works great for new features

Slide 84

Slide 84 text

but what about legacy features?

Slide 85

Slide 85 text

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

Slide 86

Slide 86 text

enter Scientist

Slide 87

Slide 87 text

github/scientist

Slide 88

Slide 88 text

measure data discrepancies

Slide 89

Slide 89 text

measure the difference in performance

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

Where we’re headed

Slide 92

Slide 92 text

static analysis of schema during code review

Slide 93

Slide 93 text

rate limiting

Slide 94

Slide 94 text

expose global relay IDs in REST API

Slide 95

Slide 95 text

preview new fields and objects with headers

Slide 96

Slide 96 text

Thank you
 @bswinnerton on Twitter & GitHub @brooks on Slack