Class: GraphQL::Language::Nodes::DirectiveDefinition

Inherits:
AbstractNode
  • Object
show all
Defined in:
lib/graphql/language/nodes.rb

Constant Summary

Constants inherited from AbstractNode

AbstractNode::NO_CHILDREN

Instance Attribute Summary collapse

Attributes inherited from AbstractNode

#filename

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractNode

#==, #children_method_name, children_of_type, #col, #definition_line, #delete_child, inherited, #initialize_copy, #line, #merge, #position, #replace_child, #to_query_string

Constructor Details

#initialize(name: nil, repeatable: nil, description: nil, arguments: NO_CHILDREN, locations: NO_CHILDREN, line: nil, col: nil, pos: nil, filename: nil, source: nil, definition_pos: nil) ⇒ DirectiveDefinition

: (?name: untyped, ?repeatable: untyped, ?description: untyped, ?arguments: Array, ?locations: Array, ?line: Integer?, ?col: Integer?, ?pos: Integer?, ?filename: String?, ?source: untyped, ?definition_pos: Integer?) -> void



476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/graphql/language/nodes.rb', line 476

def initialize(name: nil, repeatable: nil, description: nil, arguments: NO_CHILDREN, locations: NO_CHILDREN, line: nil, col: nil, pos: nil, filename: nil, source: nil, definition_pos: nil)
  @line = line
  @col = col
  @pos = pos
  @filename = filename
  @source = source
  @name = name
  @repeatable = repeatable
  @description = description && -description
  @arguments = arguments.freeze
  @locations = locations.freeze
  @definition_pos = definition_pos
end

Instance Attribute Details

#arguments ⇒ Object (readonly)

: Array



449
450
451
# File 'lib/graphql/language/nodes.rb', line 449

def arguments
  @arguments
end

#description ⇒ Object (readonly)

: String?



438
439
440
# File 'lib/graphql/language/nodes.rb', line 438

def description
  @description
end

#locations ⇒ Object (readonly)

: Array



451
452
453
# File 'lib/graphql/language/nodes.rb', line 451

def locations
  @locations
end

#name ⇒ Object (readonly)

: String



440
441
442
# File 'lib/graphql/language/nodes.rb', line 440

def name
  @name
end

#repeatable ⇒ Object (readonly)

: bool



442
443
444
# File 'lib/graphql/language/nodes.rb', line 442

def repeatable
  @repeatable
end

Class Method Details

.from_a(filename, line, col, name, repeatable, description, arguments, locations, comment: nil) ⇒ Object

rubocop:disable Metrics/ParameterLists



490
491
492
# File 'lib/graphql/language/nodes.rb', line 490

def self.from_a(filename, line, col, name, repeatable, description, arguments, locations, comment: nil) # rubocop:disable Metrics/ParameterLists
  self.new(filename: filename, line: line, col: col, name: name, repeatable: repeatable, description: description, arguments: arguments, locations: locations)
end

Instance Method Details

#children ⇒ Object



461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/graphql/language/nodes.rb', line 461

def children
  @children ||= begin
    if !@arguments.empty? || !@locations.empty?
      new_children = []
      new_children.concat(@arguments)
      new_children.concat(@locations)
      new_children.freeze
      new_children
    else
      NO_CHILDREN
    end
  end
end

#marshal_dump ⇒ Object



494
495
496
497
498
499
500
501
502
503
504
# File 'lib/graphql/language/nodes.rb', line 494

def marshal_dump
  [
    line, col, # use methods here to force them to be calculated
    @filename,
    @name,
    @repeatable,
    @description,
    @arguments,
    @locations,
  ]
end

#marshal_load(values) ⇒ Object



506
507
508
# File 'lib/graphql/language/nodes.rb', line 506

def marshal_load(values)
  @line, @col, @filename, @name, @repeatable, @description, @arguments, @locations = values
end

#merge_argument(**node_opts) ⇒ Object



453
454
455
# File 'lib/graphql/language/nodes.rb', line 453

def merge_argument(**node_opts)
  merge(arguments: arguments + [GraphQL::Language::Nodes::Argument.new(**node_opts)])
end

#merge_location(**node_opts) ⇒ Object



457
458
459
# File 'lib/graphql/language/nodes.rb', line 457

def merge_location(**node_opts)
  merge(locations: locations + [GraphQL::Language::Nodes::DirectiveLocation.new(**node_opts)])
end

#scalars ⇒ Object



444
445
446
# File 'lib/graphql/language/nodes.rb', line 444

def scalars
  @scalars ||= [@name, @repeatable].freeze
end

#visit_method ⇒ Object



433
434
435
# File 'lib/graphql/language/nodes.rb', line 433

def visit_method
  :on_directive_definition
end