Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Universal JS day - GraphQL
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Marco Sampellegrini
April 16, 2016
Programming
28
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Universal JS day - GraphQL
Marco Sampellegrini
April 16, 2016
More Decks by Marco Sampellegrini
See All by Marco Sampellegrini
MilanoJS 2017 - Elm in Production
alpacaaa
0
73
WebAppConf 2017 - Elm in Production
alpacaaa
1
160
DevFest Vienna - GraphQL
alpacaaa
0
38
MilanoJS - GraphQL
alpacaaa
0
61
Other Decks in Programming
See All in Programming
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
AmebaブログはKMPから卒業します
kmars0605
0
190
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
260
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.2k
すこし踏み込む CancellationToken
htkym
2
1.7k
残高管理から台帳サービスへの進化
artoy
1
200
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
700
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.2k
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Practical Orchestrator
shlominoach
192
12k
For a Future-Friendly Web
brad_frost
184
10k
Typedesign – Prime Four
hannesfritz
42
3.2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
GraphQLとの向き合い方2022年版
quramy
50
15k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
270
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
820
Transcript
GRAPHQL UNIVERSAL JS DAY – 2016
github.com/alpacaaa MARCO SAMPELLEGRINI
Small team – 5 people 100% Javascript codebase React Native
– React – Node.js – RethinkDB Currently working on a classi ed project
A data query and data manipulation language for client apps
ALTERNATIVE TO REST
EXAMPLE: GITHUB REPO PAGE
Start by breaking down the UI into a component hierarchy
THINKING IN REACT
THINKING IN REACT 1. <Repo> 2. <RepoInfo /> 3. <LastCommit
/> 4. 5. <RepoTree> 6. <TreeEntry> 7. <FileLastCommit /> 8. </TreeEntry> 9. 10. <TreeEntry> 11. <FileLastCommit /> 12. </TreeEntry> 13. 14. <TreeEntry> 15. <FileLastCommit />
None
REPO INFO
/repos/jonsuh/hamburgers 1. { 2. "id": 52645453, 3. "name": "hamburgers", 4.
"full_name": "jonsuh/hamburgers", 5. "html_url": "https://github.com/jonsuh/hamburgers", 6. "description": "Tasty CSSanimated Hamburgers", 7. ... 8. } 9.
LAST COMMIT
/commits/master 1. [ 2. { 3. "sha": "c06b0d54ca327f8507fd1e032a0adf69c170f122", 4. "commit":
{ 5. "message": "Update readme with new preview.", 6. "date": "20160307T15:12:22Z", 7. ... 8. }, 9. "author": { 10. "login": "jonsuh", 11. "id": 359871, 12. "avatar_url": "https://avatars.githubusercontent.com/u/359871?v=3", 13. ... 14. },
TREE
/git/trees/master 1. { 2. "tree": [ 3. { 4. "path":
".gitignore", 5. "sha": "ea60652264db43aab511d4cec0882f55908dbc59", 6. }, 7. { 8. "path": "README.md", 9. "sha": "b1d830c56ac8232269ea751e3729ea104c476761", 10. }, 11. { 12. "path": "index.html", 13. "sha": "72f0f97bf2aa5655bc6ca61b0c62df01af7b478c", 14. }, 15. {
CAN WE START CODING???
TREE ENTRY
/git/commits?path=.gitignore 1. [ 2. { 3. "sha": "2732635e20531fb0a63d1d40eca0c24105f1b3e0", 4. "commit":
{ 5. "message": "Flatten asset directory structure.", 6. "date": "20160226T22:39:51Z", 7. ... 8. }, 9. "author": { 10. "login": "jonsuh", 11. }, 12. ... 13. } 14. ] 15.
.gitignore README.md index.html ONE REQUEST PER ENTRY
PROBLEMS Many roundtrips to the server Lots of data we
don't need GBOJ – Giant Blob of JSON
THAT WAS FUN!
MEET GRAPHQL
QUERY { repo(ownerUsername: "jonsuh" name: "hamburgers") { description } }
RESULT { "data": { "repo": { "description": "Tasty CSS-animated Hamburgers" } } } HELLO WORLD IN GRAPHQL
LAST COMMIT { repo(ownerUsername: "jonsuh" name: "hamburgers") { description commits(limit:
1) { sha message date } } } { "repo": { "description": "Tasty CSS-animated Hamburgers", "commits": [ { "sha": "c06b0d54ca327f8507fd1e032a0adf69c170f122", "message": "Update readme with new preview.", "date": "2016-03-07T15:12:22Z" } ] } }
TREE { repo(ownerUsername: "jonsuh" name: "hamburgers") { description commits(limit: 1)
{ sha message date tree { entries { path } } } } } { "repo": { "description": "Tasty CSS-animated Hamburgers", "commits": [ { "sha": "c06b0d54ca327f8507fd1e032a0adf69c170f122", ... "tree": { "entries": [ { "path": ".gitignore" }, { "path": "README.md" }, { "path": "index.html" } ... ] } } ] } }
TREE ENTRY { repo(ownerUsername: "jonsuh" name: "hamburgers") { description commits(limit:
1) { sha message date tree { entries { path last_commit { sha message date } } } } } } { "repo": { "description": "Tasty CSS-animated Hamburgers", "commits": [ { "sha": "c06b0d54ca327f8507fd1e032a0adf69c170f122", ... "tree": { "entries": [ { "path": ".gitignore", "last_commit": { "message": "Flatten asset directory structure.", "date": "2016-02-26T22:39:51Z", } }, { "path": "README.md" "last_commit": { ... } } ... ] } } ] } }
TREE ENTRY { repo(ownerUsername: "jonsuh" name: "hamburgers") { description commits(limit:
1) { sha message date tree { entries { path last_commit { sha message date } } } } } } <Repo> <RepoInfo /> <LastCommit /> <RepoTree> <TreeEntry> <FileLastCommit /> </TreeEntry> <TreeEntry> <FileLastCommit /> </TreeEntry> <TreeEntry> <FileLastCommit /> </TreeEntry> ... </RepoTree> </Repo>
What you request is what you get WYRIWYG
Client is responsible for the data returned DECLARATIVE
TYPE SYSTEM
Single root schema Root schema made up of elds Fields
must have a speci c type Developers can de ne their own types GRAPHQL SCHEMA
IMPLEMENT A GRAPHQL SERVER in Node.js
OFFICIAL MODULES graphql-js express-graphql
TYPES WE NEED 2. GithubUser : Object { 3. id
: Int 4. login : String 5. company : String 6. avatar_url : String 7. repos : [GithubRepo] 8. } 1. 9. 10. 11. GithubRepo : Object { 12. id : Int 13. name : String 14. owner : GithubUser 15. issues : [GithubIssue] 16. commits : [GithubCommit] 17. } 18. 19. 20. GithubCommit : Object {
TYPE DEFINITION 2. import { 3. GraphQLObjectType, 4. GraphQLString, 5.
GraphQLNonNull, 6. GraphQLInt, 7. GraphQLFloat, 8. GraphQLBoolean, 9. GraphQLList, 10. } from 'graphql'; 11. 12. 13. const UserType = new GraphQLObjectType({ 14. name: 'GithubUser', 15. fields: () => ({ 16. login: { 1.
ROOT SCHEMA 2. const schema = new GraphQLSchema({ 3. query:
new GraphQLObjectType({ 4. name: 'RootQueryType', 5. fields: { 6. repo: { 7. type: RepoType, 8. args: { 9. name: { 10. description: 'Name of the repo', 11. type: new GraphQLNonNull(GraphQLString), 12. }, 13. ownerUsername: { 14. description: 'Username of the owner', 15. type: new GraphQLNonNull(GraphQLString), 16. } 1.
TOOLING: GRAPHIQL An IDE for building GraphQL queries
None
THANKS!