2023-06-10 02:19:31 +12:00
|
|
|
defmodule AshGraphql.Subscription do
|
|
|
|
@moduledoc """
|
|
|
|
Helpers for working with absinthe subscriptions
|
|
|
|
"""
|
|
|
|
|
|
|
|
import AshGraphql.ContextHelpers
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Produce a query that will load the correct data for a subscription.
|
|
|
|
"""
|
2023-06-10 04:01:21 +12:00
|
|
|
def query_for_subscription(query, api, %{context: context} = resolution) do
|
|
|
|
query = Ash.Query.to_query(query)
|
|
|
|
|
2023-06-10 02:19:31 +12:00
|
|
|
query
|
|
|
|
|> Ash.Query.set_tenant(Map.get(context, :tenant))
|
|
|
|
|> Ash.Query.set_context(get_context(context))
|
2024-01-25 08:59:12 +13:00
|
|
|
|> AshGraphql.Graphql.Resolver.select_fields(query.resource, resolution, nil)
|
2023-06-10 04:01:21 +12:00
|
|
|
|> AshGraphql.Graphql.Resolver.load_fields(
|
|
|
|
[
|
|
|
|
api: api,
|
|
|
|
tenant: Map.get(context, :tenant),
|
|
|
|
authorize?: AshGraphql.Api.Info.authorize?(api),
|
|
|
|
actor: Map.get(context, :actor)
|
|
|
|
],
|
|
|
|
query.resource,
|
|
|
|
resolution,
|
2023-10-27 17:29:03 +13:00
|
|
|
resolution.path,
|
|
|
|
context
|
2023-06-10 04:01:21 +12:00
|
|
|
)
|
2023-06-10 02:19:31 +12:00
|
|
|
end
|
|
|
|
end
|