Skip to content

Commit

Permalink
make subscriptions opt_in
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ committed Sep 25, 2024
1 parent 3176987 commit 9dd9c58
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ config :logger, level: :warning
config :ash, :pub_sub, debug?: true
config :logger, level: :info

config :ash_graphql, :subscriptions, true

if Mix.env() == :dev do
config :git_ops,
mix_project: AshGraphql.MixProject,
Expand Down
3 changes: 2 additions & 1 deletion lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ defmodule AshGraphql.Resource do
@verifiers [
AshGraphql.Resource.Verifiers.VerifyQueryMetadata,
AshGraphql.Resource.Verifiers.RequirePkeyDelimiter,
AshGraphql.Resource.Verifiers.VerifyPaginateRelationshipWith
AshGraphql.Resource.Verifiers.VerifyPaginateRelationshipWith,
AshGraphql.Resource.Verifiers.VerifySubscriptionOptIn
]

@sections [@graphql]
Expand Down
23 changes: 23 additions & 0 deletions lib/resource/verifiers/verify_subscription_opt_in.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule AshGraphql.Resource.Verifiers.VerifySubscriptionOptIn do
# Checks if the users has opted into using subscriptions
@moduledoc false

use Spark.Dsl.Verifier
alias Spark.Dsl.Transformer

def verify(dsl) do
has_subscriptions =
not (dsl
|> AshGraphql.Resource.Info.subscriptions()
|> Enum.empty?())

if has_subscriptions && not Application.get_env(:ash_graphql, :subscriptions, false) do
raise Spark.Error.DslError,
module: Transformer.get_persisted(dsl, :module),
message: "Subscriptions are in beta and must be enabled in the config",
path: [:graphql, :subscriptions]
end

:ok
end
end

0 comments on commit 9dd9c58

Please sign in to comment.