File tree Expand file tree Collapse file tree 5 files changed +95
-2
lines changed
Expand file tree Collapse file tree 5 files changed +95
-2
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ defmodule AshGraphql.Graphql.Resolver do
6262 input =
6363 % Ash.ActionInput { domain: domain , resource: resource }
6464 |> Ash.ActionInput . set_context ( get_context ( context ) )
65- |> Ash.ActionInput . for_action ( action . name , arguments )
65+ |> Ash.ActionInput . for_action ( action . name , arguments , opts )
6666
6767 result =
6868 input
Original file line number Diff line number Diff line change @@ -199,4 +199,38 @@ defmodule AshGraphql.GenericActionsTest do
199199 )
200200 end
201201 end
202+
203+ describe "generic action with require_actor? domain" do
204+ test "succeeds when actor is provided via GraphQL context" do
205+ resp =
206+ """
207+ query {
208+ requireActorPing
209+ }
210+ """
211+ |> Absinthe . run ( AshGraphql.Test.Schema , context: % { actor: % { id: "an-actor" } } )
212+
213+ assert { :ok , result } = resp
214+
215+ refute Map . has_key? ( result , :errors )
216+
217+ assert % { data: % { "requireActorPing" => true } } = result
218+ end
219+
220+ test "succeeds with nil actor (opts always passed with actor key)" do
221+ resp =
222+ """
223+ query {
224+ requireActorPing
225+ }
226+ """
227+ |> Absinthe . run ( AshGraphql.Test.Schema )
228+
229+ assert { :ok , result } = resp
230+
231+ refute Map . has_key? ( result , :errors )
232+
233+ assert % { data: % { "requireActorPing" => true } } = result
234+ end
235+ end
202236end
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2020 ash_graphql contributors <https://github.com/ash-project/ash_graphql/graphs.contributors>
2+ #
3+ # SPDX-License-Identifier: MIT
4+
5+ defmodule AshGraphql.Test.RequireActorDomain do
6+ @ moduledoc false
7+
8+ use Ash.Domain ,
9+ extensions: [
10+ AshGraphql.Domain
11+ ] ,
12+ otp_app: :ash_graphql
13+
14+ authorization do
15+ require_actor? ( true )
16+ end
17+
18+ graphql do
19+ queries do
20+ action AshGraphql.Test.RequireActorResource , :require_actor_ping , :ping
21+ end
22+ end
23+
24+ resources do
25+ resource ( AshGraphql.Test.RequireActorResource )
26+ end
27+ end
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2020 ash_graphql contributors <https://github.com/ash-project/ash_graphql/graphs.contributors>
2+ #
3+ # SPDX-License-Identifier: MIT
4+
5+ defmodule AshGraphql.Test.RequireActorResource do
6+ @ moduledoc false
7+
8+ use Ash.Resource ,
9+ domain: AshGraphql.Test.RequireActorDomain ,
10+ extensions: [ AshGraphql.Resource ] ,
11+ data_layer: Ash.DataLayer.Ets
12+
13+ graphql do
14+ type :require_actor_resource
15+ end
16+
17+ attributes do
18+ uuid_primary_key ( :id )
19+ end
20+
21+ actions do
22+ action :ping , :boolean do
23+ run ( fn _input , _context ->
24+ { :ok , true }
25+ end )
26+ end
27+ end
28+ end
Original file line number Diff line number Diff line change @@ -7,7 +7,11 @@ defmodule AshGraphql.Test.Schema do
77
88 use Absinthe.Schema
99
10- @ domains [ AshGraphql.Test.Domain , AshGraphql.Test.OtherDomain ]
10+ @ domains [
11+ AshGraphql.Test.Domain ,
12+ AshGraphql.Test.OtherDomain ,
13+ AshGraphql.Test.RequireActorDomain
14+ ]
1115
1216 use AshGraphql , domains: @ domains , generate_sdl_file: "priv/schema.graphql"
1317
You can’t perform that action at this time.
0 commit comments