Class: GraphQL::Language::Parser
- Inherits:
-
Object
- Object
- GraphQL::Language::Parser
show all
- Includes:
- EmptyObjects, Nodes
- Defined in:
- lib/graphql/language/parser.rb
Defined Under Namespace
Classes: SchemaParser
Constant Summary
EmptyObjects::EMPTY_ARRAY, EmptyObjects::EMPTY_HASH
Constants included
from Nodes
Nodes::NONE
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(graphql_str, filename: nil, trace: Tracing::NullTrace, max_tokens: nil) ⇒ Parser
Returns a new instance of Parser.
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/graphql/language/parser.rb', line 33
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
@lines_at = nil
end
|
Class Attribute Details
.cache ⇒ Object
Returns the value of attribute cache.
16
17
18
|
# File 'lib/graphql/language/parser.rb', line 16
def cache
@cache
end
|
Class Method Details
.parse(graphql_str, filename: nil, trace: Tracing::NullTrace, max_tokens: nil) ⇒ Object
18
19
20
|
# File 'lib/graphql/language/parser.rb', line 18
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
22
23
24
25
26
27
28
29
30
|
# File 'lib/graphql/language/parser.rb', line 22
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
#column_at(pos) ⇒ Object
69
70
71
72
73
74
75
76
77
|
# File 'lib/graphql/language/parser.rb', line 69
def column_at(pos)
next_line_idx = lines_at.bsearch_index { |l| l >= pos } || @lines_at.size
line_start = next_line_idx == 0 ? 0 : @lines_at[next_line_idx - 1] + 1
if @graphql_str.ascii_only?
pos - line_start + 1
else
@graphql_str.byteslice(line_start, pos - line_start).force_encoding(Encoding::UTF_8).length + 1
end
end
|
#line_at(pos) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/graphql/language/parser.rb', line 60
def line_at(pos)
line = lines_at.bsearch_index { |l| l >= pos }
if line.nil?
@lines_at.size + 1
else
line + 1
end
end
|
#parse ⇒ Object
45
46
47
48
49
50
51
52
53
|
# File 'lib/graphql/language/parser.rb', line 45
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, @graphql_str, filename: @filename)
end
end
|
#tokens_count ⇒ Object
55
56
57
58
|
# File 'lib/graphql/language/parser.rb', line 55
def tokens_count
parse
@lexer.tokens_count
end
|