shopify_draft_proxy/proxy/proxy_state

Long-lived runtime state types for the Gleam proxy port.

DraftProxy and its companion types (Config, ReadMode) live in this module rather than draft_proxy.gleam so domain modules (customers, products, …) can take DraftProxy as a parameter without importing draft_proxy.gleam and creating an import cycle.

draft_proxy.gleam re-exports these types via type aliases plus thin delegating constructors so existing public callers (draft_proxy.new(), draft_proxy.with_config(...), etc.) keep compiling unchanged.

Types

Sanitised configuration the proxy was constructed with. Mirrors the fields of AppConfig that surface through GET /__meta/config.

pub type Config {
  Config(
    read_mode: ReadMode,
    port: Int,
    shopify_admin_origin: String,
    snapshot_path: option.Option(String),
  )
}

Constructors

  • Config(
      read_mode: ReadMode,
      port: Int,
      shopify_admin_origin: String,
      snapshot_path: option.Option(String),
    )

Long-lived runtime state owned by the proxy. The TS class wraps this in a stateful DraftProxy; here it’s just a record threaded through each request.

pub type DraftProxy {
  DraftProxy(
    config: Config,
    synthetic_identity: synthetic_identity.SyntheticIdentityRegistry,
    store: store.Store,
    registry: List(operation_registry.RegistryEntry),
    upstream_transport: option.Option(
      upstream_client.SyncTransport,
    ),
  )
}

Constructors

  • DraftProxy(
      config: Config,
      synthetic_identity: synthetic_identity.SyntheticIdentityRegistry,
      store: store.Store,
      registry: List(operation_registry.RegistryEntry),
      upstream_transport: option.Option(upstream_client.SyncTransport),
    )

    Arguments

    registry

    Registry-driven dispatch table. Empty by default — when empty, the dispatcher falls back to the hardcoded domain_for predicates (matches Pass 1–7 behavior so existing tests keep working). Load via with_registry once a real config is available.

    upstream_transport

    Optional injected transport for upstream calls. When set, every upstream call (passthrough + handler-issued reads via proxy/upstream_query) is routed through it instead of the default upstream_client.send_sync/send_async shims. Parity tests install a cassette here; production leaves it None and hits real Shopify.

How the proxy answers reads. Mirrors the TS AppConfig['readMode']. Only the variants actually exercised by the spike are modelled; any extension to TS will need a corresponding variant here.

pub type ReadMode {
  Snapshot
  LiveHybrid
  Live
}

Constructors

  • Snapshot
  • LiveHybrid
  • Live

HTTP-shaped request the proxy accepts. Mirrors DraftProxyRequest in the TS port. Lives here (alongside DraftProxy) rather than in draft_proxy.gleam so domain handlers can take a Request as a parameter without importing draft_proxy and creating a cycle.

pub type Request {
  Request(
    method: String,
    path: String,
    headers: dict.Dict(String, String),
    body: String,
  )
}

Constructors

  • Request(
      method: String,
      path: String,
      headers: dict.Dict(String, String),
      body: String,
    )

HTTP-shaped response. Mirrors DraftProxyHttpResponse. The body is pre-serialized as a JSON tree so callers can json.to_string it without re-encoding.

pub type Response {
  Response(
    status: Int,
    body: json.Json,
    headers: List(#(String, String)),
  )
}

Constructors

  • Response(
      status: Int,
      body: json.Json,
      headers: List(#(String, String)),
    )

Values

pub fn default_config() -> Config

Default config, mirroring the values the TS test suite uses when no explicit config is supplied.

pub fn new() -> DraftProxy

Fresh proxy with default config. Equivalent to new DraftProxy(...).

pub fn with_config(config: Config) -> DraftProxy

Fresh proxy with the supplied config.

pub fn with_default_registry(proxy: DraftProxy) -> DraftProxy

Attach the vendored default registry built from config/operation-registry.json.

pub fn with_registry(
  proxy: DraftProxy,
  registry: List(operation_registry.RegistryEntry),
) -> DraftProxy

Attach a parsed operation registry to the proxy. Once attached, query/mutation dispatch routes by capability instead of the hardcoded predicates. Mirrors the dispatcher transition the TS proxy made when operation-registry.json started driving routes.ts.

pub fn with_upstream_transport(
  proxy: DraftProxy,
  transport: upstream_client.SyncTransport,
) -> DraftProxy

Install an injected upstream transport. Used by the parity runner to wire a recorded cassette into the proxy; production callers leave this unset.

Search Document