2

Environment:

  • Sitecore 10.2 XM
  • Headless 20
  • SXA 10.2
  • SPE 6.3

Problem

When I fill in the Component GraphQL Query field for a Json Rendering with something simple like this:

Component GraphQL Query field

query IntegrationQuery($contextItem:String!, $datasource:String!, $language: String!) {
  item(path: $contextItem, language: $language) {
     displayName
  } 
}

Expected Results

I expect that query to shape the Layout Service response when I retrieve a route layout with that rendering in the presentation details. I imagine the response would look something like this:

"jss-main": [{
 "uid": "c56a8699-5e33-4c04-bcab-ce57642e05e4",
 "componentName": "locations",
 "dataSource": "",
 "data" : {
   "item": {
     "displayName": "Chicago"
   }
 }
}]

Actual Results

Instead, I got an empty component that looks like this:

"jss-main": [{
 "uid": "c56a8699-5e33-4c04-bcab-ce57642e05e4",
 "componentName": "locations",
 "dataSource": ""
}]

Assumptions & Troubleshooting Attempted

  1. I assume that the Sitecore.LayoutService.GraphQL.LayoutService.GraphQLAwareRenderingContentsResolver is responsible for injecting the GraphQL response into the rendering's Json output.

  2. I noticed that this resolver is patched in for the default LayoutService configuration

    <sitecore>
     <layoutService>
       <configurations>
         <config name="default">
           <rendering>
             <renderingContentsResolver set:type="Sitecore.LayoutService.GraphQL.LayoutService.GraphQLAwareRenderingContentsResolver, Sitecore.LayoutService.GraphQL" resolve="true" />
           </rendering>
         </config>
       </configurations>
     </layoutService>
    </sitecore>
    

    Since my site is using SXA and is configured with the sxa-jss Layout Service configuration, I also patched this resolver for this configuration. No Luck :(

    SXA Site Configuration

  3. I also patched this resolver into the jss Layout Service configuration. Still No Luck

  4. I've reviewed the Sitecore logs on both CM and CD. No errors related to the Layout Service or the GraphQLAware Content Resolver.

In Summary

I've combed through the Sitecore docs looking for more information on how this field is supposed to work and cannot figure out what I'm doing wrong.

Update: Workaround

I've identified a workaround that might help others with the same problem. You can create your own 'custom' resolver in the content tree under: /sitecore/system/Modules/Layout Service/Rendering Contents Resolvers

Make sure that the Type field is set to: Sitecore.JavaScriptServices.GraphQL.LayoutService.GraphQLAwareRenderingContentsResolver, Sitecore.JavaScriptServices.GraphQL

GraphQL Aware Rendering Contents Resolver

Once this is set, you can assign this Rendering Content Resolver to any Json Rendering that uses GraphQL to shape the Component response in the Layout Service.

The expectation is that this resolver should be the default and this extra configuration is not required. Working with Sitecore Support to get to the root cause.

1
  • 1
    Does it make sense to post your work around as an Answer, instead of an embed in your Question? Aug 1, 2022 at 18:51

2 Answers 2

1

Workaround

The expectation is that the GraphQLAwareRenderingContentsResolver should be the default for any Json Renderings.

With that said, I've identified a workaround that might help others with the same problem. You can create your own 'custom' resolver in the content tree under: /sitecore/system/Modules/Layout Service/Rendering Contents Resolvers

Make sure that the Type field is set to: Sitecore.JavaScriptServices.GraphQL.LayoutService.GraphQLAwareRenderingContentsResolver, Sitecore.JavaScriptServices.GraphQL

GraphQL Aware Rendering Contents Resolver

Once this is set, you can assign this Rendering Content Resolver to any Json Rendering that uses GraphQL to shape the Component response in the Layout Service.

1

Had the same issue and found another solution (to what probably is a bug - still working with Sitecore support on that). Based on what Chet already found I checked my config and noticed I had 2 resolvers in the default config.

Playing around with those learned me that the second one was used. So I decided to switch them around and that seems to do the trick as well. This way I don't have to set the resolver on all the renderings.

<layoutService>
    <configurations>
        <config name="default">
          <rendering>
              <renderingContentsResolver type="Sitecore.LayoutService.GraphQL.LayoutService.GraphQLAwareRenderingContentsResolver, Sitecore.LayoutService.GraphQL">
                <patch:delete />
              </renderingContentsResolver>
              <renderingContentsResolver type="Sitecore.LayoutService.GraphQL.LayoutService.GraphQLAwareRenderingContentsResolver, Sitecore.LayoutService.GraphQL" resolve="true" patch:after="renderingContentsResolver[@type='Sitecore.LayoutService.ItemRendering.ContentsResolvers.RenderingContentsResolver, Sitecore.LayoutService']">
                <IncludeServerUrlInMediaUrls>false</IncludeServerUrlInMediaUrls>
              </renderingContentsResolver>
           </rendering>
         </config>
     </configurations>
 </layoutService>

Edit: I did receive feedback from Sitecore that this is indeed a (known) bug and it can be fixed this way - or you can install the latest SXA hotfix which would solve it as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.