improvement: add more NonNulls

This commit is contained in:
Zach Daniel 2020-11-11 22:53:53 -05:00
parent daf8513c26
commit cacec2de1d
No known key found for this signature in database
GPG key ID: C377365383138D4B

View file

@ -387,7 +387,7 @@ defmodule AshGraphql.Resource do
%Absinthe.Blueprint.Schema.InputValueDefinition{ %Absinthe.Blueprint.Schema.InputValueDefinition{
name: "id", name: "id",
identifier: :id, identifier: :id,
type: :id, type: %Absinthe.Blueprint.TypeReference.NonNull{of_type: :id},
description: "The id of the record" description: "The id of the record"
} }
] ]
@ -642,7 +642,7 @@ defmodule AshGraphql.Resource do
identifier: :id, identifier: :id,
module: schema, module: schema,
name: "id", name: "id",
type: :id type: %Absinthe.Blueprint.TypeReference.NonNull{of_type: :id}
} }
attribute -> attribute ->
@ -676,7 +676,14 @@ defmodule AshGraphql.Resource do
end) end)
|> Enum.map(fn |> Enum.map(fn
%{cardinality: :one} = relationship -> %{cardinality: :one} = relationship ->
type = Resource.type(relationship.destination) type =
if relationship.type == :belongs_to && relationship.required? do
%Absinthe.Blueprint.TypeReference.NonNull{
of_type: Resource.type(relationship.destination)
}
else
Resource.type(relationship.destination)
end
%Absinthe.Blueprint.Schema.FieldDefinition{ %Absinthe.Blueprint.Schema.FieldDefinition{
identifier: relationship.name, identifier: relationship.name,