Class: GraphQL::Filter Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: MergedExcept, MergedOnly

Instance Method Summary collapse

Constructor Details

#initialize(only: nil, except: nil) ⇒ Filter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Filter



5
6
7
8
# File 'lib/graphql/filter.rb', line 5

def initialize(only: nil, except: nil)
  @only = only
  @except = except
end

Instance Method Details

#call(member, ctx) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if member, ctx passes this filter



11
12
13
14
# File 'lib/graphql/filter.rb', line 11

def call(member, ctx)
  (@only ? @only.call(member, ctx) : true) &&
  (@except ? !@except.call(member, ctx) : true)
end

#merge(only: nil, except: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
19
20
21
# File 'lib/graphql/filter.rb', line 16

def merge(only: nil, except: nil)
  onlies = [self].concat(Array(only))
  merged_only = MergedOnly.build(onlies)
  merged_except = MergedExcept.build(Array(except))
  self.class.new(only: merged_only, except: merged_except)
end