Skip to content

Commit

Permalink
Add preferences updated subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
abshierjoel committed Oct 5, 2021
1 parent 648e49c commit 88a37d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
13 changes: 10 additions & 3 deletions lib/gql_preferences_web/resolvers/preferences.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ defmodule UserPreferencesWeb.Resolvers.Preferences do
def update_preferences_by_id(_, args, _) do
ActivityMonitor.update_resolver_activity("update_preferences_by_id")

Repo.get_by(Preferences, user_id: args.user_id)
|> Preferences.changeset(args)
|> Repo.update()
{:ok, prefs} =
Repo.get_by(Preferences, user_id: args.user_id)
|> Preferences.changeset(args)
|> Repo.update()

Absinthe.Subscription.publish(UserPreferencesWeb.Endpoint, prefs,
updated_user_preferences: "*"
)

{:ok, prefs}
end
end
12 changes: 9 additions & 3 deletions lib/gql_preferences_web/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ defmodule UserPreferencesWeb.Schema do

subscription do
field :created_user, :user do
config(fn args, info ->
IO.inspect(args, label: "ARGS")
IO.inspect(info, label: "INFO")
config(fn _args, _info ->
{:ok, topic: "*"}
end)
end

field :updated_user_preferences, :preferences do
arg(:user_id, non_null(:id))

config(fn _args, _ ->
{:ok, topic: "*"}
end)
end
Expand Down

0 comments on commit 88a37d4

Please sign in to comment.