Skip to content

Commit

Permalink
add subscription field to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ committed Jan 8, 2024
1 parent c51fc5b commit 4de054e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/api/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ defmodule AshGraphql.Api do
@doc false
def subscriptions(api, resources, action_middleware, schema) do
resources
|> IO.inspect(label: :subscriptions)
|> Enum.filter(fn resource ->
AshGraphql.Resource in Spark.extensions(resource)
end)
Expand Down
8 changes: 4 additions & 4 deletions lib/ash_graphql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ defmodule AshGraphql do
blueprint_with_subscriptions =
api
|> AshGraphql.Api.subscriptions(unquote(resources), action_middleware, __MODULE__)
|> Enum.reduce(blueprint_with_queries, fn subscription, blueprint ->
Absinthe.Blueprint.add_field(blueprint, "RootSubscriptionType", mutation)
|> Enum.reduce(blueprint_with_mutations, fn subscription, blueprint ->
Absinthe.Blueprint.add_field(blueprint, "RootSubscriptionType", subscription)
end)

type_definitions =
Expand Down Expand Up @@ -197,14 +197,14 @@ defmodule AshGraphql do
end

new_defs =
List.update_at(blueprint_with_mutations.schema_definitions, 0, fn schema_def ->
List.update_at(blueprint_with_subscriptions.schema_definitions, 0, fn schema_def ->
%{
schema_def
| type_definitions: schema_def.type_definitions ++ type_definitions
}
end)

{:ok, %{blueprint_with_mutations | schema_definitions: new_defs}}
{:ok, %{blueprint_with_subscriptions | schema_definitions: new_defs}}
end
end

Expand Down
10 changes: 8 additions & 2 deletions lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,15 @@ defmodule AshGraphql.Resource do
def subscriptions(api, resource, action_middleware, schema) do
resource
|> subscriptions()
|> Enum.map(fn %Subscription{name: name, config: config} ->
%Absinthe.Blueprint.Schema.FieldDefinition{
identifier: name,
name: to_string(name),
type: AshGraphql.Resource.Info.type(resource),
__reference__: ref(__ENV__)
}
end)
|> dbg()

[]
end

@doc false
Expand Down

0 comments on commit 4de054e

Please sign in to comment.