core.module.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
  2. import { NgModule } from '@angular/core';
  3. import { Apollo, APOLLO_OPTIONS, ApolloModule } from 'apollo-angular';
  4. import { HttpLink, HttpLinkModule } from 'apollo-angular-link-http';
  5. import { InMemoryCache } from 'apollo-cache-inmemory';
  6. import { API_PATH } from '../../../../shared/shared-constants';
  7. import { API_URL } from '../app.config';
  8. import { SharedModule } from '../shared/shared.module';
  9. import { APOLLO_NGRX_CACHE, StateModule } from '../state/state.module';
  10. import { AppShellComponent } from './components/app-shell/app-shell.component';
  11. import { BreadcrumbComponent } from './components/breadcrumb/breadcrumb.component';
  12. import { MainNavComponent } from './components/main-nav/main-nav.component';
  13. import { UserMenuComponent } from './components/user-menu/user-menu.component';
  14. import { BaseDataService } from './providers/data/base-data.service';
  15. import { DataService } from './providers/data/data.service';
  16. import { DefaultInterceptor } from './providers/data/interceptor';
  17. import { AuthGuard } from './providers/guard/auth.guard';
  18. import { LocalStorageService } from './providers/local-storage/local-storage.service';
  19. import { OverlayHostComponent } from './components/overlay-host/overlay-host.component';
  20. import { OverlayHostService } from './providers/overlay-host/overlay-host.service';
  21. import { NotificationService } from './providers/notification/notification.service';
  22. import { NotificationComponent } from './components/notification/notification.component';
  23. export function createApollo(httpLink: HttpLink, ngrxCache: InMemoryCache) {
  24. return {
  25. link: httpLink.create({ uri: `${API_URL}/${API_PATH}` }),
  26. cache: ngrxCache,
  27. };
  28. }
  29. @NgModule({
  30. imports: [
  31. SharedModule,
  32. HttpClientModule,
  33. ApolloModule,
  34. HttpLinkModule,
  35. StateModule,
  36. ],
  37. exports: [
  38. SharedModule,
  39. OverlayHostComponent,
  40. ],
  41. providers: [
  42. {
  43. provide: APOLLO_OPTIONS,
  44. useFactory: createApollo,
  45. deps: [HttpLink, APOLLO_NGRX_CACHE],
  46. },
  47. { provide: HTTP_INTERCEPTORS, useClass: DefaultInterceptor, multi: true },
  48. BaseDataService,
  49. LocalStorageService,
  50. DataService,
  51. AuthGuard,
  52. OverlayHostService,
  53. NotificationService,
  54. ],
  55. declarations: [AppShellComponent, UserMenuComponent, MainNavComponent, BreadcrumbComponent, OverlayHostComponent, NotificationComponent],
  56. entryComponents: [NotificationComponent],
  57. })
  58. export class CoreModule {}