Class: GraphQL::Language::Nodes::Document
- Inherits:
-
AbstractNode
- Object
- AbstractNode
- GraphQL::Language::Nodes::Document
- Defined in:
- lib/graphql/language/nodes.rb
Overview
This is the AST root for normal queries
Examples
Example: Deriving a document by parsing a string
document = GraphQL.parse(query_string)
Example: Creating a string from a document
document.to_query_string
# { ... }
Example: Creating a custom string from a document
class VariableScrubber < GraphQL::Language::Printer
def print_argument(arg)
print_string("#{arg.name}: <HIDDEN>")
end
end
document.to_query_string(printer: VariableScrubber.new)
Constant Summary
Constants inherited from AbstractNode
Instance Attribute Summary collapse
-
#definitions ⇒ Object
(also: #children)
readonly
Returns.
Attributes inherited from AbstractNode
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(definitions: NO_CHILDREN, line: nil, col: nil, pos: nil, filename: nil, source: nil) ⇒ Document
constructor
: (?definitions: Array, ?line: Integer?, ?col: Integer?, ?pos: Integer?, ?filename: String?, ?source: untyped) -> void.
- #marshal_dump ⇒ Object
- #marshal_load(values) ⇒ Object
- #slice_definition(name) ⇒ Object
- #visit_method ⇒ Object
Methods inherited from AbstractNode
#==, #children_method_name, children_of_type, #col, #definition_line, #delete_child, inherited, #initialize_copy, #line, #merge, #position, #replace_child, #scalars, #to_query_string
Constructor Details
#initialize(definitions: NO_CHILDREN, line: nil, col: nil, pos: nil, filename: nil, source: nil) ⇒ Document
: (?definitions: Array, ?line: Integer?, ?col: Integer?, ?pos: Integer?, ?filename: String?, ?source: untyped) -> void
1159 1160 1161 1162 1163 1164 1165 1166 |
# File 'lib/graphql/language/nodes.rb', line 1159 def initialize(definitions: NO_CHILDREN, line: nil, col: nil, pos: nil, filename: nil, source: nil) @line = line @col = col @pos = pos @filename = filename @source = source @definitions = definitions.freeze end |
Instance Attribute Details
#definitions ⇒ Object (readonly) Also known as: children
Returns
Array<OperationDefinition, FragmentDefinition, AbstractNode>— top-level GraphQL units: operations or fragments : Array
1154 1155 1156 |
# File 'lib/graphql/language/nodes.rb', line 1154 def definitions @definitions end |
Class Method Details
.from_a(filename, line, col, definitions, comment: nil) ⇒ Object
1168 1169 1170 |
# File 'lib/graphql/language/nodes.rb', line 1168 def self.from_a(filename, line, col, definitions, comment: nil) self.new(filename: filename, line: line, col: col, definitions: definitions) end |
Instance Method Details
#marshal_dump ⇒ Object
1172 1173 1174 1175 1176 1177 1178 |
# File 'lib/graphql/language/nodes.rb', line 1172 def marshal_dump [ line, col, # use methods here to force them to be calculated @filename, @definitions, ] end |
#marshal_load(values) ⇒ Object
1180 1181 1182 |
# File 'lib/graphql/language/nodes.rb', line 1180 def marshal_load(values) @line, @col, @filename, @definitions = values end |
#slice_definition(name) ⇒ Object
1188 1189 1190 |
# File 'lib/graphql/language/nodes.rb', line 1188 def slice_definition(name) GraphQL::Language::DefinitionSlice.slice(self, name) end |
#visit_method ⇒ Object
1146 1147 1148 |
# File 'lib/graphql/language/nodes.rb', line 1146 def visit_method :on_document end |