Skip to content

Commit

Permalink
fix: define subscription to handle case where no subscriptions exist
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Nov 30, 2024
1 parent 4ff09c5 commit ad956e6
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/ash_graphql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ defmodule AshGraphql do
end
end

defmacro subscription(do: block) do
empty? = !match?({:__block__, _, []}, block)

quote bind_quoted: [empty?: empty?, block: Macro.escape(block)], location: :keep do
require Absinthe.Schema

if empty? ||
Enum.any?(
@ash_resources,
fn resource ->
!Enum.empty?(AshGraphql.Resource.Info.subscriptions(resource, @all_domains))
end
) do
Code.eval_quoted(
quote do
Absinthe.Schema.subscription do
unquote(block)
end
end,
[],
__ENV__
)
end
end
end

defmacro __using__(opts) do
auto_import_types =
if Keyword.get(opts, :auto_import_absinthe_types?, true) do
Expand All @@ -57,12 +83,14 @@ defmodule AshGraphql do

import Absinthe.Schema,
except: [
mutation: 1
mutation: 1,
subscription: 1
]

import AshGraphql,
only: [
mutation: 1
mutation: 1,
subscription: 1
]

domains =
Expand Down

0 comments on commit ad956e6

Please sign in to comment.