Skip to content

Commit

Permalink
do some renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ committed Aug 7, 2024
1 parent 47ed2c9 commit 7c5d504
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/graphql/resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ defmodule AshGraphql.Graphql.Resolver do
Ash.Query.filter(query, ^ref(key) == ^value)
end)

case query |> domain.read_one() do
dbg()

case query |> Ash.read_one() do
# should only happen if a resource is created/updated and the subscribed user is not allowed to see it
{:ok, nil} ->
resolution
Expand Down
2 changes: 1 addition & 1 deletion lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ defmodule AshGraphql.Resource do
identifier: name,
name: to_string(name),
config:
AshGraphql.Resource.Subscription.DefaultConfig.create_config(
AshGraphql.Subscription.Config.create_config(
subscription,
api,
resource
Expand Down
9 changes: 8 additions & 1 deletion lib/resource/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ defmodule AshGraphql.Resource.Subscription do
defstruct [
:name,
:actions,
:read_action
:read_action,
:actor
]

@subscription_schema [
name: [
type: :atom,
doc: "The name to use for the subscription."
],
actor: [
type:
{:spark_function_behaviour, AshGraphql.Resource.Subscription.Actor,
{AshGraphql.Resource.Subscription.Actor, 1}},
doc: "The actor to use for authorization."
],
actions: [
type: {:or, [{:list, :atom}, :atom]},
doc: "The create/update/destroy actions the subsciption should listen to. Defaults to all."
Expand Down
3 changes: 3 additions & 0 deletions lib/resource/subscription/actor.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule AshGraphql.Resource.Subscription.Actor do
@callback author(actor :: any) :: actor :: any
end
2 changes: 1 addition & 1 deletion lib/resource/transformers/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule AshGraphql.Resource.Transformers.Subscription do
|> Transformer.persist(
:simple_notifiers,
[
AshGraphql.Resource.Subscription.Notifier
AshGraphql.Subscription.Notifier
] ++
Transformer.get_persisted(dsl, :simple_notifiers, [])
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule AshGraphql.Resource.Subscription.DefaultConfig do
defmodule AshGraphql.Subscription.Config do
alias AshGraphql.Resource.Subscription

def create_config(%Subscription{} = subscription, _domain, resource) do
Expand Down Expand Up @@ -26,8 +26,10 @@ defmodule AshGraphql.Resource.Subscription.DefaultConfig do
# context_id is exposed to the client so we might need to encrypt it
# or save it in ets or something and send generate a hash or something
# as the context_id
dbg(filter)
{:ok, topic: "*", context_id: dbg(Base.encode64(:erlang.term_to_binary(filter)))}
dbg(filter, structs: false)

{:ok,
topic: "*", context_id: dbg(Base.encode64(:erlang.term_to_binary(filter.filter)))}

_ ->
{:error, "unauthorized"}
Expand Down
6 changes: 4 additions & 2 deletions lib/endpoint.ex → lib/subscription/endpoint.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule AshGraphql.Endpoint do
defmodule AshGraphql.Subscription.Endpoint do
defmacro __using__(_opts) do
quote do
use Absinthe.Phoenix.Endpoint
Expand All @@ -8,10 +8,12 @@ defmodule AshGraphql.Endpoint do
require Logger

def run_docset(pubsub, docs_and_topics, mutation_result) do
dbg(mutation_result, structs: false)

for {topic, key_strategy, doc} <- docs_and_topics do
try do
pipeline =
Absinthe.Subscription.Local.pipeline(doc, mutation_result)
Absinthe.Subscription.Local.pipeline(doc, mutation_result.data)
# why though?
|> List.flatten()
|> Absinthe.Pipeline.insert_before(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
defmodule AshGraphql.Resource.Subscription.Notifier do
defmodule AshGraphql.Subscription.Notifier do
alias AshGraphql.Resource.Info
use Ash.Notifier

@impl Ash.Notifier
def notify(notification) do
pub_sub = Info.subscription_pubsub(notification.resource)

dbg(notification, structs: false)

for subscription <- AshGraphql.Resource.Info.subscriptions(notification.resource) do
if is_nil(subscription.actions) or
notification.action.name in List.wrap(subscription.actions) do
Absinthe.Subscription.publish(pub_sub, notification.data, [{subscription.name, "*"}])
Absinthe.Subscription.publish(pub_sub, notification, [{subscription.name, "*"}])
end
end
end
Expand Down

0 comments on commit 7c5d504

Please sign in to comment.