References
The fully typed worker API — this.ctx.props and everything around it
This page is the authoritative reference for the API surface available inside your workers — the same surface the code editor autocompletes, hovers, and lints against.
The authoring model
You write the body of the worker’s fetch handler, not a whole module. At deploy time your code is wrapped in a class extending Cloudflare’s WorkerEntrypoint, so inside your code:
request— the incomingRequest, in scope as the fetch handler’s parameter.this— the worker instance (aWorkerEntrypointsubclass).this.ctx— the execution context, carryingthis.ctx.props.this.env— present but empty: user workers hold no bindings. Capabilities arrive exclusively throughthis.ctx.props.
Whatever your code returns must be a Response (or a promise of one) — it becomes the HTTP response to the caller.
Type definitions
// The execution context available as `this.ctx`.
// (Only these members are part of Bound's documented surface.)
interface ExecutionContext {
/** Capabilities the dispatcher provides to this worker. */
readonly props: WorkerProps;
/** Keeps the worker alive until the promise settles —
* for work that should finish after the response is sent. */
waitUntil(promise: Promise<unknown>): void;
/** Passes exceptions through instead of turning them into 500 responses. */
passThroughOnException(): void;
}
// `this.ctx.props` — the capabilities provided to this worker.
interface WorkerProps {
/** Secrets enabled for this worker, keyed by name. */
secrets: { [name: string]: string };
/** Shopify Admin GraphQL client — authenticated by the dispatcher,
* so no credentials cross into worker code. */
admin: AdminGraphQL;
/** Shopify Storefront GraphQL client — authenticated by the dispatcher. */
storefront: StorefrontGraphQL;
}
interface AdminGraphQL {
/** Runs an Admin API GraphQL query against this worker's pinned API
* version and resolves with the parsed JSON response.
* Throws a ShopifyApiError when the API responds non-2xx. */
query(
query: string,
variables?: Record<string, unknown>,
): Promise<GraphQLResponse>;
}
interface StorefrontGraphQL {
/** Runs a Storefront API GraphQL query against this worker's pinned API
* version and resolves with the parsed JSON response.
* Throws a ShopifyApiError when the API responds non-2xx. */
query(
query: string,
variables?: Record<string, unknown>,
): Promise<GraphQLResponse>;
}
// The parsed Shopify GraphQL JSON body, passed through verbatim.
type GraphQLResponse = {
data?: Record<string, unknown> | null;
errors?: { message: string; [key: string]: unknown }[];
extensions?: Record<string, unknown>;
} | null;
// Thrown when Shopify responds with a non-2xx HTTP status.
class ShopifyApiError extends Error {
/** The HTTP status of the failed Shopify API response. */
status: number;
} Error semantics
- Non-2xx HTTP responses throw a
ShopifyApiError. Itsmessageembeds the status and stringified response body;statuscarries the HTTP status. - GraphQL errors inside a 200 response do not throw. A response with an
errorsarray — or mutationuserErrors— resolves like any other result. Check them yourself. - Misconfiguration throws plain
Errors — for example if the shop’s Storefront token hasn’t been provisioned yet (“Storefront API is not configured for this shop”). - Your own unhandled throws propagate to the caller as an opaque
500 Internal Server Errorwith no detail — return error detail in the response yourself while debugging.
How the editor types secrets
The code editor tracks your shop’s secrets and this worker’s enabled list, and types this.ctx.props.secrets accordingly:
- Enabled secret —
NAME: string, available at runtime. - Exists but not enabled — flagged: the secret “isn’t enabled for this worker — enable it in the Secrets section below.”
- Unknown name — flagged: “create it from the Secrets page.”
- Enabled but never referenced — flagged, so allowlists stay minimal.
The editor reads your code’s syntax tree, so mentions inside comments and strings don’t count as usage (the worker page’s “Unused secrets” banner uses a looser textual match and is advisory).
Both this.ctx.props.secrets.NAME and this.ctx.props.secrets["NAME"] forms are understood by the linter.
Limits
- CPU: 30 seconds per invocation (uniform across plans).
- Flow responses: bodies returned to Shopify Flow are truncated at 45 KB.
- Monthly runs: bounded by your plan — see Support & Plans.