Class: GraphQL::Language::Parser
- Inherits:
-
Object
- Object
- GraphQL::Language::Parser
- Includes:
- EmptyObjects, Nodes
- Defined in:
- lib/graphql/language/parser.rb
Direct Known Subclasses
Defined Under Namespace
Classes: SchemaParser
Constant Summary
Constants included from EmptyObjects
EmptyObjects::EMPTY_ARRAY, EmptyObjects::EMPTY_HASH
Constants included from Nodes
Class Attribute Summary collapse
-
.cache ⇒ Object
Returns the value of attribute cache.
Attributes included from Nodes
Class Method Summary collapse
-
.parse(graphql_str, filename: nil, trace: Tracing::NullTrace, max_tokens: nil) ⇒ Object
-
.parse_file(filename, trace: Tracing::NullTrace) ⇒ Object
Instance Method Summary collapse
-
#initialize(graphql_str, filename: nil, trace: Tracing::NullTrace, max_tokens: nil) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Object
Constructor Details
#initialize(graphql_str, filename: nil, trace: Tracing::NullTrace, max_tokens: nil) ⇒ Parser
Returns a new instance of Parser.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/graphql/language/parser.rb', line 30 def initialize(graphql_str, filename: nil, trace: Tracing::NullTrace, max_tokens: nil) if graphql_str.nil? raise GraphQL::ParseError.new("No query string was present", nil, nil, nil) end @lexer = Lexer.new(graphql_str, filename: filename, max_tokens: max_tokens) @graphql_str = graphql_str @filename = filename @trace = trace @dedup_identifiers = false end |
Class Attribute Details
.cache ⇒ Object
Returns the value of attribute cache.
13 14 15 |
# File 'lib/graphql/language/parser.rb', line 13 def cache @cache end |
Class Method Details
.parse(graphql_str, filename: nil, trace: Tracing::NullTrace, max_tokens: nil) ⇒ Object
15 16 17 |
# File 'lib/graphql/language/parser.rb', line 15 def parse(graphql_str, filename: nil, trace: Tracing::NullTrace, max_tokens: nil) self.new(graphql_str, filename: filename, trace: trace, max_tokens: max_tokens).parse end |
.parse_file(filename, trace: Tracing::NullTrace) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/graphql/language/parser.rb', line 19 def parse_file(filename, trace: Tracing::NullTrace) if cache cache.fetch(filename) do parse(File.read(filename), filename: filename, trace: trace) end else parse(File.read(filename), filename: filename, trace: trace) end end |
Instance Method Details
#parse ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/graphql/language/parser.rb', line 41 def parse @document ||= begin @trace.parse(query_string: @graphql_str) do document end rescue SystemStackError raise GraphQL::ParseError.new("This query is too large to execute.", nil, nil, @query_str, filename: @filename) end end |