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
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
Jakarta EE meets AI
ivargrimstad
0
240
ドメインイベント増えすぎ問題
h0r15h0
2
290
命名をリントする
chiroruxx
1
400
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
520
39k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Building Adaptive Systems
keathley
38
2.3k
Practical Orchestrator
shlominoach
186
10k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Music & Morning Musume
bryan
46
6.2k
4 Signs Your Business is Dying
shpigford
181
21k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
The Pragmatic Product Professional
lauravandoore
32
6.3k
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