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.



208
209
210
211
212
# File 'lib/tina4/graphql.rb', line 208

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

Instance Method Details

#parseObject



214
215
216
217
218
219
220
221
222
# File 'lib/tina4/graphql.rb', line 214

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