Ok, having spent some time trying to figure out how this whole thing works in Sitecore, I can now say, that SXA-JSS does not support integrated GQL.
The problem lies in the sxa-jss configuration for the LayoutService
, which is selected by default when you create a new SXA JSS site.
The configuration above comes from this file: \App_Config\Modules\JSS SXA\Foundation\Sitecore.XA.JSS.Foundation.Presentation.config
In that file Sitecore uses Sitecore.XA.JSS.Foundation.Presentation.ContentsResolvers.RenderingContentsResolver, Sitecore.XA.JSS.Foundation.Presentation
as the renderingContentResolver
and if you disassemble the class, you'll see that it does not execute any GQL at all!
From here you have two options:
- Create a patch file to replace that class in
configuration/sitecore/layoutservice/configurations/config[@name="sxa-jss"]/rendering/renderingContentsResolver[@type="Sitecore.XA.JSS.Foundation.Presentation.ContentsResolvers.RenderingContentsResolver, Sitecore.XA.JSS.Foundation.Presentation"]
with a content resolver that is GQL aware, i.e.: Sitecore.JavaScriptServices.GraphQL.LayoutService.GraphQLAwareRenderingContentsResolver, Sitecore.JavaScriptServices.GraphQL
, or
- In the settings of your SXA JSS site, change the
layoutServiceConfiguration
to jss
(instead of the default sxa-jss).
The only thing that the SXA ContentResolver does is that it injects the DisableEditing flag and makes sure that the Media.AlwaysIncludeServerUrl setting is respected in your JSON output, so patching it or replacing the configuration with JSS should not do any more harm.
Either way, I've reached out to Sitecore to have them comment on the problem. Once I get their feedback, I'll update my reply.
UPD:
Sitecore came back with an answer confirming that the sxa-jss configuration does not support running integrated GQL queries and this is by design. They added this configuration for compatibility reasons and said that it should not be used for JSS apps. Instead, if you have a JSS app, you need to switch it to the jss layoutServiceConfiguration
:
The 'sxa-jss' was added to allow the compatibility between SXA and JSS.
However, you should use 'jss' layout service configuration for JSS apps.
As I mentioned, this configuration should be set by default in >Sitecore.JavaScriptServices.Apps.config for default JSS app.
All you custom JSS apps should by default inherit this default app and all >attributes that are not overridden directly.