while working recently on an XM Cloud project, I ran into issue with GraphQL we were preparing to pull the header component data source, basically when we execute the query in the GraphQL playground we get ""Query is too nested to execute. Depth is 17 levels, maximum allowed on this endpoint is 15." Error, if you want to know how to resolve this, keep reading!
While working on a header component, we were preparing a GraphQL query to pull the header datasource information from Sitecore and be used for the header component, following is our GraphQL query:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query LayoutService { | |
header: item(path: "{7599BF56-A288-4288-A04C-6EE208BA1F7A}", language: "en") { | |
name | |
... on Header { | |
image { | |
jsonValue | |
} | |
utilityLinks { | |
targetItem { | |
hasChildren | |
links: children(includeTemplateIDs: ["{635DEBA3-03D4-4C06-AB43-2339C3E84D57}"]) { | |
results { | |
... on UtilityLink { | |
isLogin { | |
jsonValue | |
} | |
link { | |
jsonValue | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
mainNavigationItems: children(includeTemplateIDs: ["{6DA114C1-FB9D-41B2-92B3-AFEB3234F871}"]) { | |
results { | |
... on MainNavigation { | |
id | |
title { | |
value | |
} | |
link { | |
jsonValue | |
} | |
featuredHeaderCard { | |
targetItem { | |
... on FeaturedHeaderCard { | |
title { | |
jsonValue | |
} | |
image { | |
jsonValue | |
} | |
copy { | |
jsonValue | |
} | |
} | |
} | |
} | |
} | |
subNavs: children(includeTemplateIDs: ["{A1915165-6029-4BD8-8916-F6E8C3F1C6FC}"]) { | |
results { | |
... on SubNavigation { | |
id | |
title { | |
value | |
} | |
} | |
links: children(includeTemplateIDs: ["{E24E0789-A058-48BF-ABB6-C69C0E60B6B7}"]) { | |
results { | |
... on Link_e24e0789a05848bfabb6c69c0e60b6b7 { | |
id | |
link { | |
jsonValue | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
So how to resolve? the fix for this is basically to increase the max depth attribute in the complexity configuration under the public service for the GraphQL, see the following patch:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<sitecore xmlns:patch="http://www.sitecore.net/xmlconfig/" database="SqlServer"> | |
<api patch:source="Sitecore.Services.Client.config"> | |
<GraphQL> | |
<defaults> | |
<security> | |
<publicService type="Sitecore.Services.GraphQL.Hosting.Security.GraphQLSecurity, Sitecore.Services.GraphQL"> | |
<complexityConfiguration type="GraphQL.Validation.Complexity.ComplexityConfiguration, GraphQL"> | |
<maxDepth>35</maxDepth> | |
</complexityConfiguration> | |
</publicService> | |
</security> | |
</defaults> | |
</GraphQL> | |
</api> | |
</sitecore> |
Hopefully this will help someone and save you some time. while going through my first XM Cloud I will continue to share my experiences. stay around!
No comments:
Post a Comment