mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-19 21:03:09 +12:00
fix: wrap type in non-null reference if allow_nil? is set to false
This commit is contained in:
parent
8f9e79e273
commit
ff06d5a540
4 changed files with 68 additions and 13 deletions
|
@ -2454,13 +2454,24 @@ defmodule AshGraphql.Resource do
|
||||||
identifier: name,
|
identifier: name,
|
||||||
__reference__: AshGraphql.Resource.ref(env),
|
__reference__: AshGraphql.Resource.ref(env),
|
||||||
name: to_string(name),
|
name: to_string(name),
|
||||||
type: nested_type_name
|
type:
|
||||||
|
if Keyword.get(
|
||||||
|
constraints || [],
|
||||||
|
:allow_nil?,
|
||||||
|
true
|
||||||
|
) do
|
||||||
|
nested_type_name
|
||||||
|
else
|
||||||
|
%Absinthe.Blueprint.TypeReference.NonNull{
|
||||||
|
of_type: nested_type_name
|
||||||
|
}
|
||||||
|
end
|
||||||
}
|
}
|
||||||
| fields
|
| fields
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
_ ->
|
{type, constraints} ->
|
||||||
{types,
|
{types,
|
||||||
[
|
[
|
||||||
%Absinthe.Blueprint.Schema.FieldDefinition{
|
%Absinthe.Blueprint.Schema.FieldDefinition{
|
||||||
|
@ -2468,7 +2479,18 @@ defmodule AshGraphql.Resource do
|
||||||
identifier: name,
|
identifier: name,
|
||||||
__reference__: AshGraphql.Resource.ref(env),
|
__reference__: AshGraphql.Resource.ref(env),
|
||||||
name: to_string(name),
|
name: to_string(name),
|
||||||
type: do_field_type(attribute[:type], nil, nil, false)
|
type:
|
||||||
|
if Keyword.get(
|
||||||
|
constraints || [],
|
||||||
|
:allow_nil?,
|
||||||
|
true
|
||||||
|
) do
|
||||||
|
do_field_type(type, nil, nil, false)
|
||||||
|
else
|
||||||
|
%Absinthe.Blueprint.TypeReference.NonNull{
|
||||||
|
of_type: do_field_type(type, nil, nil, false)
|
||||||
|
}
|
||||||
|
end
|
||||||
}
|
}
|
||||||
| fields
|
| fields
|
||||||
]}
|
]}
|
||||||
|
@ -2515,13 +2537,20 @@ defmodule AshGraphql.Resource do
|
||||||
identifier: name,
|
identifier: name,
|
||||||
__reference__: AshGraphql.Resource.ref(env),
|
__reference__: AshGraphql.Resource.ref(env),
|
||||||
name: to_string(name),
|
name: to_string(name),
|
||||||
type: nested_type_name
|
type:
|
||||||
|
if Keyword.get(constraints || [], :allow_nil?, true) do
|
||||||
|
nested_type_name
|
||||||
|
else
|
||||||
|
%Absinthe.Blueprint.TypeReference.NonNull{
|
||||||
|
of_type: nested_type_name
|
||||||
|
}
|
||||||
|
end
|
||||||
}
|
}
|
||||||
| fields
|
| fields
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
_ ->
|
{type, constraints} ->
|
||||||
{types,
|
{types,
|
||||||
[
|
[
|
||||||
%Absinthe.Blueprint.Schema.InputValueDefinition{
|
%Absinthe.Blueprint.Schema.InputValueDefinition{
|
||||||
|
@ -2529,7 +2558,14 @@ defmodule AshGraphql.Resource do
|
||||||
identifier: name,
|
identifier: name,
|
||||||
__reference__: AshGraphql.Resource.ref(env),
|
__reference__: AshGraphql.Resource.ref(env),
|
||||||
name: to_string(name),
|
name: to_string(name),
|
||||||
type: do_field_type(attribute[:type], nil, nil, false)
|
type:
|
||||||
|
if Keyword.get(constraints || [], :allow_nil?, true) do
|
||||||
|
do_field_type(type, nil, nil, false)
|
||||||
|
else
|
||||||
|
%Absinthe.Blueprint.TypeReference.NonNull{
|
||||||
|
of_type: do_field_type(type, nil, nil, false)
|
||||||
|
}
|
||||||
|
end
|
||||||
}
|
}
|
||||||
| fields
|
| fields
|
||||||
]}
|
]}
|
||||||
|
|
|
@ -157,8 +157,11 @@ defmodule AshGraphql.AttributeTest do
|
||||||
data["__type"]["inputFields"]
|
data["__type"]["inputFields"]
|
||||||
|> Enum.find(fn field -> field["name"] == "foo" end)
|
|> Enum.find(fn field -> field["name"] == "foo" end)
|
||||||
|
|
||||||
assert foo_field["type"]["kind"] == "SCALAR"
|
# non null field
|
||||||
assert foo_field["type"]["name"] == "String"
|
assert foo_field["type"]["kind"] == "NON_NULL"
|
||||||
|
|
||||||
|
assert foo_field["type"]["ofType"]["kind"] == "SCALAR"
|
||||||
|
assert foo_field["type"]["ofType"]["name"] == "String"
|
||||||
|
|
||||||
bar_field =
|
bar_field =
|
||||||
data["__type"]["inputFields"]
|
data["__type"]["inputFields"]
|
||||||
|
@ -257,7 +260,11 @@ defmodule AshGraphql.AttributeTest do
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
"name" => "fooBar",
|
"name" => "fooBar",
|
||||||
"type" => %{"kind" => "SCALAR", "name" => "String", "ofType" => nil}
|
"type" => %{
|
||||||
|
"kind" => "NON_NULL",
|
||||||
|
"name" => nil,
|
||||||
|
"ofType" => %{"kind" => "SCALAR", "name" => "String"}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -301,7 +308,11 @@ defmodule AshGraphql.AttributeTest do
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
"name" => "fooBar",
|
"name" => "fooBar",
|
||||||
"type" => %{"kind" => "SCALAR", "name" => "String", "ofType" => nil}
|
"type" => %{
|
||||||
|
"kind" => "NON_NULL",
|
||||||
|
"name" => nil,
|
||||||
|
"ofType" => %{"kind" => "SCALAR", "name" => "String"}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,9 @@ defmodule AshGraphql.Test.ConstrainedMap do
|
||||||
fields: [
|
fields: [
|
||||||
foo_bar: [
|
foo_bar: [
|
||||||
type: :string,
|
type: :string,
|
||||||
allow_nil?: false
|
constraints: [
|
||||||
|
allow_nil?: false
|
||||||
|
]
|
||||||
],
|
],
|
||||||
baz: [
|
baz: [
|
||||||
type: :integer
|
type: :integer
|
||||||
|
|
|
@ -11,7 +11,10 @@ defmodule AshGraphql.Test.MapTypes do
|
||||||
constraints(
|
constraints(
|
||||||
fields: [
|
fields: [
|
||||||
foo: [
|
foo: [
|
||||||
type: :string
|
type: :string,
|
||||||
|
constraints: [
|
||||||
|
allow_nil?: false
|
||||||
|
]
|
||||||
],
|
],
|
||||||
bar: [
|
bar: [
|
||||||
type: :integer
|
type: :integer
|
||||||
|
@ -39,7 +42,10 @@ defmodule AshGraphql.Test.MapTypes do
|
||||||
constraints(
|
constraints(
|
||||||
fields: [
|
fields: [
|
||||||
foo: [
|
foo: [
|
||||||
type: :string
|
type: :string,
|
||||||
|
constraints: [
|
||||||
|
allow_nil?: false
|
||||||
|
]
|
||||||
],
|
],
|
||||||
bar: [
|
bar: [
|
||||||
type: :integer
|
type: :integer
|
||||||
|
|
Loading…
Reference in a new issue