mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 05:13:33 +12:00
add subscription field to schema
This commit is contained in:
parent
52dfa22afd
commit
64737aa505
3 changed files with 18 additions and 4 deletions
|
@ -215,6 +215,13 @@ defmodule AshGraphql do
|
|||
end)
|
||||
end)
|
||||
|
||||
blueprint_with_subscriptions =
|
||||
api
|
||||
|> AshGraphql.Api.subscriptions(unquote(resources), action_middleware, __MODULE__)
|
||||
|> Enum.reduce(blueprint_with_mutations, fn subscription, blueprint ->
|
||||
Absinthe.Blueprint.add_field(blueprint, "RootSubscriptionType", subscription)
|
||||
end)
|
||||
|
||||
managed_relationship_types =
|
||||
AshGraphql.Resource.managed_relationship_definitions(
|
||||
Process.get(:managed_relationship_requirements, []),
|
||||
|
@ -304,7 +311,7 @@ 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:
|
||||
|
@ -313,7 +320,7 @@ defmodule AshGraphql do
|
|||
}
|
||||
end)
|
||||
|
||||
{:ok, %{blueprint_with_mutations | schema_definitions: new_defs}}
|
||||
{:ok, %{blueprint_with_subscriptions | schema_definitions: new_defs}}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -211,6 +211,7 @@ defmodule AshGraphql.Domain do
|
|||
|
||||
def subscriptions(api, resources, action_middleware, schema) do
|
||||
resources
|
||||
|> IO.inspect(label: :subscriptions)
|
||||
|> Enum.filter(fn resource ->
|
||||
AshGraphql.Resource in Spark.extensions(resource)
|
||||
end)
|
||||
|
|
|
@ -1153,9 +1153,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
|
||||
|
|
Loading…
Reference in a new issue