UNPKG

@acorel/contentful-integration

Version:
33 lines (29 loc) 1.42 kB
import {GraphqlCmsIntegrationService, GraphqlCmsPageAdapter} from "@acorel/graphql-integration"; import {CmsStructureConfigService, OccCmsComponentAdapter, OccCmsPageAdapter, PageContext} from "@spartacus/core"; import {QueryOptions} from "@apollo/client/core"; import {Observable, of} from "rxjs"; import {Apollo} from "apollo-angular"; import {ContentfulLivePreviewService} from "./contentful-live-preview.service"; import {Injectable} from "@angular/core"; @Injectable({ providedIn: 'root', }) export class ContentfulCmsPageAdapter extends GraphqlCmsPageAdapter { constructor(occCmsPageAdapter: OccCmsPageAdapter, cmsStructureConfigService: CmsStructureConfigService, graphqlCmsIntegrationService: GraphqlCmsIntegrationService, apollo: Apollo, private contentfulLivePreviewService :ContentfulLivePreviewService) { super(occCmsPageAdapter, cmsStructureConfigService, graphqlCmsIntegrationService, apollo); } override doQuery(id: string, pageContext: PageContext, query: QueryOptions): Observable<any> { if (this.contentfulLivePreviewService.isPreviewEnabled()) { let previewContent = this.contentfulLivePreviewService.previewContent(id, pageContext); if (previewContent) { console.log('PREVIEW CONTENT', previewContent); return of(previewContent); } } return super.doQuery(id, pageContext, query); } }