cmsBlocks
Fetch cms blocks.
Signature
declare function cmsBlocks(
context: Context,
identifiers: string,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<CmsBlocksQuery>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
identifiers | Required | string | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- CustomQuery
- CustomHeaders
ApolloQueryResultCmsBlocksQuery
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// fetch few cms blocks by their identifiers
const { data } = await sdk.magento.cmsBlocks({
identifiers: ['id1', 'id2']
});
// result will contain cms blocks with the specified identifiers
data.cmsBlocks.items.forEach(block => console.log(block.identifier));Creating a custom GraphQL query
module.exports = {
integrations: {
magento: {
customQueries: {
'cms-blocks-custom-query': ({ variables, metadata }) => ({
variables,
query: `
query cmsBlock($identifiers: [String]) {
cmsBlocks(identifiers: $identifiers) {
items {
${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 returned by the query, when compared to the default query
// fetch only title
const customQuery = {
cmsBlocks: 'cms-blocks-custom-query',
metadata: {
fields: 'title'
}
};
const { data } = await sdk.magento.cmsBlocks({
identifiers: ['id1', 'id2']
}, customQuery);
// data will contain only block titles