shopify_draft_proxy/graphql/root_field
Mirrors src/graphql/root-field.ts.
Helpers for pulling structured data out of a parsed operation: the
root Field node, its arguments resolved against a variable map,
and the names of its sub-selections.
ResolvedValue is the Gleam analogue of TypeScript’s unknown
here — a tagged union of the JSON-shaped values an argument can
take after variable substitution. The TS version returns
Record<string, unknown>, which the proxy then feeds straight into
endpoint handlers; this enum gives us the same coverage with
type safety.
Types
JSON-shaped value an argument resolves to once variables have been
substituted. Mirrors the unknown returned by
resolveValueNode in the TS version.
pub type ResolvedValue {
NullVal
StringVal(String)
BoolVal(Bool)
IntVal(Int)
FloatVal(Float)
ListVal(List(ResolvedValue))
ObjectVal(dict.Dict(String, ResolvedValue))
}
Constructors
-
NullVal -
StringVal(String) -
BoolVal(Bool) -
IntVal(Int) -
FloatVal(Float) -
ListVal(List(ResolvedValue)) -
ObjectVal(dict.Dict(String, ResolvedValue))
Errors root_field helpers can produce.
pub type RootFieldError {
ParseFailed(parser.ParseError)
NoOperationFound
NoRootField
InvalidNumberLiteral(String)
}
Constructors
-
ParseFailed(parser.ParseError) -
NoOperationFound -
NoRootField -
InvalidNumberLiteral(String)graphql-js silently allows
Number.parseInt("x")to return NaN, but the lexer guaranteesIntValue.valueis digits-only. If we somehow see a value that doesn’t parse, surface it explicitly rather than fabricating zero.
Values
pub fn get_field_arguments(
field: ast.Selection,
variables: dict.Dict(String, ResolvedValue),
) -> Result(dict.Dict(String, ResolvedValue), RootFieldError)
Resolve a single field’s argument list to a Dict keyed by argument
name. Variable references are looked up in variables; missing
variables resolve to NullVal (graphql-js’s ?? null).
pub fn get_root_field(
document: String,
) -> Result(ast.Selection, RootFieldError)
Return the first root Field selection of the document’s first
operation. Mirrors getRootField.
pub fn get_root_field_arguments(
document: String,
variables: dict.Dict(String, ResolvedValue),
) -> Result(dict.Dict(String, ResolvedValue), RootFieldError)
Convenience wrapper around get_root_field + get_field_arguments.
Mirrors getRootFieldArguments.
pub fn get_root_fields(
document: String,
) -> Result(List(ast.Selection), RootFieldError)
Return every root-level Field selection of the first operation.
Mirrors getRootFields. Fragment spreads / inline fragments are
dropped, matching the TS .filter(kind === Kind.FIELD).
pub fn get_selection_names(field: ast.Selection) -> List(String)
Names of the top-level field selections inside a Field’s
selection set. Mirrors getSelectionNames.
pub fn parse_operation_summary(
document: String,
) -> Result(
parse_operation.ParsedOperation,
parse_operation.ParseOperationError,
)
pub fn resolved_value_decoder() -> decode.Decoder(ResolvedValue)
pub fn resolved_value_to_json(value: ResolvedValue) -> json.Json