core.module.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { 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 { SharedModule } from '../shared/shared.module';
  7. import { APOLLO_NGRX_CACHE, StateModule } from '../state/state.module';
  8. import { AppShellComponent } from './components/app-shell/app-shell.component';
  9. import { BaseDataService } from './providers/data/base-data.service';
  10. import { API_URL } from '../app.config';
  11. import { LocalStorageService } from './providers/local-storage/local-storage.service';
  12. import { DataService } from './providers/data/data.service';
  13. import { AuthGuard } from './providers/guard/auth.guard';
  14. export function createApollo(httpLink: HttpLink, ngrxCache: InMemoryCache) {
  15. return {
  16. link: httpLink.create({ uri: `${API_URL}/graphql` }),
  17. cache: ngrxCache,
  18. };
  19. }
  20. @NgModule({
  21. imports: [
  22. SharedModule,
  23. HttpClientModule,
  24. ApolloModule,
  25. HttpLinkModule,
  26. StateModule,
  27. ],
  28. exports: [
  29. SharedModule,
  30. ],
  31. providers: [
  32. {
  33. provide: APOLLO_OPTIONS,
  34. useFactory: createApollo,
  35. deps: [HttpLink, APOLLO_NGRX_CACHE],
  36. },
  37. BaseDataService,
  38. LocalStorageService,
  39. DataService,
  40. AuthGuard,
  41. ],
  42. declarations: [AppShellComponent],
  43. })
  44. export class CoreModule {}