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
14
# File 'lib/graphql/filter.rb', line 7

def initialize(only: nil, except: nil, silence_deprecation_warning: false)
  if !silence_deprecation_warning
    line = caller(2, 10).find { |l| !l.include?("lib/graphql") }
    GraphQL::Deprecation.warn("GraphQL::Filter, `only:`, `except:`, and `.merge_filters` are deprecated and will be removed in v2.1.0. Implement `visible?` on your schema members instead (https://graphql-ruby.org/authorization/visibility.html).\n  #{line}")
  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



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

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.



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

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