mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 05:13:33 +12:00
fix: destroys can still have input objects
This commit is contained in:
parent
70bdcf3216
commit
053cef4a65
1 changed files with 52 additions and 54 deletions
|
@ -366,14 +366,12 @@ defmodule AshGraphql.Resource do
|
||||||
action = Ash.Resource.Info.action(resource, mutation.action)
|
action = Ash.Resource.Info.action(resource, mutation.action)
|
||||||
|
|
||||||
args =
|
args =
|
||||||
case(
|
case mutation_fields(
|
||||||
mutation_fields(
|
resource,
|
||||||
resource,
|
schema,
|
||||||
schema,
|
action,
|
||||||
action,
|
mutation.type
|
||||||
mutation.type
|
) do
|
||||||
)
|
|
||||||
) do
|
|
||||||
[] ->
|
[] ->
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
@ -530,29 +528,25 @@ defmodule AshGraphql.Resource do
|
||||||
__reference__: ref(__ENV__)
|
__reference__: ref(__ENV__)
|
||||||
}
|
}
|
||||||
|
|
||||||
if mutation.type == :destroy do
|
case mutation_fields(
|
||||||
[result]
|
resource,
|
||||||
else
|
schema,
|
||||||
case mutation_fields(
|
mutation.action,
|
||||||
resource,
|
mutation.type
|
||||||
schema,
|
) do
|
||||||
mutation.action,
|
[] ->
|
||||||
mutation.type
|
[result]
|
||||||
) do
|
|
||||||
[] ->
|
|
||||||
[result]
|
|
||||||
|
|
||||||
fields ->
|
fields ->
|
||||||
input = %Absinthe.Blueprint.Schema.InputObjectTypeDefinition{
|
input = %Absinthe.Blueprint.Schema.InputObjectTypeDefinition{
|
||||||
fields: fields,
|
fields: fields,
|
||||||
identifier: String.to_atom("#{mutation.name}_input"),
|
identifier: String.to_atom("#{mutation.name}_input"),
|
||||||
module: schema,
|
module: schema,
|
||||||
name: Macro.camelize("#{mutation.name}_input"),
|
name: Macro.camelize("#{mutation.name}_input"),
|
||||||
__reference__: ref(__ENV__)
|
__reference__: ref(__ENV__)
|
||||||
}
|
}
|
||||||
|
|
||||||
[input, result]
|
[input, result]
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -626,34 +620,38 @@ defmodule AshGraphql.Resource do
|
||||||
)
|
)
|
||||||
|
|
||||||
attribute_fields =
|
attribute_fields =
|
||||||
resource
|
if action.type == :destroy && !action.soft? do
|
||||||
|> Ash.Resource.Info.public_attributes()
|
[]
|
||||||
|> Enum.filter(fn attribute ->
|
else
|
||||||
is_nil(action.accept) || attribute.name in action.accept
|
resource
|
||||||
end)
|
|> Ash.Resource.Info.public_attributes()
|
||||||
|> Enum.filter(& &1.writable?)
|
|> Enum.filter(fn attribute ->
|
||||||
|> Enum.map(fn attribute ->
|
is_nil(action.accept) || attribute.name in action.accept
|
||||||
allow_nil? =
|
end)
|
||||||
attribute.allow_nil? || attribute.default != nil || type == :update ||
|
|> Enum.filter(& &1.writable?)
|
||||||
attribute.generated? ||
|
|> Enum.map(fn attribute ->
|
||||||
(type == :create && attribute.name in action.allow_nil_input)
|
allow_nil? =
|
||||||
|
attribute.allow_nil? || attribute.default != nil || type == :update ||
|
||||||
|
attribute.generated? ||
|
||||||
|
(type == :create && attribute.name in action.allow_nil_input)
|
||||||
|
|
||||||
explicitly_required = attribute.name in action.require_attributes
|
explicitly_required = attribute.name in action.require_attributes
|
||||||
|
|
||||||
field_type =
|
field_type =
|
||||||
attribute.type
|
attribute.type
|
||||||
|> field_type(attribute, resource, true)
|
|> field_type(attribute, resource, true)
|
||||||
|> maybe_wrap_non_null(explicitly_required || not allow_nil?)
|
|> maybe_wrap_non_null(explicitly_required || not allow_nil?)
|
||||||
|
|
||||||
%Absinthe.Blueprint.Schema.FieldDefinition{
|
%Absinthe.Blueprint.Schema.FieldDefinition{
|
||||||
description: attribute.description,
|
description: attribute.description,
|
||||||
identifier: attribute.name,
|
identifier: attribute.name,
|
||||||
module: schema,
|
module: schema,
|
||||||
name: to_string(attribute.name),
|
name: to_string(attribute.name),
|
||||||
type: field_type,
|
type: field_type,
|
||||||
__reference__: ref(__ENV__)
|
__reference__: ref(__ENV__)
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
argument_fields =
|
argument_fields =
|
||||||
action.arguments
|
action.arguments
|
||||||
|
|
Loading…
Reference in a new issue