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
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
最新TCAキャッチアップ
0si43
0
140
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
900
Quine, Polyglot, 良いコード
qnighy
4
640
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
RubyLSPのマルチバイト文字対応
notfounds
0
120
cmp.Or に感動した
otakakot
2
150
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5k
Building Your Own Lightsaber
phodgson
103
6.1k
We Have a Design System, Now What?
morganepeng
50
7.2k
The Language of Interfaces
destraynor
154
24k
Faster Mobile Websites
deanohume
305
30k
How GitHub (no longer) Works
holman
310
140k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Rails Girls Zürich Keynote
gr2m
94
13k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Being A Developer After 40
akosma
86
590k
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