shopify_draft_proxy/graphql/location

Mirrors graphql-js language/location.ts.

Computes the (line, column) for a UTF-8 character offset within a Source body. line and column are 1-indexed.

Position semantics: graphql-js counts JS string positions (UTF-16 code units). Gleam strings are UTF-8 graphemes, so this implementation counts Unicode code points. For the BMP characters that real Shopify queries use this matches graphql-js exactly; supplementary-plane characters (very rare in GraphQL source) would diverge by one position per surrogate pair, and that gap is acceptable for the proxy use case.

Types

1-indexed line/column position inside a Source.body.

pub type SourceLocation {
  SourceLocation(line: Int, column: Int)
}

Constructors

  • SourceLocation(line: Int, column: Int)

Values

pub fn get_location(
  source: source.Source,
  position position: Int,
) -> SourceLocation

Translate a 0-indexed code point offset in source.body into a 1-indexed line and column. Matches graphql-js’s getLocation.

Search Document