Slide 1

Slide 1 text

Rescuing legacy codebases with GraphQL and Rails @nettofarah

Slide 2

Slide 2 text

Netto Farah @nettofarah !"

Slide 3

Slide 3 text

Conference speakers are professional enthusiasts Take this with a grain of salt

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Context • Website, iOS app, Android app • Seasoned Rails 3 codebase

Slide 6

Slide 6 text

Technical Challenge • Build an entirely new website and mobile apps • Iterate fast (9 months deadline)

Slide 7

Slide 7 text

We knew we needed to make some changes

Slide 8

Slide 8 text

Majestic Monoliths vs Micro-services

Slide 9

Slide 9 text

Not a binary decision

Slide 10

Slide 10 text

A hybrid approach: Rich API + specific clients

Slide 11

Slide 11 text

Challenges with Traditional APIs

Slide 12

Slide 12 text

Multiple use cases

Slide 13

Slide 13 text

with different access patterns

Slide 14

Slide 14 text

Documentation and Conventions

Slide 15

Slide 15 text

[%,",&..'] => ✅ )

Slide 16

Slide 16 text

) [!] => ask me later…

Slide 17

Slide 17 text

GraphQL a language specification for 
 defining and querying APIs

Slide 18

Slide 18 text

Describe your data with TYPES

Slide 19

Slide 19 text

type Rubygem { name: String downloads: Int versions: [Version] }

Slide 20

Slide 20 text

Load just what you need

Slide 21

Slide 21 text

query { rubygems {
 name downloads } }

Slide 22

Slide 22 text

You can even load multiple entities at once

Slide 23

Slide 23 text

query { rubygems {
 name, downloads } current_user { login, email } }

Slide 24

Slide 24 text

Get predictable results

Slide 25

Slide 25 text

{ "data": { "rubygem": { "name": "rails", "downloads": 89321853 }, “current_user": { "login": "nettofarah", "email": “nettofarah@gmail.com" } } }

Slide 26

Slide 26 text

GraphQL focuses on the clients

Slide 27

Slide 27 text

GraphQL + Ruby = ❤

Slide 28

Slide 28 text

Demo time!

Slide 29

Slide 29 text

RubyGems API Rubygem Version Dependency has_many has_many

Slide 30

Slide 30 text

RubyGems API - use cases • list all available rubygems • search one specific rubygem by name

Slide 31

Slide 31 text

Let’s see some code! http://bit.ly/gql-demo

Slide 32

Slide 32 text

We built a GraphQL API on top of our data model

Slide 33

Slide 33 text

GraphQL API as an integration layer for multiple (not so micro) services and front-ends

Slide 34

Slide 34 text

GraphQL API ☁ A P I 
 G
 A
 T E
 W
 A Y Service A Service B Service C

Slide 35

Slide 35 text

GraphQL API ⛈ A P I 
 G
 A
 T E
 W
 A Y Service A Service B Service C

Slide 36

Slide 36 text

GraphQL in production

Slide 37

Slide 37 text

What happened to semantic status codes?

Slide 38

Slide 38 text

N+1 queries

Slide 39

Slide 39 text

github.com/nettofarah/graphql-query-resolver

Slide 40

Slide 40 text

Monitoring and Errors

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

http://bit.ly/gql-rb-nr

Slide 45

Slide 45 text

Where to go next? • graphql.org • graphql.slack.com (#ruby - I hang out there) • https://github.com/rmosolgo/graphql-ruby

Slide 46

Slide 46 text

@nettofarah nettofarah@gmail.com