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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_directive(schema_member, directives, directive_class, directive_options) ⇒ 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.



33
34
35
36
# File 'lib/graphql/schema/member/has_directives.rb', line 33

def add_directive(schema_member, directives, directive_class, directive_options)
  remove_directive(directives, directive_class) unless directive_class.repeatable?
  directives << directive_class.new(schema_member, **directive_options)
end

.get_directives(schema_member, directives, directives_method) ⇒ 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.



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
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/graphql/schema/member/has_directives.rb', line 42

def get_directives(schema_member, directives, directives_method)
  case schema_member
  when Class
    inherited_directives = if schema_member.superclass.respond_to?(directives_method)
      get_directives(schema_member.superclass, schema_member.superclass.public_send(directives_method), directives_method)
    else
      NO_DIRECTIVES
    end
    if inherited_directives.any? && directives
      dirs = []
      merge_directives(dirs, inherited_directives)
      merge_directives(dirs, directives)
      dirs
    elsif directives
      directives
    elsif inherited_directives.any?
      inherited_directives
    else
      NO_DIRECTIVES
    end
  when Module
    dirs = nil
    schema_member.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 directives
      dirs ||= []
      merge_directives(dirs, directives)
    end
    dirs || NO_DIRECTIVES
  when HasDirectives
    directives || NO_DIRECTIVES
  else
    raise "Invariant: how could #{schema_member} not be a Class, Module, or instance of HasDirectives?"
  end
end

.remove_directive(directives, directive_class) ⇒ 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.



38
39
40
# File 'lib/graphql/schema/member/has_directives.rb', line 38

def remove_directive(directives, directive_class)
  directives && directives.reject! { |d| d.is_a?(directive_class) }
end

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
# File 'lib/graphql/schema/member/has_directives.rb', line 12

def directive(dir_class, **options)
  @own_directives ||= []
  HasDirectives.add_directive(self, @own_directives, dir_class, 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.



28
29
30
# File 'lib/graphql/schema/member/has_directives.rb', line 28

def directives
  HasDirectives.get_directives(self, @own_directives, :directives)
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)


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

def remove_directive(dir_class)
  HasDirectives.remove_directive(@own_directives, dir_class)
  nil
end