Module: GraphQL::Schema::Member::HasDirectives Private

Included in:
Argument, EnumValue, Field, Interface::DefinitionMethods, GraphQL::Schema::Member
Defined in:
lib/graphql/schema/member/has_directives.rb

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

Constant Summary collapse

NO_DIRECTIVES =

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

[].freeze

Instance Method Summary collapse

Instance Method Details

#directive(dir_class, **options) ⇒ void

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.

This method returns an undefined value.

Create an instance of dir_class for self, using options.

It removes a previously-attached instance of dir_class, if there is one.



12
13
14
15
16
17
# File 'lib/graphql/schema/member/has_directives.rb', line 12

def directive(dir_class, **options)
  @own_directives ||= []
  remove_directive(dir_class)
  @own_directives << dir_class.new(self, **options)
  nil
end

#directivesObject

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.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/graphql/schema/member/has_directives.rb', line 29

def directives
  case self
  when Class
    inherited_directives = if superclass.respond_to?(:directives)
      superclass.directives
    else
      NO_DIRECTIVES
    end
    if inherited_directives.any? && @own_directives
      dirs = []
      merge_directives(dirs, inherited_directives)
      merge_directives(dirs, @own_directives)
      dirs
    elsif @own_directives
      @own_directives
    elsif inherited_directives.any?
      inherited_directives
    else
      NO_DIRECTIVES
    end
  when Module
    dirs = nil
    self.ancestors.reverse_each do |ancestor|
      if ancestor.respond_to?(:own_directives) &&
          (anc_dirs = ancestor.own_directives).any?
        dirs ||= []
        merge_directives(dirs, anc_dirs)
      end
    end
    if own_directives
      dirs ||= []
      merge_directives(dirs, own_directives)
    end
    dirs || NO_DIRECTIVES
  when HasDirectives
    @own_directives || NO_DIRECTIVES
  else
    raise "Invariant: how could #{self} not be a Class, Module, or instance of HasDirectives?"
  end
end

#remove_directive(dir_class) ⇒ viod

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.

Remove an attached instance of dir_class, if there is one

Parameters:

Returns:

  • (viod)


22
23
24
25
# File 'lib/graphql/schema/member/has_directives.rb', line 22

def remove_directive(dir_class)
  @own_directives && @own_directives.reject! { |d| d.is_a?(dir_class) }
  nil
end