vendure-plugin.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { DocumentNode } from 'graphql';
  2. import { Type } from '../../../../shared/shared-types';
  3. import { VendureConfig } from '../vendure-config';
  4. /**
  5. * A VendurePlugin is a means of configuring and/or extending the functionality of the Vendure server. In its simplest form,
  6. * a plugin simply modifies the VendureConfig object. Although such configuration can be directly supplied to the bootstrap
  7. * function, using a plugin allows one to abstract away a set of related configuration.
  8. *
  9. * Aditionally, the init() method can perform async work such as starting servers, making calls to 3rd party services, or any other
  10. * kind of task which may be called for.
  11. */
  12. export interface VendurePlugin {
  13. /**
  14. * This method is called before the app bootstraps, and can modify the VendureConfig object and perform
  15. * other (potentially async) tasks needed.
  16. */
  17. init(config: Required<VendureConfig>): Required<VendureConfig> | Promise<Required<VendureConfig>>;
  18. /**
  19. * This method is called after the app has bootstrapped. In this method, instances of services may be injected
  20. * into the plugin. For example, the ProductService can be injected in order to enable operations on Product
  21. * entities.
  22. */
  23. onBootstrap?(inject: <T>(type: Type<T>) => T): void | Promise<void>;
  24. /**
  25. * The plugin may extend the default Vendure GraphQL schema by implementing this method.
  26. */
  27. defineGraphQlTypes?(): DocumentNode;
  28. /**
  29. * The plugin may define custom providers (including GraphQL resolvers) which can then be injected via the Nest DI container.
  30. */
  31. defineProviders?(): Array<Type<any>>;
  32. /**
  33. * The plugin may define custom database entities, which should be defined as classes annotated as per the
  34. * TypeORM documentation.
  35. */
  36. defineEntities?(): Array<Type<any>>;
  37. }