Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GraphQL on Rails
Search
Marc-Andre Giroux
March 15, 2016
Programming
3
1.1k
GraphQL on Rails
Introduction to GraphQl and how to use it in Rails.
Marc-Andre Giroux
March 15, 2016
Tweet
Share
More Decks by Marc-Andre Giroux
See All by Marc-Andre Giroux
It Depends - Examining GraphQL Myths & Assumptions
xuorig
0
88
So you Want to Distribute your GraphQL Schema?
xuorig
4
810
So you Want to Distribute your GraphQL Schema?
xuorig
0
530
GraphQL Schema Design @ Scale
xuorig
5
2.1k
Continuous Evolution of GraphQL Schemas @ GitHub
xuorig
3
2.1k
GraphQL à Shopify
xuorig
0
220
Exploring GraphQL
xuorig
0
250
GraphQL @ Shopify
xuorig
6
1.6k
GraphQL on Rails
xuorig
2
340
Other Decks in Programming
See All in Programming
신입 안드로이드 개발자의 AI 스타트업 생존기 (+ Native C++ Code를 Android에서 사용해보기)
dygames
0
510
CRE Meetup!ユーザー信頼性を支えるエンジニアリング実践例の発表資料です
tmnb
0
420
AtCoder Heuristic First-step Vol.1 講義スライド(山登り法・焼きなまし法編)
takumi152
3
1k
Go1.24 go vetとtestsアナライザ
kuro_kurorrr
2
690
新卒から4年間、20年もののWebサービスと 向き合って学んだソフトウェア考古学
oguri
8
6.9k
Develop Faster With FrankenPHP
dunglas
2
2.8k
複雑なフォームと複雑な状態管理にどう向き合うか / #newt_techtalk vol. 15
izumin5210
4
3.5k
Denoでフロントエンド開発 2025年春版 / Frontend Development with Deno (Spring 2025)
petamoriken
1
1.3k
小さく段階的リリースすることで深夜メンテを回避する
mkmk884
2
130
20250326_生成AIによる_レビュー承認システムの実現.pdf
takahiromatsui
17
5.7k
SLI/SLOの設定を進めるその前に アラート品質の改善に取り組んだ話
tanden
2
740
体得しよう!RSA暗号の原理と解読
laysakura
3
540
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Done Done
chrislema
183
16k
Bash Introduction
62gerente
611
210k
Automating Front-end Workflow
addyosmani
1369
200k
Being A Developer After 40
akosma
90
590k
A better future with KSS
kneath
238
17k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.6k
BBQ
matthewcrist
88
9.5k
We Have a Design System, Now What?
morganepeng
51
7.5k
Writing Fast Ruby
sferik
628
61k
Transcript
GraphQL on Rails FROM REST TO GRAP HQL @ _
_XU O R IG _ _
@ _ _XU O R IG _ _
/product/1 product/1/photos/a product/1/photos/b product/1/variants
Way too many roundtrips!
/productview?include=variants&photo_count=2
/productview_thumbnail?include=price /productview_thumbnail?include=price&photo_size=small /productview_super_special_thumbnail_with_description?photo_size=100,1000 /an_endpoint_that_returns_a_bunch_of_things_that_i_need_for_a_particular_view
Better, but quickly becomes a nightmare.
Server Client product view v1 product model v1 update endpoints
create new endpoints product view v2 product view v3 product model v2 product model v3
GraphQL to the rescue
{ myShop { name } } Selection set Field
{ “myShop” { “name”: “GitHub” } } { myShop {
name } } Lexed Parsed Validated Executed
{ myShop { name } }
{ shop(id: 19423) { name } } { myShop {
name } }
{ myShop { name location { city address } }
}
{ “myShop” { “name”: “GitHub” “location”: { “city”: “San Francisco”
“address”: “88 Colin P Kelly Jr St” } } }
The Type System
{ myShop { name location { city address } products(orderby:
POPULARITY) { name price } } }
{ myShop { name location { city address } products(orderby:
POPULARITY) { name price } } } type QueryRoot { myShop: Shop shop(id: Int): Shop }
{ myShop { name location { city address } products(orderby:
POPULARITY) { name price } } } type Shop { name: String location: Address products(orderby: OrderEnum): [Product] } enum ProductOrderEnum { PRICE, POPULARITY, ALPHABETICAL }
{ myShop { name location { city address } products(orderby:
POPULARITY) { name price } } } type Address { city: String address: String }
{ myShop { name location { city address } products(orderby:
POPULARITY) { name price } } } type Product { name: String price: Int }
Server Client H ER E I S P RO DU
C T W I TH I D = 1 G ET P R OD U C T W IT H I D= 1
Server Client EX P O SES S C HE M
A O F AL L PO S SI B I L IT I ES ( T Y P E SYS T EM ) DATA R EQ UI R EM EN T S (G R AP H Q L LA N GUAG E )
Server Client O K H ER E’S EX AC T
LY T HE DATA YO U NEE D G I VE ME DATA O F T HAT PAR T IC U LA R S H AP E
Server Client product view v1 Product model v1 product view
v3 Product model v3 product view v2 Product model v2 Doesn’t care
One endpoint to rule them all
Web iOS App POS App Android App
Fragments
{ myShop { name location { city address } }
}
{ myShop { name …locationFragment } } fragment locationFragment on
Shop { location { city address } }
Mutations
{ createBlog(title: “my cool blog") { title } }
Introspection
None
IDE integration Static Validation Code Generation Auto Documentation
GraphQL on Rails
rails generate model Blog title:string content:string author_id:integer rails generate model
Author name:string class Blog < ActiveRecord::Base has_one :author end
GEM ‘GRAPHQL’
None
None
None
query allBlogs { blogs { title author { name }
} }
{ "data": { "blogs": [ { "title": "Intro to GraphQL",
"content": "Something something something. Blah blah blah. Etc etc etc.", "author": { "name": "Marc-Andre Giroux" } }, { "title": "Hello, it's me", "content": "I've been wondering", "author": { "name": "Marc-Andre Giroux" } }, { "title": "Hello, it's me", "content": "I've been wondering", "author": { "name": "Marc-Andre Giroux" } } ] } }
GraphiQL
MG I ROUX.M E G RAPH QL-SLACK .HE R OK
UA P P.COM/ Slack channel My blog graphql-ruby G IT HU B.COM /R MO SO LG O/ G R A P H Q L-R U BY Twitter @__ XUORI G__
Thank You :D