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
Progressive Web Apps für Desktop und Mobile mit Angular (Hands-on)
christianliebel
PRO
0
110
[PyCon Korea 2024 Keynote] 커뮤니티와 파이썬, 그리고 우리
beomi
0
110
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
170
Kotlin2でdataクラスの copyメソッドを禁止する/Data class copy function to have the same visibility as constructor
eichisanden
1
140
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
440
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
520
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
590
Realtime API 入門
riofujimon
0
110
VR HMDとしてのVision Pro+ゲーム開発について
yasei_no_otoko
0
100
C#/.NETのこれまでのふりかえり
tomokusaba
1
160
Server Driven Compose With Firebase
skydoves
0
400
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
130
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Visualization
eitanlees
144
15k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
41
2.1k
Agile that works and the tools we love
rasmusluckow
327
21k
Thoughts on Productivity
jonyablonski
67
4.3k
For a Future-Friendly Web
brad_frost
175
9.4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
107
49k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
22k
Six Lessons from altMBA
skipperchong
26
3.5k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
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