api.module.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { Module } from '@nestjs/common';
  2. import { APP_FILTER, 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 { AuthGuard } from './middleware/auth-guard';
  10. import { ExceptionLoggerFilter } from './middleware/exception-logger.filter';
  11. import { IdInterceptor } from './middleware/id-interceptor';
  12. import { ValidateCustomFieldsInterceptor } from './middleware/validate-custom-fields-interceptor';
  13. /**
  14. * The ApiModule is responsible for the public API of the application. This is where requests
  15. * come in, are parsed and then handed over to the ServiceModule classes which take care
  16. * of the business logic.
  17. */
  18. @Module({
  19. imports: [
  20. ServiceModule.forRoot(),
  21. DataImportModule,
  22. ApiSharedModule,
  23. AdminApiModule,
  24. ShopApiModule,
  25. configureGraphQLModule(configService => ({
  26. apiType: 'shop',
  27. apiPath: configService.shopApiPath,
  28. typePaths: ['type', 'shop-api', 'common'].map(p =>
  29. path.join(__dirname, 'schema', p, '*.graphql'),
  30. ),
  31. resolverModule: ShopApiModule,
  32. })),
  33. configureGraphQLModule(configService => ({
  34. apiType: 'admin',
  35. apiPath: configService.adminApiPath,
  36. typePaths: ['type', 'admin-api', 'common'].map(p =>
  37. path.join(__dirname, 'schema', p, '*.graphql'),
  38. ),
  39. resolverModule: AdminApiModule,
  40. })),
  41. ],
  42. providers: [
  43. RequestContextService,
  44. {
  45. provide: APP_GUARD,
  46. useClass: AuthGuard,
  47. },
  48. {
  49. provide: APP_INTERCEPTOR,
  50. useClass: IdInterceptor,
  51. },
  52. {
  53. provide: APP_INTERCEPTOR,
  54. useClass: ValidateCustomFieldsInterceptor,
  55. },
  56. {
  57. provide: APP_FILTER,
  58. useClass: ExceptionLoggerFilter,
  59. },
  60. ],
  61. })
  62. export class ApiModule {}