Alokai

cmsPage

Fetch CMS page

Signature

declare function cmsPage(
	context: Context,
	identifier: string,
	customQuery?: CustomQuery,
	customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<CmsPageQuery>>;

Parameters

NameRequiredTypeDescription
contextRequiredContext
identifierRequiredstring
customQueryOptionalCustomQuery
customHeadersOptionalCustomHeaders

Referenced Types

Examples

Simple usage:

import { sdk } from '~/sdk.config.ts';

// fetch home page by the page identifier
const result = await sdk.magento.cmsPage({
  identifier: 'home'
});

Creating a custom GraphQL query

module.exports = {
  integrations: {
    magento: {
      customQueries: {
        'cms-page-custom-query': ({ variables, metadata }) => ({
           variables,
           query: `
             query cmsPage($identifier: String) {
               cmsPage(identifier:$identifier) {
                 ${metadata?.fields}
               }
             }
           `
        }),
      },
    }
  }
};

Using a custom GraphQL query to reduce the amount of fields returned by the query

import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields to only the content and title
const customQuery = {
  cmsPage: 'cms-page-custom-query',
  metadata: {
    fields: 'title content'
  }
};

const result = await sdk.magento.cmsPage({
  identifier: 'home'
}, customQuery);

// result will only contain the title and content fields

On this page