Skip to Content
Composed Mode

Composed Client Mode

By default, Vovk.ts generates a single RPC client that aggregates all RPC modules from every segment. This approach—called the Composed Client—is useful for single-page applications where you want a single import entry point for all RPC modules across all segments. The files are emitted to the reconfigurable src/client folder (or client if the project has no src folder) and imported as @/client with the default Next.js path alias.

The structure of the src/client folder generated by the default ts template looks like this:

    • index.ts
    • schema.ts
    • openapi.ts
    • openapi.json

The generated client is derived from the committed schema and source code, so it doesn’t need to be committed itself: vovk init adds the output folder to .gitignore and sets up the prebuild: vovk generate NPM script that regenerates the client on every build.

The default generation can be reproduced with the CLI command:

npx vovk generate --from ts --out src/client

Composed Client Config

The composed client can be configured with the following options:

vovk.config.mjs
/** @type {import('vovk').VovkConfig} */ const config = { composedClient: { enabled: true, // default fromTemplates: ['ts'], // default outDir: './src/client', // default; './client' if there is no src folder includeSegments: ['foo'], // mutually exclusive with `excludeSegments` excludeSegments: ['bar'], // mutually exclusive with `includeSegments` }, }; export default config;

enabled

If set to false, the composed client will not be generated. Useful when you only want segmented clients.

fromTemplates

An array of templates used to generate the composed client. By default, ["ts"] produces TypeScript modules compiled together with the rest of your application. You can mix built-in templates and custom templates.

outDir

The path where the composed client is generated. Defaults to ./src/client when the project has a src folder, or ./client otherwise. The path is relative to the current working directory (CWD). If the folder already holds files under the generated names, such as a hand-written index.ts, generation stops and names them; see --force.

includeSegments

An array of segments to include in the composed client. By default, all segments are included. Use this to include only specific segments.

excludeSegments

An array of segments to exclude from the composed client. By default, none are excluded. This option is mutually exclusive with includeSegments.

prettifyClient

Whether to format the generated client code. Defaults to true. The Prettier  package resolved from your project is used with your local configuration; it’s not installed with the CLI. If Prettier is not installed, the CLI prints a warning and emits unformatted code—install Prettier or set prettifyClient to false to suppress the warning.

outputConfig

Overrides the root outputConfig options.

Last updated on