Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
GraphQL
Stefan Kanev
March 28, 2018
Programming
0
210
GraphQL
Stefan Kanev
March 28, 2018
Tweet
Share
More Decks by Stefan Kanev
See All by Stefan Kanev
Automated Testing: Getting it Right
skanev
1
40
From Novice to Expert
skanev
0
400
Inbetween Code and Profession
skanev
0
220
Clojure & ClojureScript
skanev
2
84
Extreme Programming
skanev
0
300
За смъртта на TDD
skanev
0
270
Python 0 2014
skanev
1
1.5k
Clojure 0 2014
skanev
0
360
Garbage Collection
skanev
0
180
Other Decks in Programming
See All in Programming
Quarto Tips for Academic Presentation
nicetak
0
920
AWSとCPUのムフフな関係
cmdemura
0
470
Hasura の Relationship と権限管理
karszawa
0
170
子育てとEMと転職と
_atsushisakai
1
400
xarray-Datatree: Hierarchical Data Structures for Multi-Model Science
tomnicholas
0
210
新卒でサービス立ち上げから Hasuraを使って3年経った振り返り
yutorin
0
220
Rによる大規模データの処理
s_uryu
2
630
%q is for Quine
koic
0
410
AWS App Runnerがそろそろ本番環境でも使い物になりそう
n1215
PRO
0
1k
ペパカレで入社した私が感じた2つのギャップと向き合い方
kosuke_ito
0
260
CDKでValidationする本当の方法 / cdk-validation
gotok365
1
200
An Advanced Introduction to R
nicetak
0
1.8k
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
689
180k
4 Signs Your Business is Dying
shpigford
171
20k
What’s in a name? Adding method to the madness
productmarketing
12
1.9k
Typedesign – Prime Four
hannesfritz
34
1.5k
Docker and Python
trallard
30
1.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
109
16k
Unsuck your backbone
ammeep
659
56k
Navigating Team Friction
lara
177
12k
Principles of Awesome APIs and How to Build Them.
keavy
117
15k
Building Flexible Design Systems
yeseniaperezcruz
314
35k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
24
4.5k
Code Reviewing Like a Champion
maltzj
508
38k
Transcript
GraphQL Stefan Kanev http://skanev.com/ @skanev Slovenia Ruby User Group 28
March 2018 Ljubljana Why is it exciting?
Hi, I’m Stefan
skanev skanev skanev.com about.me/skanev
Chief Technical Officer @
None
Despite the management title, I still tend to think of
myself as a programmer
None
This should be part talk, part Q&A
1 2 3 4 Walkthrough Demonstration Benefits React and Relay
1 Walkthrough
It’s not a technology It’s a standard
queries vs. mutations “gets” data changes stuff
queries vs. mutations “gets” data changes stuff
Queries data on the server is represented as a graph
the client specifies which part of the graph to fetch server returns only those parts the input is in a special language the output is in JSON
None
None
query { hero { name friends { name } }
} Query { "data": { "hero": { "name": "R2-D2", "friends": [ { "name": "Luke Skywalker" }, { "name": "Han Solo" }, { "name": "Leia Organa" } ] } } } Response
Query query { hero { name appearsIn friends { name
appearsIn } } } Response { "data": { "hero": { "name": "R2-D2", "appearsIn": ["NEWHOPE", "EMPIRE", "JEDI"], "friends": [ { "name": "Luke Skywalker", "appearsIn": ["NEWHOPE", "EMPIRE", "JEDI"] }, { "name": "Han Solo", "appearsIn": ["NEWHOPE", "EMPIRE", "JEDI"] }, { "name": "Leia Organa", "appearsIn": ["NEWHOPE", "EMPIRE", "JEDI"] } ] } } }
Schema the graph is composed of objects each object
is of a specific type each type defines a number of fields each field has a type there is a form of polymorphism
type Character { name: String! friends: [Character]! appearsIn: [Episode]! }
type Character { name: String! friends: [Character!]! appearsIn: [Episode!]! } By the way, this… …is better in a different way: Anybody see the difference?
queries vs. mutations “gets” data changes stuff
Mutations each mutation is a separate endpoint it’s RPC-like
(conceptually similar to REST mutations) it still goes through the GraphQL language we’ll see an example later
2 Demonstration
3 Benefits
Caveat emptor It might be a better fit for when
you control the client, as opposed to letting anybody create a client The complexity on the backend is a magnitude bigger
Self-documenting
Decouples clients from backend once the graph is large enough,
clients won’t need to request (as many) endpoints for reading it’s closer to “write once”
Versionless evolution Versioning APIs is a bitch You can
get away with not doing it to a large extent (example)
Traffic optimisation You get only what you asked for
You can get multiple things with a single request
Structure It provides a lot of structure to build 3rd
party tools on (especially in comparison to REST) GraphiQL is a good example Apollo Engine is another one Relay is the most interesting example
4 React and Relay
None
None
?