shopify_draft_proxy/proxy/metafields

Mirrors the read path of src/proxy/metafields.ts.

This module carries the shared projection helpers (serializeMetafieldSelection*), compareDigest builder, and Shopify-like value normalization/jsonValue parsing used by owner-scoped metafield staging.

MetafieldRecordCore is the projection-shaped record. Mutation passes will likely wrap it in an owner-scoped variant; the read path here treats every metafield uniformly.

Types

Mirrors MetafieldRecordCore. Optional fields are present when the owning domain populates them (mutation-side); read paths from a snapshot may omit any of them. json_value is carried as Option(Json) so callers can pass through whatever shape the upstream record holds without us having to reify it.

pub type MetafieldRecordCore {
  MetafieldRecordCore(
    id: String,
    namespace: String,
    key: String,
    type_: option.Option(String),
    value: option.Option(String),
    compare_digest: option.Option(String),
    json_value: option.Option(json.Json),
    created_at: option.Option(String),
    updated_at: option.Option(String),
    owner_type: option.Option(String),
  )
}

Constructors

Values

pub fn make_metafield_compare_digest(
  metafield: MetafieldRecordCore,
) -> String

Build the compareDigest string for a metafield. Mirrors makeMetafieldCompareDigest.

The TS encodes JSON.stringify([namespace, key, type, value, jsonValue ?? null, updatedAt ?? null]) as base64url. We mirror that exactly: build a JSON array with the same six elements, render it to a string, then base64url-encode the bytes (no padding — Buffer.toString('base64url') strips it).

pub fn normalize_metafield_value(
  type_: option.Option(String),
  value: option.Option(String),
) -> option.Option(String)
pub fn parse_metafield_json_value(
  type_: option.Option(String),
  value: option.Option(String),
) -> option.Option(json.Json)
pub fn serialize_metafield_selection(
  metafield: MetafieldRecordCore,
  field: ast.Selection,
  options: graphql_helpers.SelectedFieldOptions,
) -> json.Json

Project a metafield against the child fields of a Field. Mirrors serializeMetafieldSelection.

pub fn serialize_metafield_selection_set(
  metafield: MetafieldRecordCore,
  selections: List(ast.Selection),
) -> json.Json

Project a metafield onto a list of selection nodes. Mirrors serializeMetafieldSelectionSet. Unknown fields fall through to null, matching the TS default branch. definition still returns null here because owner-specific callers handle definition-backed behavior at their own boundary.

pub fn serialize_metafields_connection(
  metafields: List(MetafieldRecordCore),
  field: ast.Selection,
  variables: dict.Dict(String, root_field.ResolvedValue),
  options: graphql_helpers.SelectedFieldOptions,
) -> json.Json

Serialize a metafields connection. Mirrors serializeMetafieldsConnection. Pagination uses the metafield’s id as the cursor source — same as the TS (metafield) => metafield.id.

Search Document