How to Fetch All Page Items in Sitecore Using GraphQL

In modern Sitecore implementations—especially with Sitecore Content Hub /Headless Services or Experience Edge—GraphQL has become the preferred way to query content. One common requirement is fetching all “page” items from Sitecore.
Since Sitecore doesn’t have a built-in concept of “pages,” we typically define pages using templates or content paths.
In this blog, we’ll walk through how to retrieve all page items using GraphQL queries.
Understanding the Basics
Before jumping into queries, it’s important to understand:
- Pages = Items based on a specific template
- GraphQL queries in Sitecore usually rely on:
- _templates → to filter by template
- _path → to filter by content tree location
- _language → for multilingual content
Approach 1: Fetch Pages by Template
This is the most reliable and recommended approach.
Every page in Sitecore is created from a template (e.g., Article Page, Landing Page). You can query all items using that template.
Example Query
query GetAllPages {
search(
where: {
AND: [
{
name: "_templates"
value: "{YOUR-PAGE-TEMPLATE-ID}"
operator: CONTAINS
}
]
}
) {
results {
id
name
path
url {
path
}
}
}
}How it works:
- _templates filters items by template ID
- CONTAINS ensures child templates are also included
- Returns basic page details like name, path, and URL
Approach 2: Fetch Pages by Content Path
If all your pages are stored under a specific node (e.g., /sitecore/content/Home), you can filter by path.
Example Query
query GetPagesByPath {
search(
where: {
AND: [
{
name: "_path"
value: "/sitecore/content/Home"
operator: CONTAINS
}
]
}
) {
results {
id
name
path
url {
path
}
}
}
}When to use this:
- Your content structure is well organized
- All pages live under a common parent node
Approach 3: Fetch Pages with Fields
Often, you need more than just metadata—you want actual page content like title or body.
Example Query
query GetPagesWithFields {
search(
where: {
AND: [
{
name: "_templates"
value: "{YOUR-PAGE-TEMPLATE-ID}"
operator: CONTAINS
}
]
}
) {
results {
id
name
... on PageTemplate {
title {
value
}
body {
value
}
}
}
}
}Notes:
- Replace PageTemplate with your actual GraphQL type name
- This uses GraphQL fragments to fetch strongly typed fields
Approach 4: Using Children (Hierarchical Fetch)
If you want to traverse the content tree:
query GetChildPages {
item(path: "/sitecore/content/Home", language: "en") {
id
name
children {
results {
id
name
url {
path
}
}
}
}
}Use case:
- Navigation menus
- Sitemap generation
- Tree-based rendering
Best Practices
1. Prefer Template-Based Queries
Templates are more reliable than paths because:
- Content structure may change
- Templates remain consistent
2. Always Filter by Language
If your site is multilingual:
{
name: "_language"
value: "en"
}
3. Limit Results for Performance
Use pagination:
search(first: 10, after: "cursor") {
results {
id
name
}
}
4. Use Index-Friendly Fields
Fields like _templates, _path, and _language are optimized for search.
Common Pitfalls
- Treating “pages” as a built-in concept
- Forgetting template IDs
- Not handling pagination
- Ignoring language versions
Conclusion
Fetching all page items in Sitecore using GraphQL is straightforward once you understand how Sitecore structures content.
To summarize:
- Use template filtering for accuracy
- Use path filtering for hierarchy-based queries
- Extend queries with fields and fragments for rich content
With these techniques, you can efficiently power headless applications, APIs, and frontend frameworks using Sitecore GraphQL.
Happy Coding!
