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.
Class Method Summary collapse
-
.add_directive(schema_member, directives, directive_class, directive_options) ⇒ Object
private
-
.get_directives(schema_member, directives, directives_method) ⇒ Object
private
-
.remove_directive(directives, directive_class) ⇒ Object
private
Instance Method Summary collapse
-
#directive(dir_class, **options) ⇒ void
private
Create an instance of
dir_class
forself
, usingoptions
. -
#directives ⇒ Object
private
-
#inherited(child_cls) ⇒ Object
private
-
#remove_directive(dir_class) ⇒ viod
private
Remove an attached instance of
dir_class
, if there is one.
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.
41 42 43 44 |
# File 'lib/graphql/schema/member/has_directives.rb', line 41 def add_directive(schema_member, directives, directive_class, ) remove_directive(directives, directive_class) unless directive_class.repeatable? directives << directive_class.new(schema_member, **) 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.
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 82 83 84 85 86 87 88 89 |
# File 'lib/graphql/schema/member/has_directives.rb', line 50 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 GraphQL::EmptyObjects::EMPTY_ARRAY 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 GraphQL::EmptyObjects::EMPTY_ARRAY 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 || GraphQL::EmptyObjects::EMPTY_ARRAY when HasDirectives directives || GraphQL::EmptyObjects::EMPTY_ARRAY 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.
46 47 48 |
# File 'lib/graphql/schema/member/has_directives.rb', line 46 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.
22 23 24 25 26 |
# File 'lib/graphql/schema/member/has_directives.rb', line 22 def directive(dir_class, **) @own_directives ||= [] HasDirectives.add_directive(self, @own_directives, dir_class, ) nil end |
#directives ⇒ 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.
36 37 38 |
# File 'lib/graphql/schema/member/has_directives.rb', line 36 def directives HasDirectives.get_directives(self, @own_directives, :directives) end |
#inherited(child_cls) ⇒ 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.
12 13 14 15 |
# File 'lib/graphql/schema/member/has_directives.rb', line 12 def inherited(child_cls) super child_cls.own_directives = nil 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
31 32 33 34 |
# File 'lib/graphql/schema/member/has_directives.rb', line 31 def remove_directive(dir_class) HasDirectives.remove_directive(@own_directives, dir_class) nil end |