Class: GraphQL::FancyLoader::PunditMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/fancy_loader/pundit_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(key:) ⇒ PunditMiddleware

Returns a new instance of PunditMiddleware.



3
4
5
# File 'lib/graphql/fancy_loader/pundit_middleware.rb', line 3

def initialize(key:)
  @key = key
end

Instance Method Details

#call(model:, query:, context:) ⇒ Object



7
8
9
10
11
# File 'lib/graphql/fancy_loader/pundit_middleware.rb', line 7

def call(model:, query:, context:)
  scope = ::Pundit::PolicyFinder.new(model).scope!
  user = context[@key]
  scope.new(user, query).resolve
end