api.module.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Module } from '@nestjs/common';
  2. import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
  3. import path from 'path';
  4. import { DataImportModule } from '../data-import/data-import.module';
  5. import { ServiceModule } from '../service/service.module';
  6. import { AdminApiModule, ApiSharedModule, ShopApiModule } from './api-internal-modules';
  7. import { RequestContextService } from './common/request-context.service';
  8. import { configureGraphQLModule } from './config/configure-graphql-module';
  9. import { AssetInterceptor } from './middleware/asset-interceptor';
  10. import { AuthGuard } from './middleware/auth-guard';
  11. import { IdInterceptor } from './middleware/id-interceptor';
  12. /**
  13. * The ApiModule is responsible for the public API of the application. This is where requests
  14. * come in, are parsed and then handed over to the ServiceModule classes which take care
  15. * of the business logic.
  16. */
  17. @Module({
  18. imports: [
  19. ServiceModule,
  20. DataImportModule,
  21. ApiSharedModule,
  22. AdminApiModule,
  23. ShopApiModule,
  24. configureGraphQLModule(configService => ({
  25. apiType: 'shop',
  26. apiPath: configService.shopApiPath,
  27. typePaths: ['type', 'shop-api', 'common'].map(p =>
  28. path.join(__dirname, 'schema', p, '*.graphql'),
  29. ),
  30. resolverModule: ShopApiModule,
  31. })),
  32. configureGraphQLModule(configService => ({
  33. apiType: 'admin',
  34. apiPath: configService.adminApiPath,
  35. typePaths: ['type', 'admin-api', 'common'].map(p =>
  36. path.join(__dirname, 'schema', p, '*.graphql'),
  37. ),
  38. resolverModule: AdminApiModule,
  39. })),
  40. ],
  41. providers: [
  42. RequestContextService,
  43. {
  44. provide: APP_GUARD,
  45. useClass: AuthGuard,
  46. },
  47. {
  48. provide: APP_INTERCEPTOR,
  49. useClass: AssetInterceptor,
  50. },
  51. {
  52. provide: APP_INTERCEPTOR,
  53. useClass: IdInterceptor,
  54. },
  55. ],
  56. })
  57. export class ApiModule {}