-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
84 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
defmodule AshGraphql.Subscription.Runner do | ||
Check warning on line 1 in lib/subscription/runner.ex GitHub Actions / ash-ci / mix credo --strict
|
||
alias Absinthe.Pipeline.BatchResolver | ||
|
||
require Logger | ||
|
||
def run_docset(pubsub, docs_and_topics, notification) do | ||
for {topic, key_strategy, doc} <- docs_and_topics do | ||
try do | ||
pipeline = | ||
Absinthe.Subscription.Local.pipeline(doc, notification) | ||
|
||
{:ok, %{result: data}, _} = Absinthe.Pipeline.run(doc.source, pipeline) | ||
|
||
Logger.debug(""" | ||
Absinthe Subscription Publication | ||
Field Topic: #{inspect(key_strategy)} | ||
Subscription id: #{inspect(topic)} | ||
Data: #{inspect(data)} | ||
""") | ||
|
||
case should_send?(data) do | ||
false -> | ||
:ok | ||
|
||
true -> | ||
:ok = pubsub.publish_subscription(topic, data) | ||
end | ||
rescue | ||
e -> | ||
BatchResolver.pipeline_error(e, __STACKTRACE__) | ||
end | ||
end | ||
end | ||
|
||
defp should_send?(%{errors: errors}) do | ||
# if the user is not allowed to see the data or the query didn't | ||
# return any data we do not send the error to the client | ||
# because it would just expose unnecessary information | ||
# and the user can not really do anything usefull with it | ||
not (errors | ||
|> List.wrap() | ||
|> Enum.any?(fn error -> Map.get(error, :code) in ["forbidden", "not_found"] end)) | ||
end | ||
|
||
defp should_send?(_), do: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters