mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 13:24:14 +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)
|
||||||
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 =
|
managed_relationship_types =
|
||||||
AshGraphql.Resource.managed_relationship_definitions(
|
AshGraphql.Resource.managed_relationship_definitions(
|
||||||
Process.get(:managed_relationship_requirements, []),
|
Process.get(:managed_relationship_requirements, []),
|
||||||
|
@ -304,7 +311,7 @@ defmodule AshGraphql do
|
||||||
end
|
end
|
||||||
|
|
||||||
new_defs =
|
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
|
schema_def
|
||||||
| type_definitions:
|
| type_definitions:
|
||||||
|
@ -313,7 +320,7 @@ defmodule AshGraphql do
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
{:ok, %{blueprint_with_mutations | schema_definitions: new_defs}}
|
{:ok, %{blueprint_with_subscriptions | schema_definitions: new_defs}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -211,6 +211,7 @@ defmodule AshGraphql.Domain do
|
||||||
|
|
||||||
def subscriptions(api, resources, action_middleware, schema) do
|
def subscriptions(api, resources, action_middleware, schema) do
|
||||||
resources
|
resources
|
||||||
|
|> IO.inspect(label: :subscriptions)
|
||||||
|> Enum.filter(fn resource ->
|
|> Enum.filter(fn resource ->
|
||||||
AshGraphql.Resource in Spark.extensions(resource)
|
AshGraphql.Resource in Spark.extensions(resource)
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -1153,9 +1153,15 @@ defmodule AshGraphql.Resource do
|
||||||
def subscriptions(api, resource, action_middleware, schema) do
|
def subscriptions(api, resource, action_middleware, schema) do
|
||||||
resource
|
resource
|
||||||
|> subscriptions()
|
|> 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()
|
|> dbg()
|
||||||
|
|
||||||
[]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
|
|
Loading…
Reference in a new issue