This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
graphql-lightning-talk/README.md
2018-04-08 17:20:16 +12:00

1,017 B

Subscriptions

Our little React app is pretty neat. When it loads it queries the server for a list of people and shows their faces and allows us to run a mutation to add a new person to our list.

There's only one problem. What happens if someone else comes along and adds a face to our gallery? Our client won't know that the data has changed and will just keep showing us stale data. This is where GraphQL Subscriptions come in.

Absinthe has built-in support for subscriptions and since we're using Phoenix we have a well-tested channel implementation to run it over (Absinthe can use it's own socket protocol too, if you're not running in Phoenix).

Notable changes:

  • lib/faces_web/endpoint.ex
  • lib/faces_web/schema/schema.ex
  • lib/faces_web/channels/user_socket.ex
  • assets/js/absinthe-socket-link.js
  • assets/js/client.js
  • assets/js/queries/person_added.js
  • assets/js/queries/list_people.js

Next, take a look at step-6.