Skip to content

Commit

Permalink
use the configured read action to get the data in the resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ committed Aug 5, 2024
1 parent 9db3a74 commit e79e1eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/graphql/resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,15 @@ defmodule AshGraphql.Graphql.Resolver do

def resolve(
%{arguments: _arguments, context: context, root_value: data} = resolution,
{domain, resource, %AshGraphql.Resource.Subscription{}, _input?}
{domain, resource, %AshGraphql.Resource.Subscription{read_action: read_action}, _input?}
) do
read_action =
read_action || Ash.Resource.Info.primary_action!(resource, :read).name

query =
AshGraphql.Subscription.query_for_subscription(
resource
|> Ash.Query.for_read(:read, %{}, actor: Map.get(context, :actor)),
|> Ash.Query.for_read(read_action, %{}, actor: Map.get(context, :actor)),
domain,
resolution
)
Expand Down
4 changes: 4 additions & 0 deletions lib/resource/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ defmodule AshGraphql.Resource.Subscription do
name: [
type: :atom,
doc: "The name to use for the subscription."
],
read_action: [
type: :atom,
doc: "The read action to use for reading data"
]
]

Expand Down
2 changes: 1 addition & 1 deletion lib/resource/subscription/default_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule AshGraphql.Resource.Subscription.DefaultConfig do
dbg(filter)
{:ok, topic: "*", context_id: dbg(Base.encode64(:erlang.term_to_binary(filter)))}

e ->
_ ->
{:error, "unauthorized"}
end
end
Expand Down

0 comments on commit e79e1eb

Please sign in to comment.