UNPKG

@acorel/contentful-integration

Version:
98 lines (96 loc) 3.02 kB
import {NgModule} from "@angular/core"; import {GraphqlIntegrationModule} from "@acorel/graphql-integration"; import {GraphqlCmsIntegrationService} from "@acorel/graphql-integration"; import {ContentfulIntegrationService} from "./contentful-integration.service"; import { CmsComponentAdapter, CmsConfig, CmsPageAdapter, ComponentDecorator, provideConfig, provideDefaultConfig } from "@spartacus/core"; import {ContentfulComponentDecorator} from "./contentful-component-decorator"; import {ContentfulLivePreviewService} from "./contentful-live-preview.service"; import {ContentfulCmsComponentAdapter} from "./contentful-cms-component.adapter"; import {ContentfulConfig} from "./contentful-config"; import {defaultContentfulConfig} from "./default-contentful-config"; import {APOLLO_OPTIONS} from "apollo-angular"; import {HttpLink} from "apollo-angular/http"; import {InMemoryCache} from "@apollo/client/core"; import {LayoutConfig, OutletModule, PageComponentModule} from "@spartacus/storefront"; import { ContentfulContentSlotComponent } from './components/contentful-content-slot/contentful-content-slot.component'; import {AsyncPipe, CommonModule, JsonPipe} from "@angular/common"; import {ContentfulCmsPageAdapter} from "./contentful-cms-page.adapter"; @NgModule({ imports: [ GraphqlIntegrationModule, CommonModule, PageComponentModule, OutletModule, AsyncPipe, JsonPipe, ], providers: [ provideDefaultConfig(<ContentfulConfig>defaultContentfulConfig), { provide: APOLLO_OPTIONS, useFactory(httpLink: HttpLink, config: ContentfulConfig) { return { cache: new InMemoryCache(), link: httpLink.create({ uri: (config.contentful?.backend) ? config.contentful.backend.url + config.contentful.backend.space + '?access_token=' + config.contentful.backend.accessToken : '', }) }; }, deps: [HttpLink, ContentfulConfig], }, provideDefaultConfig(<LayoutConfig>{ layoutSlots: { ContentfulContentPageTemplate: { slots: [ 'Default' ], } } } ), provideDefaultConfig(<CmsConfig>{ cmsComponents: { CmsContentfulContentSlotComponent: { component: ContentfulContentSlotComponent, } } }), { provide: GraphqlCmsIntegrationService, useExisting: ContentfulIntegrationService, }, { provide: ComponentDecorator, useExisting: ContentfulComponentDecorator, multi: true, }, { provide: ContentfulLivePreviewService, useClass: ContentfulLivePreviewService }, { provide: CmsComponentAdapter, useClass: ContentfulCmsComponentAdapter, }, { provide: CmsPageAdapter, useClass: ContentfulCmsPageAdapter, } ], declarations: [ ContentfulContentSlotComponent ] }) export class ContentfulIntegrationModule { }