Part 4: Querying the CMS data
Introduction​
After syncing your Section and Content Type definitions with the VTEX Headless CMS, each Content Type will have a corresponding type on the Gatsby GraphQL layer.
In this section, we'll see how to query for this data using the REST API and how to adapt our pages
components to consume this data.
Step by step​
Step 1 - The Headless CMS API​
To fetch data from the VTEX Headless CMS data layer into your FastStore project, you'll need to fetch the data from the Headless CMS API.
info
For more information about the CMS API, check the CMS API Reference
.
Step 2 - Rendering the CMS content​
Let's update our components to present the content submitted via the VTEX Headless CMS app. To do that, take the following steps:
Open your FastStore project in any code editor of your preference.
Go to the
src/pages/index.tsx
file.Import the React components corresponding to the Sections you previously created in the CMS (e.g.,
RichText
,Shelf
) and add it toCOMPONENTS
. For example:src/components/RenderCMS.tsximport Shelf from 'src/components/sections/Shelf'
import RichText from 'src/components/sections/RichText'
const COMPONENTS: Record<string, ComponentType<any>> = {
Shelf,
RichText,
}Save your changes.