View Queries
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.
views/page.graphql
query Page($postId: ID!) {
page(id: $postId, idType: DATABASE_ID) {
title
slug
contentBlocks
}
}The $postId argument is automatically sent to any view where a post is involved — so typically page, single and single-{post-type}, as well as custom page templates.
Last updated on