Class: Tina4::GraphQLParser

Inherits:
Object
  • Object
show all
Defined in:
lib/tina4/graphql.rb

Overview

─── Parser (recursive descent) ──────────────────────────────────────

Defined Under Namespace

Classes: Token

Constant Summary collapse

KEYWORDS =
%w[query mutation fragment on true false null].freeze

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ GraphQLParser

Returns a new instance of GraphQLParser.



211
212
213
214
215
# File 'lib/tina4/graphql.rb', line 211

def initialize(source)
  @source = source
  @tokens = tokenize(source)
  @pos = 0
end

Instance Method Details

#parseObject



217
218
219
220
221
222
223
224
225
# File 'lib/tina4/graphql.rb', line 217

def parse
  document = { kind: :document, definitions: [] }
  while current
    skip(:comma)
    break unless current
    document[:definitions] << parse_definition
  end
  document
end