Module: GraphQL::Pundit::Scope

Defined in:
lib/graphql-pundit/scope.rb

Overview

Scope methods to be included in the used Field class

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



9
10
11
# File 'lib/graphql-pundit/scope.rb', line 9

def self.prepended(base)
  base.include(GraphQL::Pundit::Common)
end

Instance Method Details

#after_scope(scope = true) ⇒ Object



25
26
27
# File 'lib/graphql-pundit/scope.rb', line 25

def after_scope(scope = true)
  @after_scope = scope
end

#before_scope(scope = true) ⇒ Object



21
22
23
# File 'lib/graphql-pundit/scope.rb', line 21

def before_scope(scope = true)
  @before_scope = scope
end

#initialize(*args, before_scope: nil, after_scope: nil, **kwargs, &block) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/graphql-pundit/scope.rb', line 13

def initialize(*args, before_scope: nil,
                      after_scope: nil,
                      **kwargs, &block)
  @before_scope = before_scope
  @after_scope = after_scope
  super(*args, **kwargs, &block)
end

#resolve_field(obj, args, ctx) ⇒ Object



29
30
31
32
33
# File 'lib/graphql-pundit/scope.rb', line 29

def resolve_field(obj, args, ctx)
  before_scope_return = apply_scope(@before_scope, obj, args, ctx)
  field_return = super(before_scope_return, args, ctx)
  apply_scope(@after_scope, field_return, args, ctx)
end