Class: GraphQL::Language::Parser

Inherits:
Object
  • Object
show all
Includes:
EmptyObjects, Nodes
Defined in:
lib/graphql/language/parser.rb

Constant Summary

Constants included from EmptyObjects

EmptyObjects::EMPTY_ARRAY, EmptyObjects::EMPTY_HASH

Constants included from Nodes

Nodes::NONE

Class Attribute Summary collapse

Attributes included from Nodes

#name

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graphql_str, filename: nil, trace: Tracing::NullTrace) ⇒ Parser

Returns a new instance of Parser.



30
31
32
33
34
35
36
37
38
# File 'lib/graphql/language/parser.rb', line 30

def initialize(graphql_str, filename: nil, trace: Tracing::NullTrace)
  if graphql_str.nil?
    raise GraphQL::ParseError.new("No query string was present", nil, nil, nil)
  end
  @lexer = Lexer.new(graphql_str, filename: filename)
  @graphql_str = graphql_str
  @filename = filename
  @trace = trace
end

Class Attribute Details

.cacheObject

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) ⇒ Object



15
16
17
# File 'lib/graphql/language/parser.rb', line 15

def parse(graphql_str, filename: nil, trace: Tracing::NullTrace)
  self.new(graphql_str, filename: filename, trace: trace).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

#parseObject



40
41
42
43
44
45
46
47
48
# File 'lib/graphql/language/parser.rb', line 40

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