shopify_draft_proxy/proxy/functions
Mirrors src/proxy/functions.ts.
Pass 18 ships the five query roots (validation, validations,
cartTransforms, shopifyFunction, shopifyFunctions) plus the six
mutation roots (validationCreate/Update/Delete,
cartTransformCreate/Delete, taxAppConfigure).
The TS handler implicitly hydrates a ShopifyFunctionRecord whenever
a validation or cart-transform mutation references one — either by
id, by handle, or by minting a fresh synthetic gid. Mirrored here as
ensure_shopify_function. The mutation pipeline returns a
MutationOutcome carrying the updated store + identity registry +
staged GIDs, matching the apps/webhooks/saved-search shape.
Types
Errors specific to the functions handler. Mirrors AppsError.
pub type FunctionsError {
ParseFailed(root_field.RootFieldError)
}
Constructors
-
ParseFailed(root_field.RootFieldError)
Outcome of a functions mutation. Same shape as the apps / webhooks / saved-search outcome record.
pub type MutationOutcome {
MutationOutcome(
data: json.Json,
store: store.Store,
identity: synthetic_identity.SyntheticIdentityRegistry,
staged_resource_ids: List(String),
log_drafts: List(mutation_helpers.LogDraft),
)
}
Constructors
-
MutationOutcome( data: json.Json, store: store.Store, identity: synthetic_identity.SyntheticIdentityRegistry, staged_resource_ids: List(String), log_drafts: List(mutation_helpers.LogDraft), )
User-error payload. Mirrors the TS FunctionUserError shape (path,
message, optional code).
pub type UserError {
UserError(
field: List(String),
message: String,
code: option.Option(String),
)
}
Constructors
-
UserError( field: List(String), message: String, code: option.Option(String), )
Values
pub fn handle_function_query(
store: store.Store,
document: String,
variables: dict.Dict(String, root_field.ResolvedValue),
) -> Result(json.Json, FunctionsError)
Process a functions query document and return a JSON data
envelope. Mirrors handleFunctionQuery.
pub fn handle_query_request(
proxy: proxy_state.DraftProxy,
request: proxy_state.Request,
parsed: parse_operation.ParsedOperation,
primary_root_field: String,
document: String,
variables: dict.Dict(String, root_field.ResolvedValue),
) -> #(proxy_state.Response, proxy_state.DraftProxy)
pub fn is_function_mutation_root(name: String) -> Bool
Predicate matching the TS FUNCTION_MUTATION_ROOTS set.
pub fn is_function_query_root(name: String) -> Bool
Predicate matching the TS FUNCTION_QUERY_ROOTS set.
pub fn local_has_function_metadata(
proxy: proxy_state.DraftProxy,
) -> Bool
True when functions-domain reads need local handling because the proxy already knows about function metadata or staged lifecycle effects. In LiveHybrid, cold reads can be forwarded upstream verbatim; once any local function metadata exists, reads must stay local so staged Validation / CartTransform state remains visible.
pub fn normalize_function_handle(handle: String) -> String
Mirror normalizeFunctionHandle. Lowercases, trims, replaces runs of
disallowed characters with -, strips leading/trailing -, and
returns local-function if the result is empty.
pub fn process(
store: store.Store,
document: String,
variables: dict.Dict(String, root_field.ResolvedValue),
) -> Result(json.Json, FunctionsError)
Convenience: parse + handle + wrap, for the dispatcher.
pub fn process_mutation(
store: store.Store,
identity: synthetic_identity.SyntheticIdentityRegistry,
request_path: String,
document: String,
variables: dict.Dict(String, root_field.ResolvedValue),
) -> Result(MutationOutcome, FunctionsError)
Process a functions mutation document. Mirrors
handleFunctionMutation.
pub fn process_mutation_with_upstream(
store: store.Store,
identity: synthetic_identity.SyntheticIdentityRegistry,
request_path: String,
document: String,
variables: dict.Dict(String, root_field.ResolvedValue),
upstream: upstream_query.UpstreamContext,
) -> Result(MutationOutcome, FunctionsError)
Pattern 2: dispatched LiveHybrid function metadata mutations first try to hydrate referenced ShopifyFunction owner/app metadata from upstream, then stage the mutation locally. Snapshot/no-transport paths fall back to the existing local synthetic Function record.
pub fn shopify_function_id_from_handle(handle: String) -> String
Build a deterministic ShopifyFunction gid from a handle. Mirrors
shopifyFunctionIdFromHandle.
pub fn title_from_handle(handle: String) -> String
Convert a handle to a human-readable title. Mirrors titleFromHandle
— splits on -, _, and whitespace; drops empty segments;
title-cases each segment; joins with a single space.