AE
Ash Elixir•2y ago
moxley

Return aggregate after GraphQL mutation

I have an aggregate defined like this:
aggregates do
count :events_count, :events
end
aggregates do
count :events_count, :events
end
And GraphQL queries defined like this:
graphql do
type :venue2

queries do
get :get_venue2, :read
list :list_venues2, :read
end

mutations do
create :create_venue2, :create
update :update_venue2, :update
destroy :delete_venue2, :destroy
end
end
graphql do
type :venue2

queries do
get :get_venue2, :read
list :list_venues2, :read
end

mutations do
create :create_venue2, :create
update :update_venue2, :update
destroy :delete_venue2, :destroy
end
end
When I call get_venue2 or list_venues2, and the query requests the aggregate, the aggregate returns successfully. When I call update_venue2, and request the aggregate, it fails with a forbidden error in the response. Removing the aggregate from the query makes the error go away, but now I don't have the aggregate I need. Apparently, whatever automatic passing of the actor to the aggregate that happens in the read queries isn't happening with the mutation. Is there a solution for this?
4 Replies
moxley
moxleyOP•2y ago
And my policy looks like this:
policies do
policy always() do
authorize_if {ActiveMemberPolicy, role: :events}
end
end
policies do
policy always() do
authorize_if {ActiveMemberPolicy, role: :events}
end
end
The same result happens if I open the policy to this:
policies do
policy always() do
authorize_if always()
end
end
policies do
policy always() do
authorize_if always()
end
end
ZachDaniel
ZachDaniel•2y ago
🤔 are you on the latest ash_graphql and ash? There were some changes to data loading for mutations very recently I've got it reproduced actually looking into it now ah, no nevermind, I had a typo I can confirm that an aggregate in an application of mine that reads a resource w/ policies is getting the correct user. and its on the latest of everything. I think we've worked out the last bugs from the relatively big underlying ash_graphql changes we made recently So it should be stable to upgrade
moxley
moxleyOP•2y ago
I upgraded all the ash* dependencies. After a wild ride adjusting to the breaking changes, now it's working!
ZachDaniel
ZachDaniel•2y ago
what breaking changes did you have to deal with? 😢 sorry about that

Did you find this page helpful?