Module: GraphQL::Pundit::Scope

Included in:
Field
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



32
33
34
# File 'lib/graphql-pundit/scope.rb', line 32

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

#before_scope(scope = true) ⇒ Object

rubocop:enable Metrics/ParameterLists



28
29
30
# File 'lib/graphql-pundit/scope.rb', line 28

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

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

rubocop:disable Metrics/ParameterLists



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/graphql-pundit/scope.rb', line 14

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

#resolve(obj, args, ctx) ⇒ Object Also known as: resolve_field



36
37
38
39
40
# File 'lib/graphql-pundit/scope.rb', line 36

def resolve(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