Class: GraphQL::Language::Nodes::Field

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

Overview

A single selection in a GraphQL query.

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, arguments: NONE, directives: NONE, selections: NONE, field_alias: nil, line: nil, col: nil, pos: nil, filename: nil, source: nil) ⇒ Field

: (?name: untyped, ?arguments: Array?, ?directives: Array?, ?selections: (Array[Field | FragmentSpread | InlineFragment])?, ?field_alias: String?, ?line: Integer?, ?col: Integer?, ?pos: Integer?, ?filename: String?, ?source: untyped) -> void



538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/graphql/language/nodes.rb', line 538

def initialize(name: nil, arguments: NONE, directives: NONE, selections: NONE, field_alias: nil, line: nil, col: nil, pos: nil, filename: nil, source: nil)
  @name = name
  @arguments = arguments || NONE
  @directives = directives || NONE
  @selections = selections || NONE
  # oops, alias is a keyword:
  @alias = field_alias
  @line = line
  @col = col
  @pos = pos
  @filename = filename
  @source = source
end

Instance Attribute Details

#alias ⇒ Object (readonly)

: String?



567
568
569
# File 'lib/graphql/language/nodes.rb', line 567

def alias
  @alias
end

#arguments ⇒ Object (readonly)

: Array



574
575
576
# File 'lib/graphql/language/nodes.rb', line 574

def arguments
  @arguments
end

#directives ⇒ Object (readonly)

: Array



578
579
580
# File 'lib/graphql/language/nodes.rb', line 578

def directives
  @directives
end

#name ⇒ Object (readonly)

: String



565
566
567
# File 'lib/graphql/language/nodes.rb', line 565

def name
  @name
end

#selections ⇒ Object (readonly)

: Array[Field | FragmentSpread | InlineFragment]



576
577
578
# File 'lib/graphql/language/nodes.rb', line 576

def selections
  @selections
end

Class Method Details

.from_a(filename, line, col, field_alias, name, arguments, directives, selections) ⇒ Object

rubocop:disable Metrics/ParameterLists



552
553
554
# File 'lib/graphql/language/nodes.rb', line 552

def self.from_a(filename, line, col, field_alias, name, arguments, directives, selections) # rubocop:disable Metrics/ParameterLists
  self.new(filename: filename, line: line, col: col, field_alias: field_alias, name: name, arguments: arguments, directives: directives, selections: selections)
end

Instance Method Details

#children ⇒ Object



592
593
594
595
596
597
598
599
600
601
602
603
604
605
# File 'lib/graphql/language/nodes.rb', line 592

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

#marshal_dump ⇒ Object



556
557
558
# File 'lib/graphql/language/nodes.rb', line 556

def marshal_dump
  [line, col, @filename, @name, @arguments, @directives, @selections, @alias]
end

#marshal_load(values) ⇒ Object



560
561
562
# File 'lib/graphql/language/nodes.rb', line 560

def marshal_load(values)
  @line, @col, @filename, @name, @arguments, @directives, @selections, @alias = values
end

#merge_argument(**node_opts) ⇒ Object



580
581
582
# File 'lib/graphql/language/nodes.rb', line 580

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

#merge_directive(**node_opts) ⇒ Object



588
589
590
# File 'lib/graphql/language/nodes.rb', line 588

def merge_directive(**node_opts)
  merge(directives: directives + [GraphQL::Language::Nodes::Directive.new(**node_opts)])
end

#merge_selection(**node_opts) ⇒ Object



584
585
586
# File 'lib/graphql/language/nodes.rb', line 584

def merge_selection(**node_opts)
  merge(selections: selections + [GraphQL::Language::Nodes::Field.new(**node_opts)])
end

#scalars ⇒ Object



569
570
571
# File 'lib/graphql/language/nodes.rb', line 569

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

#visit_method ⇒ Object



533
534
535
# File 'lib/graphql/language/nodes.rb', line 533

def visit_method
  :on_field
end