Skip to content

Commit a035261

Browse files
fix: only null values should also trigger error (#1394)
Co-authored-by: Peter Arentsen <peter.arentsen@bettyblocks.com>
1 parent 77155e3 commit a035261

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/absinthe/phase/document/validation/one_of_directive.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ defmodule Absinthe.Phase.Document.Validation.OneOfDirective do
2020

2121
defp process(%Argument{input_value: %{normalized: %Object{} = object}} = node) do
2222
if Keyword.has_key?(object.schema_node.__private__, :one_of) and
23-
field_count(object.fields) > 1 do
23+
field_count(object.fields) != 1 do
2424
message =
2525
~s[The Input Type "#{object.schema_node.name}" has the @oneOf directive. It must have exactly one non-null field.]
2626

test/absinthe/phase/document/validation/one_of_directive_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ defmodule Absinthe.Phase.Document.Validation.OneOfDirectiveTest do
5757
refute result[:data]
5858
end
5959

60+
test "with both inline args nil" do
61+
query = ~s[query { valid(input: {id: null, name: null}) }]
62+
assert {:ok, %{errors: [error]} = result} = Absinthe.run(query, Schema)
63+
assert %{locations: [%{column: 15, line: 1}], message: @message} = error
64+
refute result[:data]
65+
end
66+
6067
test "with both variable args" do
6168
options = [variables: %{"input" => %{"id" => 1, "name" => "a"}}]
6269
assert {:ok, %{errors: [error]} = result} = Absinthe.run(@query, Schema, options)

0 commit comments

Comments
 (0)