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

20 lines
1,017 B
Markdown
Raw Normal View History

2018-04-08 17:20:16 +12:00
# Subscriptions
2018-04-08 08:48:56 +12:00
2018-04-08 17:20:16 +12:00
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.
2018-04-08 14:34:46 +12:00
2018-04-08 17:20:16 +12:00
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](http://graphql.org/blog/subscriptions-in-graphql-and-relay/) come in.
2018-04-08 14:34:46 +12:00
2018-04-08 17:20:16 +12:00
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`
2018-04-08 15:27:20 +12:00
Next, take a look at `step-6`.