Ash FrameworkAF
Ash Framework3y ago
82 replies
Blibs

AshGraphql generated mutations are bypassing schema middleware

I have this middleware in my GraphQL schema to check if the user is authenticated:

  def middleware(middleware, field, obj) do
    if obj.identifier in [:query, :subscription, :mutation] and
         field.identifier not in @not_auth_apis do
      IO.puts("got here 1!")
      [Middlewares.EnsureAuthenticated | middleware]
    else
      IO.puts("got here 2!")
      middleware
    end
  end


All my custom made queries/mutations will reach that middleware function without a problem.

Now, I have this in one of my resources:

  graphql do
    type :offer

    queries do
    end

    mutations do
      create :place_offer, :place_offer
    end
  end


If I call that mutation, it will not call my middleware function at all.

If I create an equivalent for that mutation by hand, then the middleware is called as expected.
Was this page helpful?