Skip to main content
Version: Next

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>

The Action's NodeJS implementation.

config?

Optional settings: entities and auth.

auth?

boolean

If true, the action receives context.user. Defaults to true when the app has auth enabled, and false otherwise.

You can only set this field when app-level auth is enabled.

entities?

string[]

Entities the action operates on. Wasp injects a Prisma delegate for each one into the action's context.entities, and uses the list to invalidate the related query caches on the client.

Returns

Action

Example

import { action } from '@wasp.sh/spec'
import { createTask } from './src/actions' with { type: 'ref' }

action(createTask, { entities: ['Task'] })