Skip to content

Commit

Permalink
move resolve logic in existing resolver module
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ committed Mar 8, 2024
1 parent ffd851e commit d7f1a1e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
23 changes: 23 additions & 0 deletions lib/graphql/resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,29 @@ defmodule AshGraphql.Graphql.Resolver do
end
end

def resolve(
%{arguments: arguments, context: context} = resolution,
{api, resource, %AshGraphql.Resource.Subscription{}, _input?}
) do
dbg()

result =
AshGraphql.Subscription.query_for_subscription(
resource,
api,
resolution
)
# > Ash.Query.filter(id == ^args.id)
|> Ash.Query.limit(1)
|> api.read_one(actor: resolution.context[:current_user])
|> dbg()

resolution
|> Absinthe.Resolution.put_result(result)

resolution
end

defp read_one_query(resource, args) do
case Map.fetch(args, :filter) do
{:ok, filter} when filter != %{} ->
Expand Down
32 changes: 29 additions & 3 deletions lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,9 @@ defmodule AshGraphql.Resource do
raise "No such action #{query.action} on #{resource}"

%Absinthe.Blueprint.Schema.FieldDefinition{
arguments: args(query.type, resource, query_action, schema, query.identity),
arguments:
args(query.type, resource, query_action, schema, query.identity)
|> IO.inspect(label: "args"),
identifier: query.name,
middleware:
action_middleware ++
Expand Down Expand Up @@ -1010,6 +1012,9 @@ defmodule AshGraphql.Resource do
dbg(config)

%Absinthe.Blueprint.Schema.FieldDefinition{
arguments:
args(:subscription, resource, nil, schema, nil)
|> IO.inspect(label: "args"),
identifier: name,
name: to_string(name),
config:
Expand All @@ -1022,8 +1027,7 @@ defmodule AshGraphql.Resource do
middleware:
action_middleware ++
[
{{AshGraphql.Resource.Subscription.DefaultResolve, :resolve},
{api, resource, subscription, true}}
{{AshGraphql.Graphql.Resolver, :resolve}, {api, resource, subscription, true}}
],
type: AshGraphql.Resource.Info.type(resource),
__reference__: ref(__ENV__)
Expand Down Expand Up @@ -1532,6 +1536,28 @@ defmodule AshGraphql.Resource do
read_args(resource, action, schema)
end

defp args(:subscription, resource, _action, schema, _identity) do
if AshGraphql.Resource.Info.derive_filter?(resource) do
case resource_filter_fields(resource, schema) do
[] ->
[]

_ ->
[
%Absinthe.Blueprint.Schema.InputValueDefinition{
name: "filter",
identifier: :filter,
type: resource_filter_type(resource),
description: "A filter to limit the results",
__reference__: ref(__ENV__)
}
]
end
else
[]
end
end

defp read_args(resource, action, schema) do
action.arguments
|> Enum.reject(& &1.private?)
Expand Down
3 changes: 0 additions & 3 deletions lib/resource/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ defmodule AshGraphql.Resource.Subscription do
@moduledoc "Represents a configured query on a resource"
defstruct [
:name,
# :arg = filter,
:config,
:read_action
# :topic, fn _, _ -> {:ok, topic} | :error,
# :trigger fn notification -> {:ok, topics}
]

@subscription_schema [
Expand Down
28 changes: 0 additions & 28 deletions lib/resource/subscription/default_resolve.ex

This file was deleted.

0 comments on commit d7f1a1e

Please sign in to comment.