Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Monday, November 3, 2025

Troubleshooting the “Bad Message 414 — URI Too Long” Error in Sitecore SXA

 

Hey everyone,

I recently encountered an issue from one of my colleagues that I thought might be worth sharing. One of the developers on our team was hitting an error while trying to perform a build query from the Scope in an SXA-based Sitecore site. The specific URL in question was something like:

/sitecore/content/website/Settings/Scopes/Scope1


At first glance, I thought the issue was related to security permissions. I suggested checking the security settings for the relevant user group, feeling pretty confident in my assumption. 😎 However, after a deeper dive, I realized that there was more going on under the hood.

Initial Investigation

My colleague confirmed that the user had all the necessary permissions according to our team, but I still couldn’t shake the feeling that something was wrong. I decided to test it with my own credentials (admin access, of course 😜), and I was able to see the results without any issues. This raised a red flag for me — if the permissions were fine for the user, then why was I able to see the results while they couldn’t?

This led me to think that security indexing might be playing a role here, since admins generally bypass certain security checks. After checking everything again and reindexing, I was still stuck. So, I took the next logical step — investigating the logs.

Solving the Puzzle: The “Bad Message 414 — URI Too Long” Error

When I checked the logs and tried to run the query directly through Solr’s console, I was met with the following error message:

<h1>Bad Message 414</h1>
 <pre>reason: URI Too Long</pre>

At this point, I started digging into what “Bad Message 414 — URI Too Long” actually meant. The “414” error indicates that the query string exceeds the maximum allowed length for HTTP GET requests. In Sitecore SXA, this can happen when scopes or filters are applied, generating long query strings that exceed the allowed limit.


Why Does This Happen?

In Sitecore SXA, when you’re working with scopes and search queries, the system often generates a URL with a long query string. This can be problematic because HTTP GET requests have a length limit for the URL (usually around 8192 characters). If the query string becomes too long (which can happen with complex search filters or scopes), Solr will reject the request, and you’ll get the “URI Too Long” error.

So, what can you do about it?

Solutions to Fix the Issue

There are two primary solutions to resolve the “Bad Message 414” error in Sitecore SXA:

1. Switch to HTTP POST Method

The first option is to switch your query to use the HTTP POST method instead of GET. POST requests don’t have the same URL length limitations as GET requests, which can help avoid the “URI Too Long” error. To do this, you’ll need to update your query handling to send data via POST rather than GET.

2. Increase Solr’s Request Header Size

If switching to POST doesn’t work or isn’t a viable option for your implementation, you can increase the maximum allowed size for Solr’s request headers. This solution worked for me, and it’s relatively simple to implement.

Here’s how to increase Solr’s request header size:

  1. Locate the Jetty Configuration File
     
    Open the jetty.xml file in your Solr installation directory. The typical path for this file is:
     SOLR_HOME/server/etc/jetty.xml
  2. Modify the Request Header Size
     
    In the jetty.xml file, locate the following block:
     <Set name=”requestHeaderSize”>
     <Property name=”solr.jetty.request.header.size” default=”8192" />
     </Set>
  3. Increase the Header Size
     
    Change the value from 8192 (the default size) to something larger. For example:
     <Set name=”requestHeaderSize”>
     <Property name=”solr.jetty.request.header.size” default=”29000" />
     </Set>
  4. Save and Restart
     
    Save the file and restart both Solr and Sitecore.

After applying this update, I was able to resolve the issue and the query started working properly!

Conclusion

So, that’s how I tracked down and fixed the “Bad Message 414 — URI Too Long” error in Sitecore SXA. If you’re ever in a similar situation, here are the steps I took:

  • Check security settings (permissions and indexing)
  • Investigate the error logs
  • Run the query directly in Solr’s console to identify the root cause
  • Either switch to the POST method or increase Solr’s request header size

I hope this helps you avoid a similar headache if you ever run into this issue! Let me know if you have any questions, or if there’s anything I missed. Good luck with your Sitecore projects!

Stay cool,

I hope you enjoy this blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.


Wednesday, October 22, 2025

Part 2: Common GraphQL Queries for Sitecore XM Cloud: Advanced Techniques for Powerful Site Building

Hi All,

In the previous blog posts, we covered the fundamentals. Now, let’s delve a bit deeper into the topic.

6. Multi-Level Content Hierarchy Query

When you need to fetch both parent and child items, this nested query is the solution. It’s useful for creating full navigation menus that show both main items and sub-pages.

query ContextItemChildren($contextItem: String!, $language: String!) {
contextItem: item(path: $contextItem, language: $language) {
children {
results {
id
PageTitle: field(name: "PageTitle") {
value: jsonValue
}
children {
results {
id
PageTitle: field(name: "PageTitle") {
value: jsonValue
}
}
}
}
}
}
}

When to use:

  • Building multi-level navigation menus with dropdowns
  • Generating breadcrumb trails with multiple levels
  • Building category/subcategory product listings

Example Variables:

{
"contextItem": "/sitecore/content/MyProject/Home",
"language": "en"
}

7. Template-Specific Content Query

In this query, we’re using fragments to access fields specific to templates. This ensures type safety and allows you to build reusable components for different content types.

query GetTypedContent($itemPath: String!, $language: String!) {
item(path: $itemPath, language: $language) {
id
name
template {
id
name
}
... on Page {
pageTitle: field(name: "PageTitle") {
value
}
metaDescription: field(name: "MetaDescription") {
value
}
}
}
}

When to use:

  • Building reusable queries for different templates
  • Creating generic content components
  • Displaying different fields per content type

Example Variables:

{
"itemPath": "/sitecore/content/MyProject/Home/About",
"language": "en"
}

8. Multi-Template Content Handler Query

This advanced query combines multiple template types in one request using GraphQL fragments. It’s useful when you’re building flexible components that need to handle different content types (like BlogPost, ProductPage, etc.).

query GetContentByType($itemPath: String!, $language: String!) {
item(path: $itemPath, language: $language) {
id
name
template {
id
name
}
... on BlogPost {
title: field(name: "Title") {
value
}
publishDate: field(name: "PublishDate") {
value
}
author: field(name: "Author") {
value
}
}
... on ProductPage {
productName: field(name: "ProductName") {
value
}
price: field(name: "Price") {
value
}
sku: field(name: "SKU") {
value
}
}
... on ContactPage {
address: field(name: "Address") {
value
}
phone: field(name: "Phone") {
value
}
email: field(name: "Email") {
value
}
}
}
}

When to use:

  • Building universal content components
  • Implementing content listings with mixed template types
  • Building search results that adapt to content types

Example Variables:

{
"itemPath": "/sitecore/content/MyProject/Blog/MyBlogPost",
"language": "en"
}

9. Component Datasource Query

When components are using separate content items for data (like a text block or image), this query helps retrieve component-specific data by item ID.

query GetComponentDatasource($datasourceId: String!, $language: String!) {
datasource: item(id: $datasourceId, language: $language) {
id
name
template {
id
name
}
... on TextBlock {
heading: field(name: "Heading") {
value
}
content: field(name: "Content") {
value
}
}
... on ImageContent {
image: field(name: "Image") {
value
jsonValue
}

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.

Friday, October 17, 2025

Part 1: Common GraphQL Queries for Sitecore XM Cloud: A Developer’s Guide — Basic Queries to Level Up Your Skills

 Introduction

As Sitecore shifts toward headless architecture with XM Cloud, combining it with GraphQL unlocks a world of possibilities for building fast, flexible experiences. GraphQL’s ability to request exactly the data you need is an ideal match for modern frameworks like React, Next.js, and other front-end technologies.

In this blog, we’ll explore some of the most essential GraphQL queries that Sitecore developers use daily. We’ll start simple, focusing on fetching single items, and move to more advanced patterns for handling lists, navigation, and multilingual content. These queries have been production-tested, ensuring that they’re ready to be used in your own projects.

1. Get Item by Path Query

This is one of the simplest queries in Sitecore GraphQL. It’s useful when you know the exact content tree path of an item and want to retrieve its data.

query GetItemByPath($path: String!, $language: String!) {
item(path: $path, language: $language) {
id
name
displayName
path
template {
id
name
}
fields {
name
value
}
}
}

When to use:

  • Building navigation menus
  • Fetching page content by route
  • Loading specific content items

Example Variables:

{
"path": "/sitecore/content/MyProject/Home",
"language": "en"
}

2. Get Item by ID Query

If you have an item GUID, using an ID-based query is more efficient than a path-based query. Since GUIDs are unique across the entire Sitecore instance, this method ensures you’re targeting the exact item.

query GetItemById($id: String!, $language: String!) {
item(id: $id, language: $language) {
id
name
displayName
path
fields {
name
value
jsonValue
}
}
}

When to use:

  • Retrieving datasource items for components
  • Following field references

Example Variables:

{
"id": "{11111111-1111-1111-1111-111111111111}",
"language": "en"
}

3. Basic Field Values Query

Accessing individual fields is essential in Sitecore. Here’s a basic example of how to fetch various field types.

query GetItemFields($itemPath: String!, $language: String!) {
item(path: $itemPath, language: $language) {
id
name
fields {
name
value
definition {type}
}
title: field(name: "Title") {
value
definition {type}
}
description: field(name: "Description") {
value
definition {type}
}
}
}

When to use:

  • Retrieving fields like “Title” and “Description”
  • Displaying text fields

Example Variables:

{
"itemPath": "/sitecore/content/MyProject/Home",
"language": "en"
}

4. Structured Field Data Query

This query is useful for fields with more complex structures, such as images, links, or rich text content.

query GetStructuredFields($itemPath: String!, $language: String!) {
item(path: $itemPath, language: $language) {
heroImage: field(name: "HeroImage") {
value
jsonValue
}
ctaLink: field(name: "CTALink") {
value
jsonValue
}
bodyContent: field(name: "BodyContent") {
value
}
}
}

When to use:

  • Building components that need image dimensions and alt text
  • Creating buttons/links with proper href, text, and target attributes
  • Displaying rich text content with HTML formatting

Example Variables:

{
"itemPath": "/sitecore/content/MyProject/Home",
"language": "en"
}

5. Child Items Navigation Query

This query fetches all child items of a specified parent and is commonly used for building navigation menus, content listings, or displaying child pages under a parent.

query ContextItemChildren($contextItem: String!, $language: String!) {
contextItem: item(path: $contextItem, language: $language) {
children{
results{
id
PageTitle: field(name: "PageTitle") {
value: jsonValue
}
}
}
}
}

When to use:

  • Creating breadcrumb navigation
  • Generating sitemaps or content hierarchies
  • Building folder-based content listings

Example Variables:

{
"contextItem": "/sitecore/content/MyProject/Home",
"language": "en"
}

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.

Thursday, September 18, 2025

Mastering GraphQL Queries in Sitecore: A Developer's Practical Playbook - Part 1

Hi All,

In my Previous blog (Supercharging Sitecore with GraphQL: A Developer’s Guide) we started on GraphQL step by step instructions on how to configure and utilize the Sitecore GraphQL API on your local machine.

As developers, we've all been there. You have the power of GraphQL at your fingertips, but finding the right query pattern for your specific use case feels like searching for a needle in a digital haystack. That's exactly why this comprehensive guide exists – to be your go-to reference when you need to craft the perfect GraphQL query for Sitecore.

Setting the Stage: Understanding Your Content Structure

Before diving into queries, let's establish the foundation. Imagine you're working on an enterprise website with the following content structure:

/sitecore/content/Home/MySampleProject/Home/
├── About ├── Services ├── News └── Contact

Each of these items has specific templates with fields like:

  • About Template: Title, Subtitle, Description, Image, Date, IsTrue
  • Services Template: ServiceName, ServiceDescription, Icon, Features (Multilist)
  • News Template: Headline, Summary, Author, PublishDate, RelatedArticles (Treelist)

This realistic structure will ground all our examples in practical, real-world scenarios.

The Essential Query Patterns Every Sitecore Developer Needs

1. The Foundation Query: Getting All Field Data

Real-world scenario: You're debugging a component and need to see all available field data for an item.

query InspectAllFields($contextItem: String!) {
  item(path: $contextItem) {
    fields {
      name
      value
    }
  }
}

Query Variables:

{
  "contextItem": "/sitecore/content/Home/MySampleProject/Home/About"
}

Why this matters: This is your debugging lifeline. When a component isn't displaying correctly, this query shows you exactly what data is available and how it's structured.

2. The Content Retrieval Pattern: Getting Specific Item Data

Real-world scenario: You're building a hero component that needs specific fields from a content item.

query HeroComponentData {
  item(path: "/sitecore/content/Home/MySampleProject/Home/About") {
id name template { name } subTitle: field(name: "SubTitle") { value } description: field(name: "Description") { value } } }

Developer insight: Notice how we're using aliases (subTitle, description) to make the response more readable and match our frontend component props.

3. The Template Filter Pattern: Type-Safe Content Querying

Real-world scenario: You have a mixed content area, but only want to display specific item types.

query FilteredChildrenByTemplate($contextItem: String!) {
  item(path: $contextItem) {
    children {
      ... on About {
        id
        name
        title: field(name: "Title") {
          value
        }
        subtitle: field(name: "Subtitle") {
          value
        }
      }
      ... on Services {
        id
        name
        serviceName: field(name: "ServiceName") {
          value
        }
        serviceDescription: field(name: "ServiceDescription") {
          value
        }
      }
    }
  }
}

Pro tip: This pattern is incredibly powerful for building dynamic listing components where different item types need different field mappings.

4. The Common Fields Pattern: Flexible Content Components

Real-world scenario: You're building a card component that can display different content types but needs consistent field access.

query FlexibleContentCard($datasource: String!) {
  datasource: item(path: $datasource, language: "en") {
    id
    name
    url
    ... on About {
      title {
        value
      }
      subtitle {
        value
      }
      image {
        alt
        src
      }
      link {
        url
      }
      date {
        value
      }
      isTrue {
        value
      }
    }
    ... on News {
      headline: title {
        value
      }
      summary: subtitle {
        value
      }
      publishDate: date {
        value
      }
      author {
        value
      }
    }
  }
}

Developer insight: This pattern allows one component to handle multiple content types gracefully, reducing code duplication.

5. The Relationship Query Pattern: Handling Multilist and Treelist Fields

Real-world scenario: You're building a services page where each service has related case studies or features.

Approach 1: Direct Field Access

query ServiceWithRelatedItems($datasource: String!) {
  datasource: item(path: $datasource, language: "en") {
    id
    name
    ... on Services {
      serviceName: title {
        value
      }
      serviceDescription: subtitle {
        value
      }
      relatedFeatures: multiListItems {
        id
        name
        targetItems {
          id
          name
          path
          ... on Feature {
            featureName: title {
              value
            }
            featureDescription: description {
              value
            }
            icon {
              src
              alt
            }
          }
        }
      }
    }
  }
}

Approach 2: Search-Based Access

query ServiceFeaturesViaSearch {
  search(
    fieldsEqual: [
      {
        name: "_fullpath"
        value: "/sitecore/content/Home/MySampleProject/Home/Services"
} ] keyword: "" ) { results { items { item { ... on Services { serviceName: title { value } relatedFeatures: multiListItems { value name targetItems { id name ... on Feature { featureName: title { value } description { value } } } } } } } } } }

When to use which approach: Use Approach 1 when you know the exact item path. Use Approach 2 when you need to find items dynamically or apply additional search criteria.

6. The DropLink Pattern: Single Reference Fields

Real-world scenario: Your news articles reference a single author item, and you need author details.

query NewsWithAuthor($datasource: String!) {
  datasource: item(path: $datasource, language: "en") {
    id
    name
    ... on News {
      headline: title {
        value
      }
      summary {
        value
      }
      authorReference: dropLinkItem {
        id
        name
        targetItem {
          id
          name
          ... on Author {
            fullName: displayName {
              value
            }
            bio {
              value
            }
            profileImage {
              src
              alt
            }
          }
        }
      }
    }
  }
}

7. The Alias Power Pattern: Clean, Component-Ready Data

Real-world scenario: Your frontend team needs field names that match their component props exactly.

query ComponentReadyData($contextItem: String!) {
  componentData: item(path: $contextItem) {
    componentId: id
    ... on About {
      heading: title {
        value
      }
      subheading: subtitle {
        value
      }
      bodyText: description {
        value
      }
      ctaLink: link {
        url
        target
      }
    }
  }
}

Developer benefit: This eliminates the need for field mapping in your frontend code, making components cleaner and more maintainable.

8. The Hierarchical Data Pattern: Multi-Level Navigation

Real-world scenario: You're building a navigation component that needs to show page hierarchies.

query NavigationStructure {
  item(path: "/sitecore/content/Home/MySampleProject/Home") {
children { name id url template { name } ... on NavigationItem { navigationTitle: title { value } showInNavigation { value } } children { name id url template { name } ... on NavigationItem { navigationTitle: title { value } showInNavigation { value } } # Third level if needed children { name id url ... on NavigationItem { navigationTitle: title { value } } } } } } }

9. The Template-Only Fields Pattern: Clean Data Filtering

Real-world scenario: You want to avoid system fields and only get template-defined fields for a cleaner component interface.

query CleanTemplateFields($contextItem: String!) {
  item(path: $contextItem) {
    fields(ownFields: true) {
      id
      name
      value
      type
    }
    template {
      name
      fields {
        name
        type
      }
    }
  }
}

Why this matters: This prevents your components from accidentally depending on Sitecore system fields, making them more portable and maintainable.

10. The Search Mastery Patterns: Finding Content Dynamically

Pattern A: Exact Field Matching

Real-world scenario: Finding all blog posts by a specific author.

query BlogPostsByAuthor {
  search(
    fieldsEqual: [
      {
        name: "author"
        value: "John Smith"
      }
      {
        name: "_template"
        value: "BlogPost"
      }
    ]
    rootItem: "/sitecore/content/Home/MySampleProject/Home/Blog"
) { results { totalCount items { item { id name path url ... on BlogPost { title { value } publishDate { value } summary { value } author { value } } } } } } }

Pattern B: Keyword Search

Real-world scenario: Building a site search feature.

query SiteSearch($searchTerm: String!, $searchRoot: String!) {
  search(
    keyword: $searchTerm
    rootItem: $searchRoot
  ) {
    results {
      totalCount
      items {
        item {
          id
          name
          path
          url
          template {
            name
          }
          # Get title field regardless of template
          title: field(name: "Title") {
            value
          }
          # Get description field regardless of template
          description: field(name: "Description") {
            value
          }
        }
      }
    }
  }
}

Query Variables:

{
  "searchTerm": "GraphQL",
  "searchRoot": "/sitecore/content/Home/MySampleProject/Home"
}

Pattern C: Complex Field-Based Search

Real-world scenario: Finding products within a specific category and price range.

query ProductSearch {
  search(
    fieldsEqual: [
      {
        name: "Category"
        value: "Electronics"
      }
      {
        name: "InStock"
        value: "1"
      }
    ]
    rootItem: "/sitecore/content/Home/MySampleProject/Home/Products"
) { results { totalCount items { item { id name path url ... on Product { productName: title { value } price { value } category { value } inStock { value } productImage: image { src alt } } } } } } }

Advanced Patterns for Complex Scenarios

Error-Handling Query Pattern

Real-world scenario: You need to ensure your queries gracefully handle missing content.

query SafeContentQuery($contextItem: String!) {
  item(path: $contextItem) {
    id
    name
    template {
      name
    }
    ... on About {
      title {
        value
        ... on TextField {
          value
        }
      }
      # Fallback for missing fields
      subtitle {
        value
      } @skip(if: false)
    }
  }
}

Multi-Language Content Pattern

Real-world scenario: Building a multilingual site with language-specific content.

query MultiLanguageContent($itemPath: String!, $language: String!) {
  item(path: $itemPath, language: $language) {
    id
    name
    language
    ... on About {
      title {
        value
      }
      subtitle {
        value
      }
    }
  }
  
  # Get versions in other languages
  allLanguages: item(path: $itemPath) {
    versions {
      language
      version
    }
  }
}

Performance Optimization Tips from the Trenches

1. Query Only What You Need

# ❌ Avoid: Over-fetching
query BadExample {
  item(path: "/sitecore/content/Home/MySampleProject/Home") {
fields { name value } children { fields { name value } } } } # ✅ Better: Specific field requests query GoodExample { item(path: "/sitecore/content/Home/MySampleProject/Home") {
title { value } description { value } } }

2. Use Fragments for Reusable Patterns

fragment BasicItemInfo on Item {
  id
  name
  path
  url
}

fragment ContentFields on About {
  title {
    value
  }
  subtitle {
    value
  }
  image {
    src
    alt
  }
}

query OptimizedQuery($contextItem: String!) {
  item(path: $contextItem) {
    ...BasicItemInfo
    ...ContentFields
  }
}

Troubleshooting Common Issues

Problem: "Field not found" Errors

Solution: Always check your template inheritance and field names in Sitecore. Use the field inspection query first.

Problem: Empty Results from Search Queries

Solution: Verify your search indexes are up to date and check field value formatting (especially for boolean and date fields).

Problem: Performance Issues with Deep Hierarchies

Solution: Limit nesting levels and use search queries instead of deep children traversals when possible.

Building Your GraphQL Query Library

As you work with these patterns, consider building a team library of commonly used queries. Here's a suggested structure:

/graphql-queries/
├── /components/
│   ├── hero-queries.graphql
│   ├── navigation-queries.graphql
│   └── listing-queries.graphql
├── /search/
│   ├── content-search.graphql
│   └── product-search.graphql
└── /utils/
    ├── field-inspection.graphql
    └── debug-queries.graphql

The Path Forward: From Queries to Solutions

Understanding these query patterns is just the beginning. The real power comes from combining them creatively to solve specific business challenges. Whether you're building a dynamic product catalog, a complex news portal, or an interactive corporate website, these patterns provide the building blocks for success.

Remember, GraphQL in Sitecore isn't just about fetching data – it's about empowering your development team to build more maintainable, performant, and scalable digital experiences. Every query you craft is an investment in your application's future flexibility and your team's productivity.

Your Next Steps

  1. Start with the basics: Master the field inspection and content retrieval patterns
  2. Build incrementally: Add complexity gradually as your comfort level increases
  3. Document your discoveries: Keep notes on query patterns that work well for your specific use cases
  4. Share with your team: Create a shared knowledge base of successful query patterns
  5. Performance test: Always validate that your queries perform well with realistic data volumes

The journey to GraphQL mastery in Sitecore is iterative. Each query you write, each pattern you discover, and each problem you solve adds to your expertise. Your future self – and your entire development team – will thank you for building this foundation of knowledge and practical experience.


Ready to dive deeper? The Sitecore and GraphQL communities are incredibly supportive. Don't hesitate to share your own query discoveries and learn from others who are solving similar challenges.

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.

Monday, September 8, 2025

Supercharging Sitecore with GraphQL: A Developer’s Guide

Introduction

In the dynamic world of web development, efficiency and performance are paramount. One powerful way to achieve both is by integrating GraphQL with Sitecore, a leading enterprise content management system. While GraphQL isn’t new to Sitecore, the advent of Sitecore JavaScript Services (JSS) has made its implementation smoother and more accessible than ever.

This guide walks you through the process of setting up GraphQL in Sitecore, focusing on how to craft effective queries to retrieve content. Whether you're building a new solution or enhancing an existing one, this integration can be a game-changer.


Why GraphQL with Sitecore?

Integrating GraphQL into Sitecore offers a host of benefits:

  • Enhanced Flexibility: Fetch only the data you need—no more, no less.
  • Streamlined Development: Decouple frontend and backend workflows for faster iteration.
  • Improved Performance: Reduce payload sizes and speed up response times.
  • Modern Frontend Compatibility: GraphQL’s schema-based approach aligns perfectly with frameworks like React, Vue.js, and Angular.

Getting Started: Installing JSS and GraphQL

To begin, you’ll need the correct JSS server component package for your Sitecore version. Once identified:

Step 1: Install the JSS Package

  • Open Sitecore in your browser.
  • Navigate to: Desktop → Development Tools → Installation Wizard.
  • Upload and install the JSS package.

This installation will add several components to your Sitecore instance:

  • Configuration files under App_Config (including LayoutService and GraphQL configs).
  • DLLs in the bin folder.
  • JssApp.cshtml view file.
  • Sitecore templates under Foundation and System.

Step 2: Configure GraphQL

After installation:

  1. Go to App_Config\Services.GraphQL.
  2. Rename the file Sitecore.Services.GraphQL.Content.Master.config.example to Sitecore.Services.GraphQL.Content.Master.config.

Step 3: Add and Configure API Key

To query GraphQL via API:

  1. Switch to the Core database.
  2. Navigate to /sitecore/system/Settings/Services/API Keys.
  3. Right-click and insert a new API Key item.

Enable API Key Authentication

Edit the file:
App_Config\Sitecore\Services.GraphQL\Sitecore.Services.GraphQL.config

In the <security> section, enable API Key authentication.


Step 4: Access the GraphQL Browser

Once everything is set up, you can test your queries using the Sitecore GraphQL Browser:

  • URL format:
    https://your-domain/sitecore/api/graph/items/master/ui

If you encounter an “Authentication required” error:

Fix: Add Site-Neutral Path

  1. Open:
    App_Config\Sitecore\Owin.Authentication\Sitecore.Owin.Authentication.config
  2. Locate the <siteNeutralPaths> node.
  3. Add:
    /sitecore/api/graph/items/

Save the file and retry accessing the GraphQL browser.


Step 5: Run Your First Query

Here’s a sample GraphQL query to fetch child items of a context item:

query GQLQuerySamples($contextItem: String!) {
  item(path: $contextItem) {
    children {
      id
      name
    }
  }
}

Important Notes:

  • In the Query Variables section, pass the contextItem path.
  • In the HTTP Headers, include your API Key.

Conclusion

Integrating GraphQL with Sitecore empowers developers to build faster, leaner, and more scalable applications. With precise data fetching, improved performance, and seamless frontend integration, GraphQL is a natural fit for modern Sitecore solutions.

Whether you're a seasoned Sitecore developer or just getting started, embracing GraphQL can elevate your development workflow and deliver richer digital experiences.

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.