2

Environment:

Sitecore 10.2 XM/ 10.3 XP

Headless 20/Headless 21

Problem

After populating the Component GraphQL Query field for a Json Rendering with a specific GraphQL query, we anticipate that the layout service response should adjust to reflect this query. Our goal is to limit the fields returned from the datasource item in the layout service response, rather than receiving all fields. However, this functionality is currently not operating as expected.

We've verified that this functionality works correctly in another Sitecore instance using an SXA JSS app

Is there something I'm missing? Are there any specific configurations needed in the config files or elsewhere? Please advise if any additional steps are required..

2 Answers 2

3

In order for the rendering to support Component GraphQL Query, make sure the following things are in place.

  1. There is app configuration defined for the site as below defined under the sitecore\javaScriptServices\apps section.
<app name="{{JSS_AppName}}"
     layoutServiceConfiguration="default"
     sitecorePath="{{Site_RootPath}}"
     useLanguageSpecificLayout="true"
     graphQLEndpoint="/sitecore/api/graph/edge"
     inherits="defaults"
     serverSideRenderingEngine="http"
     serverSideRenderingEngineEndpointUrl=""
     serverSideRenderingEngineApplicationUrl=""
        />
  1. The site root item inherits from the /sitecore/templates/Foundation/JavaScript Services/App template.

enter image description here

Using above changes, Component GraphQL Query field in the rendering will work as expected.

Hope this helps!!! Let me know in case you face any issues.

2

Finally I have some potential workaround for this issue involves creating a custom resolver in the content tree. Follow these steps:

  1. Navigate to: /sitecore/system/Modules/Layout Service/Rendering Contents Resolvers

  2. Create a new resolver item.

enter image description here

  1. Set the Type field to:
Sitecore.LayoutService.GraphQL.LayoutService.GraphQLAwareRenderingContentsResolver, Sitecore.LayoutService.GraphQL
  1. Assign this new Rendering Content Resolver to any Json Rendering that uses GraphQL to shape the Component response in the Layout Service.

This approach should allow the resolver to handle GraphQL queries correctly. However, this manual configuration shouldn't be necessary - the GraphQL-aware resolver should be the default. But this approach worked for me.

learnt something new 🙂...

1
  • You dont have to create a rendering content resolver item with type GraphQLAwareRenderingContentsResolver as its the default resolver type for the layoutservice configuration named "jss". The above solution mentioned should fix your issue also check the layout service url you are using
    – Anandarup
    Commented Aug 8 at 10:42

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.