shopify_draft_proxy/graphql/parser

Mirrors graphql-js language/parser.ts, scoped to executable definitions (queries, mutations, subscriptions, fragments).

Schema-definition productions (SchemaDefinition, *TypeDefinition, *TypeExtension, DirectiveDefinition, SchemaCoordinate) and the legacy fragment-variables option are intentionally omitted — the proxy does not parse schema text or rely on those legacy modes.

graphql-js mutates Parser and Lexer instances. This port threads an immutable Parser value through every parsing function and uses Result rather than thrown errors. Each parse_* function takes the current parser, consumes some tokens, and returns the produced AST node plus the advanced parser.

Types

A parse-time error. Mirrors graphql-js GraphQLError for the parser.

pub type ParseError {
  ParseError(
    message: String,
    position: Int,
    line: Int,
    column: Int,
  )
}

Constructors

  • ParseError(
      message: String,
      position: Int,
      line: Int,
      column: Int,
    )

Immutable parser state. token is the current (lookahead) token; last_token is the most recently consumed token, and is used to compute the end of an AST node’s location range.

pub type Parser {
  Parser(
    lexer: lexer.Lexer,
    token: token.Token,
    last_token: token.Token,
  )
}

Constructors

Values

pub fn parse(
  source: source.Source,
) -> Result(ast.Document, ParseError)

Parse a Source containing an executable GraphQL document.

Search Document