Slide 1

Slide 1 text

Real-Time API’s with GraphQL Sandeep Singh initialspark.co.uk @initial_spark

Slide 2

Slide 2 text

◦ What is GraphQL ? ◦ Why it exists and the problems it aims to solve ? ◦ GraphQL core concepts ◦ Real-Time API’s – the what, why and how Agenda @initial_spark

Slide 3

Slide 3 text

GraphQL is a declarative query language for your API @initial_spark

Slide 4

Slide 4 text

@initial_spark

Slide 5

Slide 5 text

○Built on specification ○Hierarchical ○Client‐driven ○Strongly typed What is GraphQL? @initial_spark

Slide 6

Slide 6 text

Q: Why GraphQL? @initial_spark

Slide 7

Slide 7 text

○Efficiency ○Predictability ○Versioning ○Caching ○Security, tooling, documentation and more Modern API considerations @initial_spark

Slide 8

Slide 8 text

Let’s look at an example… @initial_spark

Slide 9

Slide 9 text

@initial_spark

Slide 10

Slide 10 text

Efficiency @initial_spark

Slide 11

Slide 11 text

Efficiency @initial_spark GraphQL API Mongo DB AWS Lamba REST API SOAP Service HTTP TCP/IP HTTP SOAP Optimisted data for each channel

Slide 12

Slide 12 text

Versioning Evolution @initial_spark

Slide 13

Slide 13 text

Tooling & DX @initial_spark

Slide 14

Slide 14 text

Introspection { __schema{ types{ name } } } • Query schema, types and fields • Build tools o Auto complete / Validate (graphiql) o Code generation o Documentation @initial_spark

Slide 15

Slide 15 text

GraphQL Core Concepts @initial_spark

Slide 16

Slide 16 text

Schema Type System Query Language GraphQL Core Concepts @initial_spark

Slide 17

Slide 17 text

GraphQL Core Concepts - Resolvers @initial_spark

Slide 18

Slide 18 text

Schema Type System Query Language o Operations • Queries – read • Mutations – write • Subscriptions – real-time o Alias o Fragments GraphQL Core Concepts @initial_spark

Slide 19

Slide 19 text

Lets build a GraphQL API! @initial_spark

Slide 20

Slide 20 text

@initial_spark

Slide 21

Slide 21 text

◦ Unpredictable Execution ◦ Handling File Upload ◦ Cache at Network Level ◦ Authentication/Authorisation GraphQL - Challenges @initial_spark

Slide 22

Slide 22 text

Q:What about Real-time data? @initial_spark

Slide 23

Slide 23 text

@initial_spark Chat Notifications Live feed Collaborative

Slide 24

Slide 24 text

◦ Pull ◦ Polling - Short/Long - HTTP ◦ Push ◦ Subscriptions - Event driven ◦ Live queries - Infinitely fast/cheap polling (State driven) Real-Time API’s @initial_spark

Slide 25

Slide 25 text

◦ Real time events ◦ Idea: Server pushes data to client when something ‘interesting’ occurs ◦ The client defines the shape of the data pushed to it Subscriptions – Event Based @initial_spark

Slide 26

Slide 26 text

◦ The initial state is large, but the incremental change sets are small ◦ You care about low-latency updates in the case of specific events, e.g. chat application where users expect to receive new messages in a matter of seconds Subscriptions – When to use @initial_spark

Slide 27

Slide 27 text

Subscriptions Implementation @initial_spark

Slide 28

Slide 28 text

Subscriptions (Redis, Kafka, MQ, own?) @initial_spark Request / Response Bi-Directional Transport (SSE, websockets etc) HTTP Subscription(s) GraphQL Domain Events Events

Slide 29

Slide 29 text

@initial_spark

Slide 30

Slide 30 text

Let’s look at another example… @initial_spark

Slide 31

Slide 31 text

@initial_spark GraphQL API Run Mutation Trigger Subscription subscription {patientDischarged{…}} PAS View (Admin) Ward View (Nurse)

Slide 32

Slide 32 text

Lets have some fun with subscriptions @initial_spark

Slide 33

Slide 33 text

Advanced features – Enrich payload @initial_spark

Slide 34

Slide 34 text

@initial_spark There isn’t such thing as a free lunch…

Slide 35

Slide 35 text

◦ Scaling state is hard ◦ Who’s subscribed/ how do we send messages etc ◦ QOS ◦ Throttling ◦ Buffering Subscriptions - Challenges @initial_spark

Slide 36

Slide 36 text

○ http://graphql.org/learn/ ○ https://www.youtube.com/watch?v=bn8qsi8jVew - Lee Byron ○ https://github.com/apollographql/apollo-client ○ https://github.com/initialspark/real-time-apis-graphql ○ https://www.graphqlhub.com/ ○ https://www.youtube.com/watch?v=4_Bcw7BULC8 - Authentication Resources @initial_spark

Slide 37

Slide 37 text

Thank you ! You can find me at @initial_spark & initialspark.co.uk