Fireship · @fireship

Apollo Angular GraphQL Optimistic UI

Uploaded July 3, 2018 · Length 7:27

Apollo Angular GraphQL Optimistic UI

Summary

Implementing optimistic UI updates with Apollo and GraphQL in an Angular app, including setting up mutations and queries.

  • apollo angular
  • graphql optimistic ui
  • angular apollo
  • graphql mutations
  • apollo optimistic updates

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    a few weeks ago we built a graph QL

  2. 0:08

    server with Apollo and nodejs if you

  3. 0:11

    haven't seen that video make sure to

  4. 0:12

    check that one out first to get a better

  5. 0:14

    understanding of graph QL and Apollo

  6. 0:16

    because in today's episode we're going

  7. 0:17

    to be tackling the front end side of

  8. 0:19

    this equation which involves querying

  9. 0:21

    data and providing mutations with

  10. 0:23

    optimistic updates in our angular app if

  11. 0:25

    you're new here make sure to LIKE and

  12. 0:26

    subscribe and send a thank you to Arjun

  13. 0:29

    Yellen and Shelley who was responsible

  14. 0:30

    for writing the code for this lesson to

  15. 0:33

    get started let's first talk about why

  16. 0:34

    Apollo and graph QL are awesome

  17. 0:36

    technologies from the front-end

  18. 0:38

    developer perspective

  19. 0:39

    notice how when I click this heart

  20. 0:41

    button that the count increases and then

  21. 0:43

    a second later our server responds with

  22. 0:45

    an error and then it revert back to the

  23. 0:47

    old value that's known as an optimistic

  24. 0:49

    update or latency compensation and if

  25. 0:52

    you use firebase you're probably already

  26. 0:53

    familiar with this because that's one of

  27. 0:55

    the things that the SDK does for you

  28. 0:57

    automatically but if you're not using

  29. 0:58

    the firebase SDK this is a feature that

  30. 1:00

    would be really difficult to implement

  31. 1:02

    from scratch

  32. 1:03

    Apollo angular makes it easy to

  33. 1:04

    implement features like this plus we can

  34. 1:06

    use it with any back-end data source

  35. 1:08

    that we've set up in our graph QL server

  36. 1:10

    if we open this project in be s code

  37. 1:12

    you'll notice that we have a back-end

  38. 1:13

    and front-end folder the backend is the

  39. 1:16

    graph QL server that we built in the

  40. 1:17

    first episode we'll go in there and make

  41. 1:19

    some updates but for the most part will

  42. 1:21

    be in the front end which is an angular

  43. 1:22

    6 app in our friend and app we're going

  44. 1:25

    to install Apollo angular boost which is

  45. 1:27

    a client library that makes it easy to

  46. 1:29

    set up graph QL on an angular app and

  47. 1:31

    also a library called Apollo code gen

  48. 1:33

    which will allow us to generate

  49. 1:35

    typescript definitions from our server

  50. 1:37

    side automatically which is another

  51. 1:39

    really awesome feature that we'll see

  52. 1:40

    here in a few minutes and lastly we'll

  53. 1:43

    use the angular CLI to generate an NG

  54. 1:45

    module for our graph QL feature then we

  55. 1:48

    can go ahead and open up that module and

  56. 1:50

    we'll want to import the apollo boost

  57. 1:52

    library and add it to the imports array

  58. 1:54

    in the ng module then we'll add a palo

  59. 1:57

    boost to the constructor of this module

  60. 1:59

    and call apollo boost create and then