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.
Before jumping into queries, it’s important to understand:

Fetch Sitecore pages efficiently with flexible GraphQL queries, smart filtering, pagination, and scalable data delivery for modern headless applications.
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:
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:
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:
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:
Templates are more reliable than paths because:
If your site is multilingual:
{
name: "_language"
value: "en"
}Use pagination:
search(first: 10, after: "cursor") {
results {
id
name
}
}Fields like _templates, _path, and _language are optimized for search.
Fetching all page items in Sitecore using GraphQL is straightforward once you understand how Sitecore structures content.
To summarize:
With these techniques, you can efficiently power headless applications, APIs, and frontend frameworks using Sitecore GraphQL.
Happy Coding!
You can use the Sitecore GraphQL search query to retrieve page items by filtering on the _templates field. This is typically the most reliable approach because Sitecore pages are created from templates rather than having a single built-in page item type.
Template-based filtering is generally the best approach. Query the _templates field with the page template ID so the results return items based on the templates that define your website pages.
Yes. You can filter the GraphQL search query using the _path field to retrieve items stored under a specific content tree location. This works well when all page items are organized beneath a common parent node.
Use GraphQL fragments and the appropriate GraphQL type to request strongly typed fields such as title, body, images, links, or other template-specific content fields.
Use the item query to retrieve a parent item and request its children. This approach is useful for navigation menus, sitemap generation, tree-based interfaces, and hierarchical content structures.
Filter the query using the _language field or provide a language parameter where supported by the GraphQL endpoint. This helps return the correct language version of multilingual Sitecore content.
Use GraphQL pagination arguments such as first and after when supported by the endpoint. Pagination helps limit the number of results returned in a single request and improves performance for large content collections.
For basic page lists, return fields such as id, name, path, and URL. For richer page data, use fragments to request template-specific fields such as titles, body content, images, and metadata.
Templates are usually more stable than content paths. A page can move to another location in the content tree while retaining the same template, making template-based filtering more resilient to content restructuring.
Common mistakes include treating pages as a built-in Sitecore item type, using incorrect template IDs, ignoring language versions, returning too many results, skipping pagination, and not using strongly typed fragments for template-specific fields.