shopify_draft_proxy/proxy/saved_searches

Saved-search runtime implementation for the Gleam port.

Covers the connection-shaped *SavedSearches read pipeline, savedSearchCreate, savedSearchUpdate, savedSearchDelete, query grammar normalization, mutation-log drafts, and the static Shopify default order/draft-order saved searches. Live-hybrid upstream hydration remains outside the current Gleam substrate.

Types

Outcome of a saved-search mutation: a JSON data envelope plus the updated store and synthetic identity registry. Callers thread these forward.

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

Result of splitting a raw saved-search query string into the structured shape Shopify exposes on SavedSearch.

pub type ParsedSavedSearchQuery {
  ParsedSavedSearchQuery(
    filters: List(types.SavedSearchFilter),
    search_terms: String,
    canonical_query: String,
  )
}

Constructors

Errors specific to the saved-searches handler. Currently just surfaces upstream parse errors.

pub type SavedSearchesError {
  ParseFailed(root_field.RootFieldError)
}

Constructors

User-error payload emitted on validation failure. Mirrors the UserError shape in TS (field may be null).

pub type UserError {
  UserError(field: option.Option(List(String)), message: String)
}

Constructors

Values

pub fn draft_order_saved_searches() -> List(
  types.SavedSearchRecord,
)

Default saved searches for DRAFT_ORDER. Mirrors DRAFT_ORDER_SAVED_SEARCHES from proxy/orders/shared.ts.

pub fn handle_saved_search_query(
  store: store.Store,
  document: String,
  variables: dict.Dict(String, root_field.ResolvedValue),
) -> Result(json.Json, SavedSearchesError)

Process a saved-searches query document and return a JSON data envelope. Mirrors handleSavedSearchQuery. The Store argument supplies effective (base + staged) records; static defaults are merged in for resource types that have them.

pub fn is_saved_search_mutation_root(name: String) -> Bool

Predicate matching the three saved-search mutation roots.

pub fn is_saved_search_query_root(name: String) -> Bool

Predicate matching the TS isSavedSearchQueryRoot. Useful for the dispatcher when checking whether to delegate.

pub fn order_saved_searches() -> List(types.SavedSearchRecord)

Default saved searches for ORDER. Mirrors ORDER_SAVED_SEARCHES.

pub fn parse_saved_search_query(
  raw_query: String,
) -> ParsedSavedSearchQuery

Mirrors parseSavedSearchQuery in src/proxy/saved-searches.ts. Splits a raw query into top-level tokens, classifies each as filter vs search-term, and recomputes the canonical stored shape (<terms> <filters>).

pub fn process(
  store: store.Store,
  document: String,
  variables: dict.Dict(String, root_field.ResolvedValue),
) -> Result(json.Json, SavedSearchesError)

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, SavedSearchesError)

Process a saved-search mutation document. Currently only savedSearchCreate is implemented; other root fields produce a MutationNotImplemented error.

pub fn root_field_resource_type(
  name: String,
) -> Result(String, Nil)

Map from saved-search root field name to the resource type the store keys defaults under. Mirrors SAVED_SEARCH_ROOT_RESOURCE_TYPES.

pub fn saved_search_cursor(
  record: types.SavedSearchRecord,
) -> String

Build the synthetic cursor for a saved-search record. Exposed for tests.

pub fn wrap_data(data: json.Json) -> json.Json

Wrap a successful saved-searches response in the standard GraphQL envelope.

Search Document