Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/graphql/resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ defmodule AshGraphql.Graphql.Resolver do
input =
%Ash.ActionInput{domain: domain, resource: resource}
|> Ash.ActionInput.set_context(get_context(context))
|> Ash.ActionInput.for_action(action.name, arguments)
|> Ash.ActionInput.for_action(action.name, arguments, opts)

result =
input
Expand Down
34 changes: 34 additions & 0 deletions test/generic_actions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,38 @@ defmodule AshGraphql.GenericActionsTest do
)
end
end

describe "generic action with require_actor? domain" do
test "succeeds when actor is provided via GraphQL context" do
resp =
"""
query {
requireActorPing
}
"""
|> Absinthe.run(AshGraphql.Test.Schema, context: %{actor: %{id: "an-actor"}})

assert {:ok, result} = resp

refute Map.has_key?(result, :errors)

assert %{data: %{"requireActorPing" => true}} = result
end

test "succeeds with nil actor (opts always passed with actor key)" do
resp =
"""
query {
requireActorPing
}
"""
|> Absinthe.run(AshGraphql.Test.Schema)

assert {:ok, result} = resp

refute Map.has_key?(result, :errors)

assert %{data: %{"requireActorPing" => true}} = result
end
end
end
27 changes: 27 additions & 0 deletions test/support/require_actor_domain.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-FileCopyrightText: 2020 ash_graphql contributors <https://github.com/ash-project/ash_graphql/graphs.contributors>
#
# SPDX-License-Identifier: MIT

defmodule AshGraphql.Test.RequireActorDomain do
@moduledoc false

use Ash.Domain,
extensions: [
AshGraphql.Domain
],
otp_app: :ash_graphql

authorization do
require_actor?(true)
end

graphql do
queries do
action AshGraphql.Test.RequireActorResource, :require_actor_ping, :ping
end
end

resources do
resource(AshGraphql.Test.RequireActorResource)
end
end
28 changes: 28 additions & 0 deletions test/support/resources/require_actor_resource.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: 2020 ash_graphql contributors <https://github.com/ash-project/ash_graphql/graphs.contributors>
#
# SPDX-License-Identifier: MIT

defmodule AshGraphql.Test.RequireActorResource do
@moduledoc false

use Ash.Resource,
domain: AshGraphql.Test.RequireActorDomain,
extensions: [AshGraphql.Resource],
data_layer: Ash.DataLayer.Ets

graphql do
type :require_actor_resource
end

attributes do
uuid_primary_key(:id)
end

actions do
action :ping, :boolean do
run(fn _input, _context ->
{:ok, true}
end)
end
end
end
6 changes: 5 additions & 1 deletion test/support/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ defmodule AshGraphql.Test.Schema do

use Absinthe.Schema

@domains [AshGraphql.Test.Domain, AshGraphql.Test.OtherDomain]
@domains [
AshGraphql.Test.Domain,
AshGraphql.Test.OtherDomain,
AshGraphql.Test.RequireActorDomain
]

use AshGraphql, domains: @domains, generate_sdl_file: "priv/schema.graphql"

Expand Down
Loading