Source for a talk I gave about GraphQL and Elixir/Phoenix.
.vscode | ||
assets | ||
config | ||
lib | ||
priv | ||
test | ||
.gitignore | ||
mix.exs | ||
mix.lock | ||
README.md |
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
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
.