diff --git a/api/src/extensions.ts b/api/src/extensions.ts index 81aaae72d0..7ba1052b33 100644 --- a/api/src/extensions.ts +++ b/api/src/extensions.ts @@ -7,6 +7,7 @@ import emitter from './emitter'; import logger from './logger'; import { HookRegisterFunction, EndpointRegisterFunction } from './types'; import { ensureDir } from 'fs-extra'; +import { getSchema } from './utils/get-schema'; import * as exceptions from './exceptions'; import * as services from './services'; @@ -93,7 +94,7 @@ function registerHooks(hooks: string[]) { } } - let events = register({ services, exceptions, env, database }); + let events = register({ services, exceptions, env, database, getSchema }); for (const [event, handler] of Object.entries(events)) { emitter.on(event, handler); } @@ -126,6 +127,6 @@ function registerEndpoints(endpoints: string[], router: Router) { const scopedRouter = express.Router(); router.use(`/${endpoint}/`, scopedRouter); - register(scopedRouter, { services, exceptions, env, database }); + register(scopedRouter, { services, exceptions, env, database, getSchema }); } } diff --git a/api/src/types/extensions.ts b/api/src/types/extensions.ts index 1f492f5592..a614c1b3d1 100644 --- a/api/src/types/extensions.ts +++ b/api/src/types/extensions.ts @@ -4,12 +4,14 @@ import * as exceptions from '../exceptions'; import env from '../env'; import { Knex } from 'knex'; import { Router } from 'express'; +import { getSchema } from '../utils/get-schema'; export type ExtensionContext = { services: typeof services; exceptions: typeof exceptions; database: Knex; env: typeof env; + getSchema: typeof getSchema; }; export type HookRegisterFunction = (context: ExtensionContext) => Record; diff --git a/docs/guides/api-endpoints.md b/docs/guides/api-endpoints.md index b6f4bd4271..432bcff0b8 100644 --- a/docs/guides/api-endpoints.md +++ b/docs/guides/api-endpoints.md @@ -38,6 +38,7 @@ that is scoped to `/custom/`, while `context` holds the followin - `services` — All API internal services. - `exceptions` — API exception objects that can be used to throw "proper" errors. - `database` — Knex instance that is connected to the current database. +- `getSchema` — Async function that reads the full available schema for use in services - `env` — Parsed environment variables. ## 3. Restart the API diff --git a/docs/guides/api-hooks.md b/docs/guides/api-hooks.md index 7dc6556772..aded41c7a5 100644 --- a/docs/guides/api-hooks.md +++ b/docs/guides/api-hooks.md @@ -126,6 +126,7 @@ The `registerHook` function receives a context parameter with the following prop - `services` — All API internal services - `exceptions` — API exception objects that can be used for throwing "proper" errors - `database` — Knex instance that is connected to the current database +- `getSchema` — Async function that reads the full available schema for use in services - `env` — Parsed environment variables ### Event Handler Function