Source for a talk I gave about GraphQL and Elixir/Phoenix.
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.
Find a file
2018-04-08 16:18:48 +12:00
.vscode Client-side subscriptions via Apollo work. 2018-04-08 15:26:22 +12:00
assets Client-side subscriptions via Apollo work. 2018-04-08 15:26:22 +12:00
config Fix timestamps to always create as :utc_datetime. 2018-04-08 12:25:31 +12:00
lib Add postgres database triggers and use them to notify subscribers. 2018-04-08 16:18:48 +12:00
priv Add postgres database triggers and use them to notify subscribers. 2018-04-08 16:18:48 +12:00
test Add face importing from github. 2018-04-08 10:06:11 +12:00
.gitignore Empty Phoenix application. 2018-04-08 09:20:53 +12:00
mix.exs Add absinthe-socket-link and send all GraphQL via a Phoenix channel. 2018-04-08 15:00:11 +12:00
mix.lock Add absinthe-socket-link and send all GraphQL via a Phoenix channel. 2018-04-08 15:00:11 +12:00
README.md Add postgres database triggers and use them to notify subscribers. 2018-04-08 16:18:48 +12:00

More extra for experts

Our existing subscription only triggers if someone else uses the importPerson mutation to trigger the subscription event - what if we want to let clients know whenever a row is added to our people table? Maybe it's added by another service, or something.

In this branch we're using Postgres triggers and stored procedures to send notifications whenever a row is added to the people table and we're using Postgrex.Notifications to subscribe to them. A substantian portion of the code for this example comes from this hackernoon post.

Things to look at:

  • priv/repo/migrations/20180408032823_broadcast_people_table_changes.exs
  • lib/faces/gallery/event_listener.ex

Demo

Let's try manually inserting a row (via psql faces_dev):

INSERT INTO "people" ("username", "name", "location", "avatar_url", "inserted_at", "updated_at")
VALUES ('pupper', 'pupper', 'the bath', 'https://media.giphy.com/media/3o6Zt9ved5rCuidNlK/giphy.gif', NOW(), NOW());

Next, move on to step-7.