class GraphQL::Language::Parser
Attributes
Public Class Methods
# File lib/graphql/language/parser.rb, line 32 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
# File lib/graphql/language/parser.rb, line 17 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
# File lib/graphql/language/parser.rb, line 21 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
Public Instance Methods
Source
# File lib/graphql/language/parser.rb, line 68 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
Source
# File lib/graphql/language/parser.rb, line 59 def line_at(pos) line = lines_at.bsearch_index { |l| l >= pos } if line.nil? @lines_at.size + 1 else line + 1 end end
Source
# File lib/graphql/language/parser.rb, line 44 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
Source
# File lib/graphql/language/parser.rb, line 54 def tokens_count parse @lexer.tokens_count end