Skip to content

Commit

Permalink
Merge pull request #13 from Frameio/bryanj/GRAPH-1099/allow_extras_to…
Browse files Browse the repository at this point in the history
…_be_defined

[GRAPH-1099] Allows config error to return a map
  • Loading branch information
bryanjos authored Sep 27, 2024
2 parents 0a89be5 + ea99753 commit 6881fa5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/absinthe/phase/document/result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ defmodule Absinthe.Phase.Document.Result do
defp field_name(%{alias: name}), do: name
defp field_name(%{name: name}), do: name

defp format_error(%Phase.Error{message: %{message: _message} = error_object} = error, _opts) do
if Enum.empty?(error.locations) do
error_object
else
locations = Enum.flat_map(error.locations, &format_location/1)
Map.put_new(error_object, :locations, locations)
end
end

defp format_error(%Phase.Error{locations: []} = error, opts) do
error_object = %{message: error.message}

Expand Down
42 changes: 42 additions & 0 deletions test/absinthe/execution/subscription_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ defmodule Absinthe.Execution.SubscriptionTest do
{:ok, topic: "*", context_id: "*", document_id: op_name}
end
end

field :config_error, :string do
config fn _, _ ->
{:error, "failed"}
end
end

field :config_error_with_map, :string do
config fn _, _ ->
{:error, %{message: "failed", extensions: %{code: "FAILED"}}}
end
end
end

mutation do
Expand Down Expand Up @@ -584,6 +596,36 @@ defmodule Absinthe.Execution.SubscriptionTest do
assert_receive(:batch_get_group)
end

@query """
subscription Example {
configError
}
"""
test "config errors" do
assert {:ok, %{errors: [%{message: "failed"}]}} =
run_subscription(
@query,
Schema,
variables: %{},
context: %{pubsub: PubSub}
)
end

@query """
subscription Example {
configErrorWithMap
}
"""
test "config errors with a map" do
assert {:ok, %{errors: [%{message: "failed", extensions: %{code: "FAILED"}}]}} =
run_subscription(
@query,
Schema,
variables: %{},
context: %{pubsub: PubSub}
)
end

describe "subscription_ids" do
@query """
subscription {
Expand Down

0 comments on commit 6881fa5

Please sign in to comment.