From e79e1eb0f2d26ae586536778a16b09d38938c3c6 Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Mon, 5 Aug 2024 16:34:32 +0200 Subject: [PATCH] use the configured read action to get the data in the resolver --- lib/graphql/resolver.ex | 7 +++++-- lib/resource/subscription.ex | 4 ++++ lib/resource/subscription/default_config.ex | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/graphql/resolver.ex b/lib/graphql/resolver.ex index f28f6c8a..c4278041 100644 --- a/lib/graphql/resolver.ex +++ b/lib/graphql/resolver.ex @@ -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 ) diff --git a/lib/resource/subscription.ex b/lib/resource/subscription.ex index f87f18c6..b8b25acf 100644 --- a/lib/resource/subscription.ex +++ b/lib/resource/subscription.ex @@ -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" ] ] diff --git a/lib/resource/subscription/default_config.ex b/lib/resource/subscription/default_config.ex index cc7f70b0..733d44df 100644 --- a/lib/resource/subscription/default_config.ex +++ b/lib/resource/subscription/default_config.ex @@ -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