Skip to content

Commit

Permalink
Merge branch 'main' of github.com:absinthe-graphql/absinthe into brya…
Browse files Browse the repository at this point in the history
…njos/unbounded_concurrency_fix
  • Loading branch information
bryanjos committed Aug 15, 2024
2 parents 486ba3e + 0c5d315 commit 92d09a5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
pull_request:
branches:
- master
- main

jobs:
test:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.7.8

- Bugfix: Fixes an issue where schemas would not find their types, or not be found at all.

## 1.7.7
- POTENTIALLY BREAKING Bug Fix: [Validate variable usage in nested input arguments](https://github.com/absinthe-graphql/absinthe/pull/1290).This could break incoming documents previously considered valid. Skip the Absinthe.Phase.Document.Arguments.VariableTypesMatch phase to avoid this check. See Absinthe.Pipeline on adjusting the document pipeline.
- #1321 resolves telemetry issues
Expand Down
32 changes: 15 additions & 17 deletions lib/absinthe/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ defmodule Absinthe.Subscription do
registry = pubsub |> registry_name

for field_key <- pdict_fields(doc_id) do
Registry.unregister(registry, field_key)
Registry.unregister_match(registry, field_key, doc_id)
end

Registry.unregister(registry, doc_id)
Expand All @@ -187,24 +187,22 @@ defmodule Absinthe.Subscription do

@doc false
def get(pubsub, key) do
pubsub
|> registry_name
|> Registry.lookup(key)
|> then(fn doc_ids ->
pubsub
|> registry_name
|> Registry.select(
# We compose a list of match specs that basically mean "lookup all keys
# in the doc_ids list"
for {_, doc_id} <- doc_ids,
do: {{:"$1", :_, :"$2"}, [{:==, :"$1", doc_id}], [{{:"$1", :"$2"}}]}
)
end)
|> Map.new(fn {doc_id, doc} ->
doc = Map.update!(doc, :initial_phases, &PipelineSerializer.unpack/1)
name = registry_name(pubsub)

{doc_id, doc}
name
|> Registry.lookup(key)
|> MapSet.new(fn {_pid, doc_id} -> doc_id end)
|> Enum.reduce([], fn doc_id, acc ->
case Registry.lookup(name, doc_id) do
[] ->
acc

[{_pid, doc} | _rest] ->
doc = Map.update!(doc, :initial_phases, &PipelineSerializer.unpack/1)
[{doc_id, doc} | acc]
end
end)
|> Map.new()
end

@doc false
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Absinthe.Mixfile do
use Mix.Project

@source_url "https://github.com/absinthe-graphql/absinthe"
@version "1.7.7"
@version "1.7.8"

def project do
[
Expand Down
33 changes: 33 additions & 0 deletions test/absinthe/execution/subscription_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,39 @@ defmodule Absinthe.Execution.SubscriptionTest do
refute_receive({:broadcast, _})
end

test "can unsubscribe from duplicate subscriptions individually" do
client_id = "abc"

assert {:ok, %{"subscribed" => topic1}} =
run_subscription(
@query,
Schema,
variables: %{"clientId" => client_id},
context: %{pubsub: PubSub}
)

assert {:ok, %{"subscribed" => topic2}} =
run_subscription(
@query,
Schema,
variables: %{"clientId" => client_id},
context: %{pubsub: PubSub}
)

Absinthe.Subscription.publish(PubSub, "foo", thing: client_id)
assert_receive({:broadcast, a})
assert_receive({:broadcast, b})
doc_ids = Enum.map([a, b], & &1.topic)
assert topic1 in doc_ids
assert topic2 in doc_ids

Absinthe.Subscription.unsubscribe(PubSub, topic1)
Absinthe.Subscription.publish(PubSub, "bar", thing: client_id)
assert_receive({:broadcast, a})
refute_receive({:broadcast, _})
assert topic2 == a.topic
end

@query """
subscription {
multipleTopics
Expand Down

0 comments on commit 92d09a5

Please sign in to comment.