VendurePlugin

VendurePlugin

A VendurePlugin is a means of configuring and/or extending the functionality of the Vendure server. In its simplest form, a plugin simply modifies the VendureConfig object. Although such configuration can be directly supplied to the bootstrap function, using a plugin allows one to abstract away a set of related configuration.

As well as configuring the app, a plugin may also extend the GraphQL schema by extending existing types or adding entirely new types. Database entities and resolvers can also be defined to handle the extended GraphQL types.

Signature

interface VendurePlugin {
  configure?(config: Required<VendureConfig>): Required<VendureConfig> | Promise<Required<VendureConfig>>;
  onBootstrap?(inject: InjectorFn): void | Promise<void>;
  onClose?(): void | Promise<void>;
  extendShopAPI?(): APIExtensionDefinition;
  extendAdminAPI?(): APIExtensionDefinition;
  defineProviders?(): Provider[];
  defineEntities?(): Array<Type<any>>;
}

Members

configure

method
type:
(config: Required<VendureConfig>) => Required<VendureConfig> | Promise<Required<VendureConfig>>

This method is called before the app bootstraps, and can modify the VendureConfig object and perform other (potentially async) tasks needed.

onBootstrap

method
type:
(inject: InjectorFn) => void | Promise<void>

This method is called after the app has bootstrapped. In this method, instances of services may be injected into the plugin. For example, the ProductService can be injected in order to enable operations on Product entities.

onClose

method
type:
() => void | Promise<void>

This method is called when the app closes. It can be used for any clean-up logic such as stopping servers.

extendShopAPI

method

The plugin may extend the default Vendure GraphQL shop api by implementing this method and providing extended schema definitions and any required resolvers.

extendAdminAPI

method

The plugin may extend the default Vendure GraphQL admin api by implementing this method and providing extended schema definitions and any required resolvers.

defineProviders

method
type:
() => Provider[]

The plugin may define custom providers which can then be injected via the Nest DI container.

defineEntities

method
type:
() => Array<Type<any>>

The plugin may define custom database entities, which should be defined as classes annotated as per the TypeORM documentation.

alpha