moxley
I’m running into a policy and AshGraphql problem, and it seems like a bug.
Here’s my GraphQL query:
query GetEvent2($id: ID!) {
getEvent2(id: $id) {
id
}
}
It’s returning the following response:
%{"data" => %{"getEvent2" => nil}}
Here’s the policy debug log:
[debug] Successful authorization: GF.Events.Event2.read
Generated Filter:
invites.member_id == "BKDK97081LAQXMUJR"
Policy Breakdown
member2: %{id: "BKDK97081LAQXMUJR"}
Policy | 🔎:
condition: action == :read
authorize if: invites.member_id == "BKDK97081LAQXMUJR" | ✓ | 🔎
And here’s the policy definition:
policy action :read do
# authorize_if expr(is_public)
# authorize_if expr(^actor(:status) == :active)
authorize_if expr(invites.member_id == ^actor(:id))
end
The primary resource is Event2, which has_many Invites. Each Invite has a member_id. The actor is a Member whose ID matches member_id.
If I use straight Ash.get!(Event2, event_id, actor: actor), that returns Event2 data.
If I uncomment those two other authorize_if lines, then modify the test setup to use either of them, the query returns the expected response data. It’s just that last authorize_if that seems to be tripping things up. What is different about it? Is it because it goes throug a has_many relationship?
I also tried opening up the :read policy on the Invite resource, to allow anyone to read that, and that didn’t help.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
Try using
EDIT: not sure if its your issue or not, but if it is, the context for what may be happening is here:
In the section on “using
exists” (which I frustratingly cannot anchor link you directly to)moxley
I tried that
exists()expression earlier today, after reading that documentation. I just tried it again now, with the same result. Here’s the SQL from the logs, if you’re interested:zachdaniel
Hmm…that seems right? In terms of how the
existsquery should be run. Do you know where thegroup_id = $2part of the query comes from?moxley
The group_id is the tenant. That’s added automatically. The query looks correct. The policy passes (according to the logs). It’s just that the data returned from the GraphQL is empty.
zachdaniel
moxley
LIke this?
Yeah, it returned Event2 data, using the same test setup as the GraphQL test.
I’ll return to this tomorrow, and re-check the test, just to be sure.
zachdaniel
It definitely seems like a bug somewhere, but I think its at the point where I’ll need to be able to reproduce it as nothing is really jumping out at me
moxley
I extracted the problem away from AshGraphql:
This produces
{:ok, nil}.However, if I remove
|> Ash.Query.set_tenant(ctx.group.id)from the expression, it returns the Event2 struct instead of nil.moxley
Found the problem. The Invite didn’t have a group_id (tenant). It works now!
Thanks for working through this problem with me @zachdaniel!