Skip to content

Commit

Permalink
improvement: Support generic actions without a return type. (#238)
Browse files Browse the repository at this point in the history
Infer that their return type is `:boolean` and they always return `true`.
We considered returning `null` but that's also returned when the query/mutation fails and might convey the wrong information.
  • Loading branch information
jimsynz authored Nov 14, 2024
1 parent 07d796a commit 4559267
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/graphql/resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ defmodule AshGraphql.Graphql.Resolver do
|> Ash.ActionInput.for_action(action.name, arguments)
|> Ash.run_action(opts)
|> case do
:ok ->
{:ok, true}

{:ok, result} ->
load_opts =
[
Expand Down
6 changes: 1 addition & 5 deletions lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1643,12 +1643,8 @@ defmodule AshGraphql.Resource do
end

defp generic_action_type(action, resource) do
if !action.returns do
raise "Cannot use #{inspect(resource)}.#{action.name} with AshGraphql, because it does not have a return type."
end

fake_attribute = %{
type: action.returns,
type: action.returns || Ash.Type.Boolean,
constraints: action.constraints,
allow_nil?: Map.get(action, :allow_nil?, false),
name: action.name
Expand Down

0 comments on commit 4559267

Please sign in to comment.