Class: GraphQL::Language::Nodes::FieldDefinition

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, #position, #replace_child, #to_query_string

Constructor Details

#initialize(name: nil, type: nil, description: nil, comment: nil, arguments: NO_CHILDREN, directives: NO_CHILDREN, line: nil, col: nil, pos: nil, filename: nil, source: nil, definition_pos: nil) ⇒ FieldDefinition

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



1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
# File 'lib/graphql/language/nodes.rb', line 1571

def initialize(name: nil, type: nil, description: nil, comment: nil, arguments: NO_CHILDREN, directives: 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
  @type = type
  @description = description && -description
  @comment = comment
  @arguments = arguments.freeze
  @directives = directives.freeze
  @definition_pos = definition_pos
end

Instance Attribute Details

#arguments ⇒ Object (readonly) Also known as: fields

: Array



1544
1545
1546
# File 'lib/graphql/language/nodes.rb', line 1544

def arguments
  @arguments
end

#comment ⇒ Object (readonly)

: String?



1533
1534
1535
# File 'lib/graphql/language/nodes.rb', line 1533

def comment
  @comment
end

#description ⇒ Object (readonly)

: String?



1531
1532
1533
# File 'lib/graphql/language/nodes.rb', line 1531

def description
  @description
end

#directives ⇒ Object (readonly)

: Array



1546
1547
1548
# File 'lib/graphql/language/nodes.rb', line 1546

def directives
  @directives
end

#name ⇒ Object (readonly)

: String



1535
1536
1537
# File 'lib/graphql/language/nodes.rb', line 1535

def name
  @name
end

#type ⇒ Object (readonly)

: TypeName | ListType | NonNullType



1537
1538
1539
# File 'lib/graphql/language/nodes.rb', line 1537

def type
  @type
end

Class Method Details

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

rubocop:disable Metrics/ParameterLists



1586
1587
1588
# File 'lib/graphql/language/nodes.rb', line 1586

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

Instance Method Details

#children ⇒ Object



1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
# File 'lib/graphql/language/nodes.rb', line 1556

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

#marshal_dump ⇒ Object



1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
# File 'lib/graphql/language/nodes.rb', line 1590

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

#marshal_load(values) ⇒ Object



1602
1603
1604
# File 'lib/graphql/language/nodes.rb', line 1602

def marshal_load(values)
  @line, @col, @filename, @name, @type, @description, @arguments, @directives = values
end

#merge(new_options) ⇒ Object



1615
1616
1617
1618
1619
1620
# File 'lib/graphql/language/nodes.rb', line 1615

def merge(new_options)
  if (f = new_options.delete(:fields))
    new_options[:arguments] = f
  end
  super
end

#merge_argument(**node_opts) ⇒ Object



1548
1549
1550
# File 'lib/graphql/language/nodes.rb', line 1548

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

#merge_directive(**node_opts) ⇒ Object



1552
1553
1554
# File 'lib/graphql/language/nodes.rb', line 1552

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

#scalars ⇒ Object



1539
1540
1541
# File 'lib/graphql/language/nodes.rb', line 1539

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

#visit_method ⇒ Object



1526
1527
1528
# File 'lib/graphql/language/nodes.rb', line 1526

def visit_method
  :on_field_definition
end