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.
|
|
|
|
"""
|
2024-08-08 00:35:48 +12:00
|
|
|
def query_for_subscription(
|
|
|
|
query,
|
|
|
|
domain,
|
|
|
|
%{context: context} = resolution,
|
|
|
|
type_override \\ nil,
|
|
|
|
nested \\ []
|
|
|
|
) do
|
2023-06-10 02:19:31 +12:00
|
|
|
query
|
2024-04-02 07:03:06 +13:00
|
|
|
|> Ash.Query.new()
|
2023-06-10 02:19:31 +12:00
|
|
|
|> Ash.Query.set_tenant(Map.get(context, :tenant))
|
|
|
|
|> Ash.Query.set_context(get_context(context))
|
2024-08-08 00:35:48 +12:00
|
|
|
|> AshGraphql.Graphql.Resolver.select_fields(
|
|
|
|
query.resource,
|
|
|
|
resolution,
|
|
|
|
type_override,
|
|
|
|
nested
|
|
|
|
)
|
2023-06-10 04:01:21 +12:00
|
|
|
|> AshGraphql.Graphql.Resolver.load_fields(
|
|
|
|
[
|
2024-04-02 07:03:06 +13:00
|
|
|
domain: domain,
|
2023-06-10 04:01:21 +12:00
|
|
|
tenant: Map.get(context, :tenant),
|
2024-04-02 07:03:06 +13:00
|
|
|
authorize?: AshGraphql.Domain.Info.authorize?(domain),
|
2023-06-10 04:01:21 +12:00
|
|
|
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
|