Skip to main content

writeQuery

Callable

  • writeQuery(directory: string): (query: Query, options?: { override?: boolean; path?: string; versionExistingContent?: boolean }) => Promise<void>

  • Write a query to EventCatalog.

    You can optionally override the path of the query.

    @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 });