Views typically need to access data about the current page or object, as well as other arbitrary content from the CMS. To do so, create a .graphql file with the same name as the .tsx file. The GraphQL query will be executed every request, and the data is automatically passed to the view when it is rendered. You never need to handle the loading process yourself!
To query the current page or post being viewed, use $postId as an input variable.
query Page($postId: ID!) {
page(id: $postId, idType: DATABASE_ID) {
title
slug
template {
templateName
}
contentBlocks
}
}