Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
GraphQL subscriptions
Search
fr0gM4ch1n3
July 10, 2018
Education
85
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GraphQL subscriptions
fr0gM4ch1n3
July 10, 2018
More Decks by fr0gM4ch1n3
See All by fr0gM4ch1n3
Colors
fr0gm4ch1n3
1
42
Water Drop Refraction macro photography
fr0gm4ch1n3
0
34
GraphQL integration with Redux
fr0gm4ch1n3
0
76
GraphQL basics with the Apollo Client
fr0gm4ch1n3
0
61
Redux with GraphQL integration
fr0gm4ch1n3
0
62
Other Decks in Education
See All in Education
[2026後期火5] 論理学(京都大学文学部 後期 第1回)「名前はあるのに、誰なのかわからない」
yatabe
0
150
El Clima de España. Tema 2 (PPT)
juanmartin2026
0
19k
AIの力を100%引き出すために
frievea
0
610
Sekolah Sabat - Triwulan 4 2026 - Pelajaran 3
hiola
0
6.7k
Dronegeografía innovación didáctica y fotogrametría 3D para la enseñanza de la geografía local y la ciudadaniía activa
juanmartin2026
0
39k
響け!ユーフォニアムと考える「決め方」/Thinking About Decision-Making with Sound! Euphonium
3l4l5
1
200
Book-keeping
bvr7352
0
130
Introduction - Lecture 1 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
3.5k
CSS3 and Responsive Web Design - Lecture 5 - Web Technologies (1019888BNR)
signer
PRO
1
3.5k
中小規模私大の教学IRを支えるデータマネジメント ― データ基盤構築の取り組みと実務の現在地 ―
terazawa
0
230
2026年度秋学期 統計学 第3回 クロス集計と感度・特異度,データの可視化 (2026. 10. 13)
akiraasano
PRO
0
260
DRONEGEOGRAFÍA: INNOVACIÓN DIDÁCTICA Y FOTOGRAMETRÍA 3D PARA LA COHESIÓN TERRITORIAL Y LA CIUDADANÍA ACTIVA
juanmartin2026
0
39k
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7k
Building the Perfect Custom Keyboard
takai
2
910
Why Our Code Smells
bkeepers
PRO
340
58k
How to Talk to Developers About Accessibility
jct
2
580
Statistics for Hackers
jakevdp
799
230k
Crafting Experiences
bethany
1
380
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
570
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
The Language of Interfaces
destraynor
162
27k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.2k
Building an army of robots
kneath
307
47k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Transcript
GraphQL subscriptions
Preview There are some public APIs to play with: •
SWAPI - The Star Wars API • Deutsche Bahn • And more …
Good and bad part Round Trips
DataLoader Batching is not an advanced feature, it's DataLoader's primary
feature DataLoader provides a memoization cache for all loads userLoader.load(1) .then(user => userLoader.load(user.invitedByID)) .then(invitedBy => console.log(`User 1 was invited by ${invitedBy}`)); Example
DataLoader helper const applyOrder = (idField: string, order: any[], input:
any[], emptyElement: ObjectConstructor = Object) => { const _input: any[] = [], result = []; for (let index0 = 0, len1 = order.length; index0 < len1; index0++) { _input.push(Object.assign({}, order[index0])); } loop: for (let index1 = 0, len1 = order.length; index1 < len1; index1++) { for (let index2 = 0, len2 = _input.length; index2 < len2; index2++) { if (order[index1] === _input[index2][idField]) { result.push(_input[index2]); index2 = len2; continue loop; } } result.push(new emptyElement()); } return result; };
Overview GraphQL subscriptions have to be defined in the schema,
just like queries and mutations: type Subscription { commentAdded(repoFullName: String!): Comment }
Overview On the client, subscription queries look just like any
other kind of operation: subscription onCommentAdded($repoFullName: String!){ commentAdded(repoFullName: $repoFullName){ id content } }
Overview The response sent to the client looks as follows:
{ "data": { "commentAdded": { "id": "123", "content": "Hello!" } } }
Server setup server.use('/graphql', bodyParser.json(), graphqlExpress({ schema })); server.use('/graphiql', graphiqlExpress({ endpointURL:
'/graphql', subscriptionsEndpoint: `ws://localhost:${PORT}/subscriptions` })); const ws = createServer(server); ws.listen(PORT, () => { new SubscriptionServer({ execute, subscribe, schema }, { server: ws, path: '/subscriptions', }); });
Client setup Add support for this transport to Apollo Client
import { WebSocketLink } from "apollo-link-ws"; import { SubscriptionClient } from "subscriptions-transport-ws"; const GRAPHQL_ENDPOINT = "ws://localhost:3000/graphql"; const client = new SubscriptionClient(GRAPHQL_ENDPOINT, { reconnect: true }); const link = new WebSocketLink(client);
Subscription Component Subscriptions are just listeners, they don’t request any
data! Still need an initial query: const COMMENT_QUERY = gql` query Comment($repoName: String!) { entry(repoFullName: $repoName) { comments { id content } } } `; this.commentsQuery = apollo.watchQuery({ query: COMMENT_QUERY, variables: { repoName: `${params.org}/${params.repoName}` } }); this.comments = this.commentsQuery.valueChanges;
Subscription Component same component ... const COMMENTS_SUBSCRIPTION = gql` subscription
onCommentAdded( $repoFullName: String!){ commentAdded(repoFullName: $repoFullName){ id content } } `; this.commentsQuery.subscribeToMore({ document: COMMENTS_SUBSCRIPTION, variables: { repoFullName: params.repoFullName, }, updateQuery: (prev, {subscriptionData}) => { if (!subscriptionData.data) { return prev; } return { ...prev, entry: { comments: [ subscriptionData.data.commentAdded, ...prev.entry.comments] } }; } });
Integration with NativeScript You can use Apollo with NativeScript exactly
as you would with normal Angular application.
GraphQL-IO
subZero Software development stack, with the primary focus of building
GraphQL and REST APIs backed by a PostgreSQL database
Example App