Skip to content

Commit

Permalink
improvement: make mutation results non-nullable (#110)
Browse files Browse the repository at this point in the history
Adjust rool level error tests: since result is now non-nullable, if the content
of the result is nil, the whole result becomes nil. Note that this is not a
breaking change since GraphQL always allows a field nullability to propagate
upwards in case of a field error (see October 2021 spec, section 6.4.4).
  • Loading branch information
rbino authored Jan 31, 2024
1 parent afa4ae6 commit af4193f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 9 additions & 3 deletions lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,9 @@ defmodule AshGraphql.Resource do
module: schema,
name: to_string(mutation.name),
description: Ash.Resource.Info.action(resource, mutation.action).description,
type: String.to_atom("#{mutation.name}_result"),
type: %Absinthe.Blueprint.TypeReference.NonNull{
of_type: String.to_atom("#{mutation.name}_result")
},
__reference__: ref(__ENV__)
}
end
Expand Down Expand Up @@ -642,7 +644,9 @@ defmodule AshGraphql.Resource do
module: schema,
name: to_string(mutation.name),
description: Ash.Resource.Info.action(resource, mutation.action).description,
type: String.to_atom("#{mutation.name}_result"),
type: %Absinthe.Blueprint.TypeReference.NonNull{
of_type: String.to_atom("#{mutation.name}_result")
},
__reference__: ref(__ENV__)
}

Expand Down Expand Up @@ -693,7 +697,9 @@ defmodule AshGraphql.Resource do
module: schema,
name: to_string(mutation.name),
description: Ash.Resource.Info.action(resource, mutation.action).description,
type: String.to_atom("#{mutation.name}_result"),
type: %Absinthe.Blueprint.TypeReference.NonNull{
of_type: String.to_atom("#{mutation.name}_result")
},
__reference__: ref(__ENV__)
}
end
Expand Down
8 changes: 3 additions & 5 deletions test/errors_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule AshGraphql.ErrorsTest do

assert {:ok, result} = resp

assert %{data: %{"createPost" => nil}, errors: [%{message: message}]} = result
assert %{data: nil, errors: [%{message: message}]} = result

assert message =~ "confirmation did not match value"
end
Expand Down Expand Up @@ -68,7 +68,7 @@ defmodule AshGraphql.ErrorsTest do

assert {:ok, result} = resp

assert %{data: %{"createPostWithError" => nil}, errors: [%{message: message}]} =
assert %{data: nil, errors: [%{message: message}]} =
result

assert message =~ "Something went wrong."
Expand Down Expand Up @@ -139,9 +139,7 @@ defmodule AshGraphql.ErrorsTest do
assert {:ok, result} = resp

assert %{
data: %{
"createPostWithError" => nil
},
data: nil,
errors: [
%{message: message}
]
Expand Down

0 comments on commit af4193f

Please sign in to comment.