Skip to main content

Function: writeQuery()

writeQuery(directory): (query, options) => Promise<void>

Defined in: queries.ts:94

Write a query to EventCatalog.

You can optionally override the path of the query.

Parameters

ParameterType
directorystring

Returns

Function

Parameters

ParameterType
queryQuery
options{ format: "md" | "mdx"; override: boolean; path: string; versionExistingContent: boolean; }
options.format?"md" | "mdx"
options.override?boolean
options.path?string
options.versionExistingContent?boolean

Returns

Promise<void>

Example

import utils from '@eventcatalog/utils';

const { writeQuery } = utils('/path/to/eventcatalog');

// Write an event to the catalog
// Event would be written to queries/GetOrder
await writeQuery({
id: 'GetOrder',
name: 'Get Order',
version: '0.0.1',
summary: 'This is a summary',
markdown: '# Hello world',
});

// Write an event to the catalog but override the path
// Event would be written to queries/Inventory/GetOrder
await writeQuery({
id: 'GetOrder',
name: 'Get Order',
version: '0.0.1',
summary: 'This is a summary',
markdown: '# Hello world',
}, { path: "/Orders/GetOrder"});

// Write a query to the catalog and override the existing content (if there is any)
await writeQuery({
id: 'GetOrder',
name: 'Get Order',
version: '0.0.1',
summary: 'This is a summary',
markdown: '# Hello world',
}, { override: true });

// Write a query to the catalog and version the previous version
// only works if the new version is greater than the previous version
await writeQuery({
id: 'GetOrder',
name: 'Get Order',
version: '0.0.1',
summary: 'This is a summary',
markdown: '# Hello world',
}, { versionExistingContent: true });