mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 21:32:59 +12:00
365b3aedc6
* feat: add support for relay global IDs * improvement: use the GraphQL type when projecting fields This allows picking also up fields coming from fragments in queries returning an interface * feat: add relay node query Allow retrieving a resource implementing the Node interface given its Relay global id.
31 lines
865 B
Elixir
31 lines
865 B
Elixir
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.
|
|
"""
|
|
def query_for_subscription(query, api, %{context: context} = resolution) do
|
|
query = Ash.Query.to_query(query)
|
|
|
|
query
|
|
|> Ash.Query.set_tenant(Map.get(context, :tenant))
|
|
|> Ash.Query.set_context(get_context(context))
|
|
|> AshGraphql.Graphql.Resolver.select_fields(query.resource, resolution, nil)
|
|
|> 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,
|
|
resolution.path,
|
|
context
|
|
)
|
|
end
|
|
end
|