Problem statement :
We are on Sitecore 10.2 and using an Edge connector using version 20.0 and headless services 20.0 During the implementation of our customer’s project we found this scenario where we had to use our local development to test various GraphQL queries locally before promoting to higher environments as those use cases had business logic to execute.
What we found is inconsistency in local edge endpoint GraphQL queries which are limited to only ‘Sitecore/Content’ and anything outside the ‘Content’ folder was returning null, whereas when we test with Edge GraphQL endpoint (not local) it was returning expected data.
Below is a snapshot of query to the media item using the local endpoint.
Below is a snapshot of query to the media item using the edge endpoint.
Description / Root cause:
The first thing which comes to mind is our local development environment is not set up as expected and/or configuration issue. But after verifying those were not true had to take the reverse engineering process and that’s deep dive into GraphQL EdgeSchema dll.
So what it revealed was “/Sitecore/Content” is indeed hardcoded in the FilterItem method. So just believe these are PreviewAPI’s which are hosted on Sitecore XM, however, Delivery APIs on Experience edge do support querying outside the content folder.
Resolution:
Sitecore ticket is already raised and waiting for Sitecore to review and provide a patch for it. Until then let’s see how we fixed it with a simple patch.
As with every patch we have experienced before, we would need a config file to point to our custom code and class file with logic that overrides the default behavior of the FilterItem method (In our scenario).
Class file – Create a class file at the preferred location in your project (considering my class name as CustomItemQuery). Override FilterItem as below code.
public class CustomItemQuery : Sitecore.Services.GraphQL.EdgeSchema.Queries.ItemQuery
{
protected override bool FilterItem(Item item)
{
return !item.Paths.FullPath.StartsWith("/sitecore") && !item.ID.Equals(ItemIDs.RootID);
}
}
Config file – Create a patch config file under App_config. Link your assembly and class name as shown below patch.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore>
<api>
<graphql>
<defaults>
<content>
<schemaproviders>
<edgecontent>
<queries hint="raw:AddQuery">
<query name="item" role:require="Standalone">
<patch:attribute name="type">Sitecore.Demo.Edge.Foundation.KnownIssues.CustomItemQuery, Sitecore.Demo.Edge.Foundation.KnownIssues</patch:attribute>
</query>
</queries>
</edgecontent>
</schemaproviders>
</content>
</defaults>
</graphql>
</api>
</sitecore>
</configuration>
Once you have that deployed you could now query and verify on edge playground UI or postman.
Check Experience Edge Issue or Serialization Issue to see if you had faced it and find a resolution to it.