mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-19 12:53:40 +12:00
improvement: make mutation result errors list non-nullable (#144)
* chore: regenerate cheat sheets * improvement: make mutation result errors list non-nullable
This commit is contained in:
parent
446bc12f70
commit
7386a5b627
3 changed files with 84 additions and 31 deletions
|
@ -3,11 +3,11 @@ This file was generated by Spark. Do not edit it by hand.
|
|||
-->
|
||||
# DSL: AshGraphql.Domain
|
||||
|
||||
The entrypoint for adding graphql behavior to an Ash domain
|
||||
The entrypoint for adding GraphQL behavior to an Ash domain
|
||||
|
||||
|
||||
## graphql
|
||||
Global configuration for graphql
|
||||
Domain level configuration for GraphQL
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -930,9 +930,11 @@ defmodule AshGraphql.Resource do
|
|||
identifier: :errors,
|
||||
module: schema,
|
||||
name: "errors",
|
||||
type: %Absinthe.Blueprint.TypeReference.List{
|
||||
of_type: %Absinthe.Blueprint.TypeReference.NonNull{
|
||||
of_type: :mutation_error
|
||||
type: %Absinthe.Blueprint.TypeReference.NonNull{
|
||||
of_type: %Absinthe.Blueprint.TypeReference.List{
|
||||
of_type: %Absinthe.Blueprint.TypeReference.NonNull{
|
||||
of_type: :mutation_error
|
||||
}
|
||||
}
|
||||
},
|
||||
__reference__: ref(__ENV__)
|
||||
|
|
|
@ -11,34 +11,72 @@ defmodule AshGraphql.ErrorsTest do
|
|||
end)
|
||||
end
|
||||
|
||||
test "errors can be configured to be shown in the root" do
|
||||
resp =
|
||||
"""
|
||||
mutation CreatePost($input: CreatePostInput) {
|
||||
createPost(input: $input) {
|
||||
result{
|
||||
text
|
||||
}
|
||||
errors{
|
||||
message
|
||||
describe "when root level errors are enabled" do
|
||||
test "errors that occur are shown at the root level" do
|
||||
resp =
|
||||
"""
|
||||
mutation CreatePost($input: CreatePostInput) {
|
||||
createPost(input: $input) {
|
||||
result{
|
||||
text
|
||||
}
|
||||
errors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|> Absinthe.run(AshGraphql.Test.RootLevelErrorsSchema,
|
||||
variables: %{
|
||||
"input" => %{
|
||||
"text" => "foobar",
|
||||
"confirmation" => "foobar2"
|
||||
"""
|
||||
|> Absinthe.run(AshGraphql.Test.RootLevelErrorsSchema,
|
||||
variables: %{
|
||||
"input" => %{
|
||||
"text" => "foobar",
|
||||
"confirmation" => "foobar2"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
assert {:ok, result} = resp
|
||||
|
||||
assert %{data: %{"createPost" => nil}, errors: [%{message: message}]} = result
|
||||
assert message =~ "confirmation did not match value"
|
||||
end
|
||||
|
||||
test "the root level errors field is not present when no errors occur" do
|
||||
resp =
|
||||
"""
|
||||
mutation CreatePost($input: CreatePostInput) {
|
||||
createPost(input: $input) {
|
||||
result{
|
||||
text
|
||||
}
|
||||
errors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
"""
|
||||
|> Absinthe.run(AshGraphql.Test.RootLevelErrorsSchema,
|
||||
variables: %{
|
||||
"input" => %{
|
||||
"text" => "foobar",
|
||||
"confirmation" => "foobar"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
assert {:ok, result} = resp
|
||||
assert {:ok, result} = resp
|
||||
|
||||
assert %{data: %{"createPost" => nil}, errors: [%{message: message}]} = result
|
||||
assert %{
|
||||
data: %{
|
||||
"createPost" => %{
|
||||
"result" => %{"text" => "foobar"},
|
||||
"errors" => []
|
||||
}
|
||||
}
|
||||
} = result
|
||||
|
||||
assert message =~ "confirmation did not match value"
|
||||
refute Map.has_key?(result, :errors)
|
||||
end
|
||||
end
|
||||
|
||||
test "raised errors are by default not shown" do
|
||||
|
@ -354,7 +392,7 @@ defmodule AshGraphql.ErrorsTest do
|
|||
assert message =~ "Breakdown"
|
||||
end
|
||||
|
||||
test "error items are non-nullable" do
|
||||
test "error items are a non-nullable list of non-nullables" do
|
||||
{:ok, %{data: data}} =
|
||||
"""
|
||||
query {
|
||||
|
@ -366,7 +404,10 @@ defmodule AshGraphql.ErrorsTest do
|
|||
ofType {
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -380,9 +421,19 @@ defmodule AshGraphql.ErrorsTest do
|
|||
data["__type"]["fields"]
|
||||
|> Enum.find(fn field -> field["name"] == "errors" end)
|
||||
|
||||
assert errors["type"]["kind"] == "LIST"
|
||||
assert errors["type"]["ofType"]["kind"] == "NON_NULL"
|
||||
assert errors["type"]["ofType"]["ofType"]["name"] == "MutationError"
|
||||
assert errors == %{
|
||||
"name" => "errors",
|
||||
"type" => %{
|
||||
"kind" => "NON_NULL",
|
||||
"ofType" => %{
|
||||
"kind" => "LIST",
|
||||
"ofType" => %{
|
||||
"kind" => "NON_NULL",
|
||||
"ofType" => %{"name" => "MutationError"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
test "MutationError fields items are non-nullable" do
|
||||
|
|
Loading…
Reference in a new issue