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
Introduction to Graph API
Search
Yosuke Kurami
May 27, 2016
Programming
370
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Graph API
Yosuke Kurami
May 27, 2016
More Decks by Yosuke Kurami
See All by Yosuke Kurami
TypeScript LSP の今までとこれから
quramy
1
2k
フロントエンドテストの育て方
quramy
12
3.8k
App Router 悲喜交々
quramy
8
730
上手に付き合うコンポーネントテスト
quramy
6
2.3k
Patched fetch did not work
quramy
6
780
GraphQL あるいは React における自律的なデータ取得について
quramy
18
5.8k
Next.js App Router
quramy
15
3.9k
Fragment Composition of GraphQL
quramy
17
4.8k
reg-viz VRT tools
quramy
4
1.7k
Other Decks in Programming
See All in Programming
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
150
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.2k
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
240
AIで効率化できた業務・日常
ochtum
0
120
dRuby over BLE
makicamel
2
330
New "Type" system on PicoRuby
pocke
1
810
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
2k
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
450
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
1
660
The NotImplementedError Problem in Ruby
koic
1
700
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
260
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
230
Featured
See All Featured
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
230
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
200
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
AI: The stuff that nobody shows you
jnunemaker
PRO
8
700
Chasing Engaging Ingredients in Design
codingconduct
0
220
Deep Space Network (abreviated)
tonyrice
0
170
Prompt Engineering for Job Search
mfonobong
0
340
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The agentic SEO stack - context over prompts
schlessera
0
810
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
Abbi's Birthday
coloredviolet
2
8k
Transcript
Introduction to graph API ~ GraphQL and Falcor ~ @Quramy
2016.05.27
About me Yosuke Kurami ǛQuarry TypeScript༻ͷVimϓϥΪϯ։ൃ͕झຯɻ http://vimawesome.com/plugin/tsuquyomi ຊۀWeb front-end Developer.
Angular (1 and 2)ͰSPAΛ։ൃ͍ͯ͠·͢
SPA
Single Page Application
Single Page Application Ƀ Ȑ {JSON} ɂ Ʌ HTTP
Today’s theme: Ƀ Ȑ {JSON} ɂ Ʌ HTTP
How to design API? endpointͷཻɺͲΕ͘Β͍͕దͰ͔͢? 1. ResourceʹશͯURLΛৼͬͯlinkͰଓʁ 2. Request͠қ͍Α͏ؔ࿈Resourcepopulateʁ
1. Thin endpoint Ƀ Ȑ { “id”: “123”, “title”: “graph
API”, “author”: “/api/v1/users/u0001” } ɂ Ʌ Get /api/v1/articles/123 Get /api/v1/users/u0001 { “id”: “u0001”, “name”: “quramy” }
1. Thin endpoint ֤ResourceURL LinkͰ݁߹͞Ε͍ͯΔɿ RESTful APIͷݪଇ௨Γ Endpointࣗମͷ࠶ར༻ੑߴ͍ RenderingʹෳRequest͕ඞཁ
2. Fat endpoint Ƀ Ȑ { “id”: “123”, “title”: “graph
API”, “author”: { “id”: “u0001”, “name”: “quramy” } } ɂ Ʌ Get /api/v1/articles/123
2. Fat endpoint Responseʹଟ͘ͷใΛωετͤ͞Δ: ը໘ͷ3FOEFSJOHָ ͦͯ͠ߴ . Endpointͷ࠶ར༻ੑ͍ ը໘ཁ݅ʹҾͬுΒΕͯɺ&OEQPJOUվम͕ඞཁͱͳΔ
View only knows what values to render Client͕Response༰ͷܾఆݖΛ࣋ͯΑ͍: • ϨεϙϯεʹͲͷؚ͕·Ε͍ͯΔ͖͔
• ඥ͍ͮͨؔ࿈Ϧιʔε͕ඞཁ͔Ͳ͏͔
Ideal endpoint Ƀ Ȑ { “id”: “123”, “title”: “graph api”,
“author”: { “id”: “u0001”, “name”: “quramy” } } ɂ Ʌ { “where”: “/article?id=123”, “properties”: [ “id”, “title”, “author”: { “properties”: [“id”, “name”] }] }
So, graph API
There are 2 major libraries GraphQL powered by Facebook http://graphql.org/
Falcor powered by Netflix http://netflix.github.io/falcor/
GraphQL
GraphQL: GraphQL is a query language import assert from "assert";
import { parse } from "graphql/language"; import { execute } from "graphql/execution"; import { schema } from "./schema"; execute(schema, parse(` { article(id :"123") { id, title, author { id, name } } } `)).then(response => { assert.deepEqual(response.data, { article: { id: "123", title: "graph api", author: { id: "u0001", name: "quramy" } } }); });
GrahpQLΛར༻͢ΔʹSchemaͷఆ͕ٛඞਢ ʮarticle(id: “123”)͕औಘՄೳʯͷใશͯSchemaʹఆ͓ٛͯ͠ ͘ඞཁ͕͋Δ GraphQL: GraphQL has solid Schema Ȑ
schema Inquire Implement
GraphQL: pros/cons • Pros: • JavaScriptҎ֎Ͱ৭ʑͳݴޠ(Java, golang, Ruby, etc…)Ͱར༻Մೳͳlibrary ͕͋Δɻ
• GraphiQlChrome Extensionɺ։ൃิॿπʔϧ๛ɻ • Cons: • शಘίετ͕ߴ͍. SchemaΛखΈͰΉͱࢮͶͦ͏. • Relay(React.js + GraphQLͷϑϨʔϜϫʔΫ)ߴػೳͰ͋ΔҰํɺGraphQL ࣗମͷRIͰ͋ΔGraphQL.jsը໘͔Β͏͜ͱΛߟ͑Δͱ૬γϣϘ͍ɻ ڧ੍తʹReact.jsʹϩοΫΠϯ͞Εͦ͏ɻ
GraphQL: Tools example e.g. Execution query with GraphiQL:
Falcor
Falcor: Access as the JSON way import { Model }
from "falcor"; import { dataSource } from "./dataSource"; import assert from "assert"; new Model({ source: dataSource, }).get( "article['123']['id', 'title']", "article['123'].author['id', 'name']" ).subscribe(response => { assert.deepEqual(response.json, { article: { "123": { id: "123", title: "graph api", author: { id: "u0001", name: "quramy" } } } }); });
Falcor “Virtual JSON Graph” ΛClient, ServerํͰڞ༗͢Δ ClientVirtual JSON Graphͷ෦ू߹ΛऔΓग़͢. Falcor:
Model as one JSON Object Ȑ JSON Graph
Falcor: pros/cons • Pros: • Έ͕୯७Ͱ͋Γɺशಘ͕༰қɻ • ७ਮͳData Fetching Library
Ͱ͋ΔͨΊɺClient-Side MVC͕ϩοΫΠϯ͞Ε ͳ͍ɻAngularͩΖ͏ͱVue.jsͩΖ͏ͱԿͰΈ߹ΘͤΒΕΔɻ • falcor.jsʹCaching, Batching, onChange, ͋Δͱخ͍͠ػೳҰ௨Γἧͬͯ ͍Δ • Cons: • Server-Side࣮جຊతʹNode.jsҰ(ҰԠC#࣮͋ΔΒ͍͚͠Ͳ…) • ࣮ߦ͠ͳ͍ͱJSON GraphͷܕใΛऔಘग़དྷͳ͍
Summary
GraphQL v.s. Falcor • GraphQLʹݫີͳSchemaఆ͕ٛଘࡏ͢ΔҰํ, Falcorʹ͓͚ ΔJSON Graphߏ҉(ͦͷ, ֶश࣮ίετΊ) •
Server-SideͱClient-Sideͷ࣮νʔϜ͕͞Ε͍ͯΔ߹ GraphQLબΜͩํ͕ྑ͍ͣɻ • ٯʹ, Front-End νʔϜ͕Endpointͷ࣮·Ͱग़དྷΔͷͰ͋Ε , FalcorͰඞཁॆͳέʔε͕ଟͦ͏ɻ
Graph API • طଘͷREST endpointΛϥοϓ͢Δ༻్ͷ߹ɺͦΕ΄ͲϝϦοτແ ͍ɻ ಛʹViewʹಛԽͨ͠EndpointઃܭΛ͍ͯ͠ΔέʔεͰҰGraphͷܗࣜ ʹਖ਼نԽ͢Δख͕͔͔ؒΔ͚͔ͩɻ • MicroServicesͷจ຺ʹ͓͍ͯ,
ෳͷDown Stream ServiceΛଋͶΔత ʹڧ͍(API Gateway, Backend-For-Fronend ) • ʮMonolithic ͳServiceΛෳׂ͢Δ࣌ʹFront͕ઌߦͯ͠ಋೖ͢Δʯͷ Α͏ͳಋೖݱ࣮త͔
Thank you!