Class: GraphQL::Language::Nodes::Document

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

Overview

This is the AST root for normal queries

Examples:

Deriving a document by parsing a string

document = GraphQL.parse(query_string)

Creating a string from a document

document.to_query_string
# { ... }

Creating a custom string from a document

class VariableScrubber < GraphQL::Language::Printer
  def print_argument(arg)
    "#{arg.name}: <HIDDEN>"
  end
end

document.to_query_string(printer: VariableSrubber.new)

Instance Attribute Summary collapse

Attributes inherited from AbstractNode

#col, #filename, #line

Instance Method Summary collapse

Methods inherited from AbstractNode

#eql?, #initialize, #position, #scalars, #to_query_string

Constructor Details

This class inherits a constructor from GraphQL::Language::Nodes::AbstractNode

Instance Attribute Details

#definitionsArray<OperationDefinition, FragmentDefinition> Also known as: children

Returns top-level GraphQL units: operations or fragments.

Returns:



173
174
175
# File 'lib/graphql/language/nodes.rb', line 173

def definitions
  @definitions
end

Instance Method Details

#initialize_node(definitions: []) ⇒ Object



173
174
175
# File 'lib/graphql/language/nodes.rb', line 173

def initialize_node(definitions: [])
  @definitions = definitions
end

#slice_definition(name) ⇒ Object



177
178
179
# File 'lib/graphql/language/nodes.rb', line 177

def slice_definition(name)
  GraphQL::Language::DefinitionSlice.slice(self, name)
end