Skip to content

Commit

Permalink
returned my first result from a subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ committed Jan 10, 2024
1 parent 4de054e commit d022389
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 60 deletions.
5 changes: 5 additions & 0 deletions lib/ash_graphql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ defmodule AshGraphql do

@dialyzer {:nowarn_function, {:run, 2}}
def run(blueprint, _opts) do
# IO.inspect(
# blueprint.schema_definitions
# |> Enum.find(&(&1.name == "RootSubscriptionType").fields)
# )

api = unquote(api)
action_middleware = unquote(action_middleware)

Expand Down
10 changes: 9 additions & 1 deletion lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -886,10 +886,18 @@ defmodule AshGraphql.Resource do
def subscriptions(api, resource, action_middleware, schema) do
resource
|> subscriptions()
|> Enum.map(fn %Subscription{name: name, config: config} ->
|> Enum.map(fn %Subscription{name: name, config: config} = subscription ->
%Absinthe.Blueprint.Schema.FieldDefinition{
identifier: name,
name: to_string(name),
config: config,
module: schema,
middleware:
action_middleware ++
[
{{AshGraphql.Resource.Subscription.DefaultResolve, :resolve},
{api, resource, subscription, true}}
],
type: AshGraphql.Resource.Info.type(resource),
__reference__: ref(__ENV__)
}
Expand Down
8 changes: 2 additions & 6 deletions lib/resource/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ defmodule AshGraphql.Resource.Subscription do
doc: "The name to use for the subscription."
],
config: [
type:
{:spark_function_behaviour, AshGraphql.Resource.Subscription.Config,
{AshGraphql.Resource.Subscription.Config.Function, 2}},
type: {:mfa_or_fun, 2},
doc: """
Function that creates the config for the subscription
"""
],
resolve: [
type:
{:spark_function_behaviour, AshGraphql.Resource.Subscription.Resolve,
{AshGraphql.Resource.Subscription.Resolve.Function, 3}},
type: {:mfa_or_fun, 3},
doc: """
Function that creates the config for the subscription
""",
Expand Down
9 changes: 0 additions & 9 deletions lib/resource/subscription/config.ex

This file was deleted.

13 changes: 0 additions & 13 deletions lib/resource/subscription/config_function.ex

This file was deleted.

30 changes: 22 additions & 8 deletions lib/resource/subscription/default_resolve.ex
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
defmodule AshGraphql.Resource.Subscription.DefaultResolve do
require Ash.Query

def resolve(args, _, resolution) do
AshGraphql.Subscription.query_for_subscription(
Post,
Api,
resolution
)
|> Ash.Query.filter(id == ^args.id)
|> Api.read(actor: resolution.context.current_user)
def resolve(%Absinthe.Resolution{state: :resolved} = resolution, _),
do: resolution

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])
|> IO.inspect()

resolution
|> Absinthe.Resolution.put_result(result)
end
end
10 changes: 0 additions & 10 deletions lib/resource/subscription/resolve.ex

This file was deleted.

13 changes: 0 additions & 13 deletions lib/resource/subscription/resolve_function.ex

This file was deleted.

0 comments on commit d022389

Please sign in to comment.