Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Real-time API's with GraphQL

4e5fd4655e0c94ae66cebb466bf8e788?s=47 Sandeep Singh
October 14, 2018

Real-time API's with GraphQL

4e5fd4655e0c94ae66cebb466bf8e788?s=128

Sandeep Singh

October 14, 2018
Tweet

Transcript

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

  2. ◦ 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
  3. GraphQL is a declarative query language for your API @initial_spark

  4. @initial_spark

  5. ◦Built on specification ◦Hierarchical ◦Client‐driven ◦Strongly typed What is GraphQL?

    @initial_spark
  6. Q: Why GraphQL? @initial_spark

  7. ◦Efficiency ◦Predictability ◦Versioning ◦Caching ◦Security, tooling, documentation and more Modern

    API considerations @initial_spark
  8. Let’s look at an example… @initial_spark

  9. @initial_spark

  10. Efficiency @initial_spark

  11. Efficiency @initial_spark GraphQL API Mongo DB AWS Lamba REST API

    SOAP Service HTTP TCP/IP HTTP SOAP Optimisted data for each channel
  12. Versioning Evolution @initial_spark

  13. Tooling & DX @initial_spark

  14. Introspection { __schema{ types{ name } } } • Query

    schema, types and fields • Build tools o Auto complete / Validate (graphiql) o Code generation o Documentation @initial_spark
  15. GraphQL Core Concepts @initial_spark

  16. Schema Type System Query Language GraphQL Core Concepts @initial_spark

  17. GraphQL Core Concepts - Resolvers @initial_spark

  18. Schema Type System Query Language o Operations • Queries –

    read • Mutations – write • Subscriptions – real-time o Alias o Fragments GraphQL Core Concepts @initial_spark
  19. Lets build a GraphQL API! @initial_spark

  20. @initial_spark

  21. ◦ Unpredictable Execution ◦ Handling File Upload ◦ Cache at

    Network Level ◦ Authentication/Authorisation GraphQL - Challenges @initial_spark
  22. Q:What about Real-time data? @initial_spark

  23. @initial_spark Chat Notifications Live feed Collaborative

  24. ◦ Pull ◦ Polling - Short/Long - HTTP ◦ Push

    ◦ Subscriptions - Event driven ◦ Live queries - Infinitely fast/cheap polling (State driven) Real-Time API’s @initial_spark
  25. ◦ 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
  26. ◦ 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
  27. Subscriptions Implementation @initial_spark

  28. Subscriptions (Redis, Kafka, MQ, own?) @initial_spark Request / Response Bi-Directional

    Transport (SSE, websockets etc) HTTP Subscription(s) GraphQL Domain Events Events
  29. @initial_spark

  30. Let’s look at another example… @initial_spark

  31. @initial_spark GraphQL API Run Mutation Trigger Subscription subscription {patientDischarged{…}} PAS

    View (Admin) Ward View (Nurse)
  32. Lets have some fun with subscriptions @initial_spark

  33. Advanced features – Enrich payload @initial_spark

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

  35. ◦ Scaling state is hard ◦ Who’s subscribed/ how do

    we send messages etc ◦ QOS ◦ Throttling ◦ Buffering Subscriptions - Challenges @initial_spark
  36. ◦ 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
  37. Thank you ! You can find me at @initial_spark &

    initialspark.co.uk