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
受け取る人から提供する人になるということ
little_rubyist
0
250
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
210
subpath importsで始めるモック生活
10tera
0
330
Djangoの開発環境で工夫したこと - pre-commit / DevContainer
hiroki_yod
1
200
flutterkaigi_2024.pdf
kyoheig3
0
160
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
150
Outline View in SwiftUI
1024jp
1
340
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
260
Remix on Hono on Cloudflare Workers
yusukebe
1
310
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
BBQ
matthewcrist
85
9.3k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Teambox: Starting and Learning
jrom
133
8.8k
It's Worth the Effort
3n
183
27k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
The World Runs on Bad Software
bkeepers
PRO
65
11k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
4 Signs Your Business is Dying
shpigford
180
21k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
17k
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