Skip to content

Latest commit

 

History

History
107 lines (80 loc) · 5.07 KB

resolve-context.md

File metadata and controls

107 lines (80 loc) · 5.07 KB
id title description
resolve-context
ReSolve Context
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.

:::info 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 Name Description
uploader Exposes the file upload API.
eventstoreAdapter Exposes the event store adapter API.
performanceTracer Exposes the performance tracer API.
monitoring Exposes the monitoring API.

Methods

Function Name Description
executeCommand Executes a command on the server side.
executeQuery Queries 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 Name Type Description
command A 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 Name Type Description
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 Name Type Description
applicationName string The reSolve application's name as specified in package.json.
distDir string The path to the WebPack dist directory within the application.
jwtCookie object An object that contains JWT cookie settings as specified in the application configuration.
rootPath string The application's root URL path.
staticDir string The path to a directory that contains static files.
staticPath string The base URL path for static file URLs.