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 Directiveを試してみた
Search
piglovesyou
December 21, 2018
Programming
0
320
GraphQL Directiveを試してみた
GraphQL Directiveに可能性を感じたので、Apollo Serverでカスタムディレクティブを作ってみたのと、その考察です。
piglovesyou
December 21, 2018
Tweet
Share
More Decks by piglovesyou
See All by piglovesyou
Apollo Linkでできること
piglovesyou
1
150
Other Decks in Programming
See All in Programming
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
現場で役立つモデリング 超入門
masuda220
PRO
13
2.9k
レガシーな Android アプリのリアーキテクチャ戦略
oidy
1
170
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
330
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.7k
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
210
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
590
OpenTelemetryでRailsのパフォーマンス分析を始めてみよう(KoR2024)
ymtdzzz
4
1.6k
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
7
2.8k
CSC509 Lecture 09
javiergs
PRO
0
110
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
520
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
270
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1365
200k
Embracing the Ebb and Flow
colly
84
4.4k
Ruby is Unlike a Banana
tanoku
96
11k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
328
21k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Why Our Code Smells
bkeepers
PRO
334
57k
Practical Orchestrator
shlominoach
186
10k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Agile that works and the tools we love
rasmusluckow
327
21k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Transcript
(SBQI2-%JSFDUJWFTΛ ࢼͯ͠Έͨ &*5ߴଜ
(SBQI2-%JSFDUJWFT ͱԿ͔ʁ
࠷ॳ͔Β͋ΔσΟϨΫςΟϒ IUUQTXXXBQPMMPHSBQIRMDPNEPDTBQPMMPTFSWFSGFBUVSFT EJSFDUJWFTIUNM%FGBVMU%JSFDUJWFT
ಠ࣮ࣗྫ IUUQTXXXBQPMMPHSBQIRMDPNEPDTHSBQIRMUPPMTTDIFNB EJSFDUJWFTIUNM&YBNQMFT
Ͳ͏͍͏छྨ͕ ͋Δͷ͔ʁ
εΩʔϚͰ͏ IUUQTHJUIVCDPNHSBQIRMHSBQIRMKTCMPC BFFBEBCEDGDBGFTSDMBOHVBHF EJSFDUJWF-PDBUJPOKT--
ϦΫΤετͰ͏ IUUQTHJUIVCDPNHSBQIRMHSBQIRMKTCMPC BFFBEBCEDGDBGFTSDMBOHVBHF EJSFDUJWF-PDBUJPOKT--
ͬͯΈ͍ͨ☺
͓ w ྻΛฦ͢ෳͷ3&45GVM"1*63-Λ͢ͱɺ ݁ՌΛܨ͛ͯฦͯ͘͠ΕΔ !DPODBU VSMT σΟϨΫςΟϒ
σΟϨΫςΟϒΛએݴ
# .graphql directive @concat(urls: [String]) on FIELD_DEFINITION
σΟϨΫςΟϒΛ࣮
// .js import { SchemaDirectiveVisitor } from 'apollo-server'; class ConcatDirective
extends SchemaDirectiveVisitor { visitFieldDefinition(fieldDefinition) { const { urls } = this.args; fieldDefinition.resolve = (obj, args, context, info) => Promise.all( urls.map( url => fetch(url).then( res => res.json() ) ) ).then( rs => rs.reduce((xs, arr) => [...xs, ...arr], []), ); } } export const schemaDirectives = { concat: ConcatDirective, };
ͦΕΛεΩʔϚͰ͏
# .graphql type Issue { id: String url: String }
type RootQuery { # ... ghissues: [Issue] @concat(urls: [ "https://api.github.com/repos/apollographql/apollo-link/issues", "https://api.github.com/repos/apollographql/apollo-client/issues", "https://api.github.com/repos/apollographql/apollo-server/issues", ]) }
ͦͷΫΤϦΛୟ͘
# .graphql query { ghissues { id url } }
# the graphql response { data: { ghissues: [ {
id: 393044392, url: https://api.github.com/repos/apollographql/apollo-link/issues/897 }, // ... { id: 392713767, url: https://api.github.com/repos/apollographql/apollo-client/issues/4252 }, // ... { id: 386114424, url: https://api.github.com/repos/apollographql/apollo-server/issues/2051 } ] } }
w 3&45GVM"1*͕࠶ར༻ՄೳͳͷʹͳΕͳΔ΄Ͳɺ(SBQI2- 3FTPMWFS࣮୯ௐͳͷʹͳΔɻͦ͜Λղܾ͢Δ w ʮεΩʔϚͰఆٛͨ͠63-ʹର͠ɺϢʔβϦΫΤετ࣌ʹύ ϥϝʔλΛՃʯͳͲͪΖΜՄೳ w '*&-%ΑΓɺ(SBQI2-αʔόଆΛ֦ு͢Δ '*&-%@%&'*/*5*0/ͷํ͕ເ͕͕Δײ͋Δ w
࡞Δ࣌ɺ(SBQI2-γϯλοΫεΤϥʔʹؾ͖͍͢Α͏ૉ ૣ͘ىಈͰ͖Δঢ়ଶΛ࡞͓͚͔ͬͯͳΓָ ʢ34,ͰΫϥΠΞϯτίʔυͷίϯύΠϧΛؚΊىಈͯͨ͠ Β৸ͦ͏ʹͳͬͨʣ
// ./dev-graphql-server.js import { ApolloServer } from 'apollo-server'; global.__DEV__ =
true; const { default: schema } = require('./src/data/schema'); new ApolloServer(schema).listen().then(({ url }) => { console.log(` Server ready at ${url}`); }); (SBQI2-αʔόͷΈΛ5SZ&SSPSͰ͖ΔΑ͏ʹ͓ͯ͘͠
w (SBQI2-ͷޙΖͷ࣮Λແͤ͘Δເ w ϑϩϯτΤϯυΤϯδχΞ͕ɺ(SBQI2-εΩʔϚͱϑϩϯτͷ ίʔυΛॻ͚ͩ͘Ͱׂͱڽͬͨ8FCΞϓϦΛσϓϩΠ͢Δະདྷ w ྫ͑!NZTRM!SFEJTͳͲͱ͍ͬͨσΟϨΫςΟϒΛ࡞Εɺ ετϨʔδଓ෦ͷ࣮ͳ͠Ͱσʔλऔಘɾॻ͖͑Ͱ͖ͦ͏ɻ !BVUI༷ΛݻΊΒΕΕ͔ͳΓεέʔϧͦ͠͏ w
ΧελϜσΟϨΫςΟϒҰࣜΛͯ͠Δ IUUQTXXXOQNKTDPNQBDLBHFHSBQIRMDVTUPNEJSFDUJWFT !EBUF BTz:::: ͱ͔·Εڧͦ͏ʣ w (SBQI2-εΩʔϚͰ%#εΩʔϚࡁ·ͤΔ IUUQTXXXOQNKTDPNQBDLBHFHSBQIRMEJSFDUJWFTRM