page.query.graphql
The page.query.graphql file contains the main GraphQL query for fetching page data. This query retrieves the “shell” (layout) and above-the-fold content needed for initial page render.
File Location
Section titled “File Location”src/pages/{routeName}/_graphql/page.query.graphqlsrc/pages/{routeName}/_graphql/page.query.cms.graphqlsrc/pages/{routeName}/_graphql/page.query.api.graphqlsrc/pages/{routeName}/_graphql/page.query.shop.graphqlPage query files are located in the _graphql directory with optional codegen suffixes.
Examples:
src/pages/articles/_graphql/page.query.cms.graphqlsrc/pages/places/_graphql/page.query.cms.graphqlsrc/pages/articles/[slug]/_graphql/page.query.cms.graphqlsrc/pages/shop/products/_graphql/page.query.shop.graphqlFile Naming Convention
Section titled “File Naming Convention”page.query.{codegen?}.graphqlWhere {codegen} indicates which GraphQL service:
.cms.graphql- Contentful (most pages).api.graphql- Rakiura GraphQL.shop.graphql- Shopify- No suffix - Generic/multi-service
Operation Naming
Section titled “Operation Naming”The operation name follows the pattern:
query {RouteName}Page { # fields}Examples:
query ArticlesPage { } # /articlesquery ArticlePage { } # /articles/[slug] (singular)query PlacesPage { } # /placesquery PlacePage { } # /places/[slug]Typical Structure
Section titled “Typical Structure”Static Page Query
Section titled “Static Page Query”query ArticlesPage { internalPageCollection(where: { slug: "articles" }, limit: 1) { items { title slug
# Hero section hero { title subtitle image { ...ImageProperties } }
# Page metadata metadata { metaTitle metaDescription ogImage { ...ImageProperties } }
# Above-fold components componentsCollection(limit: 3) { items { __typename ... on ComponentHero { title content } ... on ComponentFeatured { articlesCollection { items { ...ArticleListItem } } } } } } }}Dynamic Page Query
Section titled “Dynamic Page Query”query ArticlePage($slug: String!) { articleCollection(where: { slug: $slug }, limit: 1) { items { title slug publishDate
# Hero heroImage { ...ImageProperties }
# Author author { name slug image { ...ImageProperties } }
# Content (above fold only) contentCollection(limit: 2) { items { __typename ... on ContentText { text } ... on ContentImage { image { ...ImageProperties } caption } } }
# Metadata metadata { metaTitle metaDescription tags } } }}Variables
Section titled “Variables”Define variables with appropriate types:
# Static page - no variablesquery ArticlesPage { }
# Dynamic page - required variablesquery ArticlePage($slug: String!) { }
# Optional filtersquery ArticlesPage( $category: String $tag: String $limit: Int = 20) { }
# Multiple variablesquery ArticlePage( $slug: String! $preview: Boolean = false $locale: String = "en-US") { }Fragment Imports
Section titled “Fragment Imports”Use path aliases for fragment imports:
#import "#graphql/fragments/image.fragment.graphql"#import "#graphql/fragments/articleListItem.fragment.graphql"
query ArticlesPage { articleCollection { items { ...ArticleListItem } }}Related
Section titled “Related”- GraphQL Naming - Query naming conventions
- api.ts - API functions that execute queries
- Fragment Files - Reusable field selections
- GraphQL Query Patterns - Query organization and best practices