Skip to main content
Version: 0.24

Function: action()

action(fn, config?): Action

Creates an Action definition.

Actions are server-side write operations. Like queries, they can be called from the client and the server. Listing entities in config.entities lets Wasp invalidate related query caches when this action runs.

See Actions.

Parametersโ€‹

fnโ€‹

Reference<AnyFunction>

Reference to the Action's NodeJS implementation.

See the docs for details on the implementation and its context.

Use reference imports when passing values from your app into the Wasp spec. If a direct import is not practical, use ref as a fallback.

config?โ€‹

auth?โ€‹

boolean

Whether this Action requires auth. If your app has auth enabled, this defaults to true.

Only available if your app has auth enabled.

entities?โ€‹

string[]

A list of entities you wish to use inside your Action.

See Using Entities in Actions.

Returnsโ€‹

Action

Exampleโ€‹

import { app, action } from "@wasp.sh/spec"
import { createTask } from "./src/actions" with { type: "ref" }
export default app({
// ...
spec: [
action(createTask, { entities: ["Task"] }),
],
})