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, silence_deprecation_warning: false) ⇒ 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.



7
8
9
10
11
12
13
# File 'lib/graphql/filter.rb', line 7

def initialize(only: nil, except: nil, silence_deprecation_warning: false)
  if !silence_deprecation_warning
    GraphQL::Deprecation.warn("GraphQL::Filter is deprecated and will be removed in v2.1.0. Implement `visible?` on your schema members instead (https://graphql-ruby.org/authorization/visibility.html).")
  end
  @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



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

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.



21
22
23
24
25
26
# File 'lib/graphql/filter.rb', line 21

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, silence_deprecation_warning: true)
end