Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardd committed May 3, 2022
1 parent d7bddaa commit f09e532
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 36 deletions.
6 changes: 4 additions & 2 deletions lib/absinthe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ defmodule Absinthe do
@type continuation_t :: nil | [Continuation.t()]

@type result_t ::
%{required(:data) => nil | result_selection_t,
%{
required(:data) => nil | result_selection_t,
optional(:ordinal) => term(),
optional(:continuation) => continuation_t,
optional(:errors) => [result_error_t]}
optional(:errors) => [result_error_t]
}
| %{errors: [result_error_t]}

@doc """
Expand Down
7 changes: 3 additions & 4 deletions lib/absinthe/blueprint/continuation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ defmodule Absinthe.Blueprint.Continuation do
]

@type t :: %__MODULE__{
phase_input: Pipeline.data_t,
pipeline: Pipeline.t()
}

phase_input: Pipeline.data_t(),
pipeline: Pipeline.t()
}
end
2 changes: 1 addition & 1 deletion lib/absinthe/phase/document/result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ defmodule Absinthe.Phase.Document.Result do
defp format_location(_), do: []

defp maybe_add_continuations(result, %{continuations: continuations}) when continuations != [],
do: Map.put(result, :continuation, continuations)
do: Map.put(result, :continuation, continuations)

defp maybe_add_continuations(result, _), do: result
end
8 changes: 7 additions & 1 deletion lib/absinthe/phase/subscription/get_ordinal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ defmodule Absinthe.Phase.Subscription.GetOrdinal do
@spec run(any, Keyword.t()) :: {:ok, Blueprint.t()}
def run(blueprint, _options \\ []) do
op = Blueprint.current_operation(blueprint)

if op.type == :subscription do
{:ok, %{blueprint | result: Map.put(blueprint.result, :ordinal, get_ordinal(op, blueprint))}}
{:ok,
%{blueprint | result: Map.put(blueprint.result, :ordinal, get_ordinal(op, blueprint))}}
else
{:ok, blueprint}
end
Expand All @@ -20,16 +22,20 @@ defmodule Absinthe.Phase.Subscription.GetOrdinal do
defp get_ordinal(op, blueprint) do
%{selections: [field]} = op
{:ok, config} = SubscribeSelf.get_config(field, blueprint.execution.context, blueprint)

case config[:ordinal] do
nil ->
nil

fun when is_function(fun, 1) ->
fun.(blueprint.execution.root_value)

_fun ->
IO.write(
:stderr,
"Ordinal function must be 1-arity"
)

nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/phase/subscription/prime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Absinthe.Phase.Subscription.Prime do
@moduledoc false

@spec run(any(), Keyword.t()) :: Phase.result_t()
def run(blueprint, [prime_result: cr]) do
def run(blueprint, prime_result: cr) do
{:ok, put_in(blueprint.execution.root_value, cr)}
end
end
1 change: 1 addition & 0 deletions lib/absinthe/phase/subscription/result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule Absinthe.Phase.Subscription.Result do
topic = Keyword.get(options, :topic)
prime = Keyword.get(options, :prime)
result = %{"subscribed" => topic}

case prime do
nil ->
{:ok, put_in(blueprint.result, result)}
Expand Down
8 changes: 4 additions & 4 deletions lib/absinthe/phase/subscription/subscribe_self.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ defmodule Absinthe.Phase.Subscription.SubscribeSelf do
end

def get_config(
%{schema_node: schema_node, argument_data: argument_data} = field,
context,
blueprint
) do
%{schema_node: schema_node, argument_data: argument_data} = field,
context,
blueprint
) do
name = schema_node.identifier

config =
Expand Down
5 changes: 4 additions & 1 deletion lib/absinthe/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ defmodule Absinthe.Pipeline do
case result do
{:ok, blueprint, phases} when rest == [] ->
{:ok, blueprint, phases}

{:ok, blueprint, phases} ->
bp_result = Map.put(blueprint.result, :continuation, rest)
blueprint = Map.put(blueprint, :result, bp_result)
{:ok, blueprint, phases}
error -> error

error ->
error
end
end

Expand Down
45 changes: 23 additions & 22 deletions test/absinthe/execution/subscription_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ defmodule Absinthe.Execution.SubscriptionTest do
:ok,
topic: args.client_id,
prime: fn %{context: %{prime_id: prime_id}} ->
{:ok, Enum.map(args.prime_data, &(%{id: prime_id, name: &1}))}
{:ok, Enum.map(args.prime_data, &%{id: prime_id, name: &1})}
end
}
end
Expand All @@ -154,8 +154,7 @@ defmodule Absinthe.Execution.SubscriptionTest do
config fn args, _ ->
{
:ok,
topic: args.client_id,
ordinal: fn %{version: version} -> version end
topic: args.client_id, ordinal: fn %{version: version} -> version end
}
end
end
Expand Down Expand Up @@ -217,7 +216,7 @@ defmodule Absinthe.Execution.SubscriptionTest do
assert %{
event: "subscription:data",
result: %{data: %{"thing" => "foo"}, ordinal: nil},
topic: topic,
topic: topic
} == msg
end

Expand Down Expand Up @@ -261,7 +260,7 @@ defmodule Absinthe.Execution.SubscriptionTest do
msg = %{
event: "subscription:data",
result: %{data: %{"multipleTopics" => "foo"}, ordinal: nil},
topic: topic,
topic: topic
}

Absinthe.Subscription.publish(PubSub, "foo", multiple_topics: "topic_1")
Expand Down Expand Up @@ -363,7 +362,7 @@ defmodule Absinthe.Execution.SubscriptionTest do
assert %{
event: "subscription:data",
result: %{data: %{"user" => %{"id" => "1", "name" => "foo"}}, ordinal: nil},
topic: topic,
topic: topic
} == msg
end

Expand Down Expand Up @@ -411,7 +410,7 @@ defmodule Absinthe.Execution.SubscriptionTest do
assert %{
event: "subscription:data",
result: %{data: %{"thing" => "foo"}, ordinal: nil},
topic: topic,
topic: topic
} == msg
end

Expand All @@ -430,7 +429,7 @@ defmodule Absinthe.Execution.SubscriptionTest do
assert %{
event: "subscription:data",
result: %{data: %{"thing" => "foo"}, ordinal: nil},
topic: topic,
topic: topic
} == msg
end)

Expand Down Expand Up @@ -642,7 +641,7 @@ defmodule Absinthe.Execution.SubscriptionTest do
assert %{
event: "subscription:data",
result: %{data: %{"thing" => "foo"}, ordinal: nil},
topic: topic,
topic: topic
} == msg

# Subscription events
Expand Down Expand Up @@ -675,13 +674,14 @@ defmodule Absinthe.Execution.SubscriptionTest do
context: %{prime_id: "test_prime_id"}
)

assert {:more, %{
data: %{"prime" => %{"id" => "test_prime_id", "name" => "name1"}},
continuation: continuation}}
= Absinthe.continue(continuation)
assert {:more,
%{
data: %{"prime" => %{"id" => "test_prime_id", "name" => "name1"}},
continuation: continuation
}} = Absinthe.continue(continuation)

assert {:ok, %{data: %{"prime" => %{"id" => "test_prime_id", "name" => "name2"}}}}
= Absinthe.continue(continuation)
assert {:ok, %{data: %{"prime" => %{"id" => "test_prime_id", "name" => "name2"}}}} =
Absinthe.continue(continuation)
end

@query """
Expand Down Expand Up @@ -733,14 +733,15 @@ defmodule Absinthe.Execution.SubscriptionTest do
}
)

assert {:more, %{
data: %{"primeOrdinal" => %{"name" => "first_user"}},
ordinal: 1,
continuation: continuation}}
= Absinthe.continue(continuation)
assert {:more,
%{
data: %{"primeOrdinal" => %{"name" => "first_user"}},
ordinal: 1,
continuation: continuation
}} = Absinthe.continue(continuation)

assert {:ok, %{data: %{"primeOrdinal" => %{"name" => "second_user"}}, ordinal: 2}}
= Absinthe.continue(continuation)
assert {:ok, %{data: %{"primeOrdinal" => %{"name" => "second_user"}}, ordinal: 2}} =
Absinthe.continue(continuation)
end

defp run_subscription(query, schema, opts \\ []) do
Expand Down

0 comments on commit f09e532

Please sign in to comment.