Skip to main content

ReSolve Context

TypeScript Support

A reSolve context object has an associated TypeScript type:

  • Type Name - UserBackendResolve
  • Package - @resolve-js/runtime-base

The resolve context object is available to an API handler function through its request (req) argument. This object implements a communication layer between an API handler and the reSolve framework.

The resolve context object exposes the following API:

Objectsā€‹

Field NameDescription
uploaderExposes the file upload API.
eventstoreAdapterExposes the event store adapter API.
performanceTracerExposes the performance tracer API.
monitoringExposes the monitoring API.

Methodsā€‹

Function NameDescription
executeCommandExecutes a command on the server side.
executeQueryQueries a read model or view model.

executeCommandā€‹

Executes a command on the server side.

Exampleā€‹

const myApiHandler = async (req, res) => {
const { resolve } = req
try {
const result = await resolve.executeCommand({
type: 'addItem',
aggregateName: 'MyItems',
aggregateId: uuid(),
payload: { name: itemName },
})
...
} catch (e) {
...
}
}

Argumentsā€‹

Argument NameTypeDescription
commandA command object.Describes a command to execute.

Resultā€‹

A promise that resolves to a command result object.

executeQueryā€‹

Exampleā€‹

const myApiHandler = async (req, res) => {
const { resolve } = req
try {
const result = await resolve.executeQuery({
modelName: 'MyList',
resolverName: 'all',
})
...
} catch (e) {
...
}
}

Argumentsā€‹

Argument NameTypeDescription
query A read model query or view model query object.Describes a query to execute.

Resultā€‹

A promise that resolves to a read model query result or view model query result depending on the query object's type.

Constantsā€‹

Constant NameTypeDescription
applicationNamestringThe reSolve application's name as specified in package.json.
distDirstringThe path to the WebPack dist directory within the application.
jwtCookieobjectAn object that contains JWT cookie settings as specified in the application configuration.
rootPathstringThe application's root URL path.
staticDirstringThe path to a directory that contains static files.
staticPathstringThe base URL path for static file URLs.