Skip to main content
Version: Next

Function: query()

query(fn, config?): Query

Creates a Query definition.

Queries are server-side read-only operations. They can be invoked from the client (with caching via useQuery) and the server. List the entities the query reads from so Wasp can inject the matching Prisma delegates into context.entities and invalidate the client cache when related actions modify them.

See Queries.

Parameters

fn

Reference<AnyFunction>

The Query's NodeJS implementation.

config?

Optional settings: entities and auth.

auth?

boolean

If true, the query 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 query reads from. Wasp injects a Prisma delegate for each one into the query's context.entities, and uses the list to invalidate the client-side cache when related actions run.

Returns

Query

Example

import { query } from '@wasp.sh/spec'
import { getTasks } from './src/queries' with { type: 'ref' }

query(getTasks, { entities: ['Task'] })