How to handle max cost on a per user basis in absinthe

Maybe https://hexdocs.pm/absinthe_plug/Absinthe.Plug.html#put_options/2 would work?

case user do
  %User{admin?: true} -> Absinthe.Plug.put_options(conn, max_complexity: 100)
  _user -> Absinthe.Plug.put_options(conn, max_complexity: 50)
end

It seems to be updating conn.private.absinthe map.

For :max_complexity to work, analyze_complexity: true should be set during plug’s init as well, I think.

Absinthe.Plug.init([max_complexity: @default_max_complexity, analyze_complexity: true] ++ opts)
1 Like