Permit.Absinthe.Middleware.DataloaderSetup (permit_absinthe v0.1.0)
Middleware that sets up authorization-aware dataloaders during GraphQL field resolution.
The problem: traditional dataloader setup happens in the schema's context/1
callback,
before we know anything about field-specific authorization. This middleware fixes that
by creating dataloaders on-demand with the right authorization context.
Add it to top-level fields:
field :me, :user do
middleware Permit.Absinthe.Middleware.DataloaderSetup
resolve &UserResolver.me/3
end
Then use the configured sources in nested resolvers:
object :user do
field :articles, list_of(:article) do
resolve &Permit.Absinthe.Resolvers.Dataloader.authorized_dataloader/3
end
end
Each dataloader source gets a unique key like "MyApp.Auth:me:read"
so different
authorization contexts don't step on each other.