22using GraphQL ;
33using GraphQL . Client . Abstractions ;
44using Microsoft . Extensions . Logging ;
5+ using Sitecore . AspNetCore . SDK . GraphQL . Request ;
56using Sitecore . AspNetCore . SDK . LayoutService . Client . Exceptions ;
67using Sitecore . AspNetCore . SDK . LayoutService . Client . Interfaces ;
78using Sitecore . AspNetCore . SDK . LayoutService . Client . Request ;
1011using Sitecore . AspNetCore . SDK . LayoutService . Client . Response . Model ;
1112using Sitecore . AspNetCore . SDK . LayoutService . Client . Serialization ;
1213using Sitecore . AspNetCore . SDK . LayoutService . Client . Serialization . Fields ;
13- using Sitecore . AspNetCore . SDK . Pages . GraphQL ;
1414using Sitecore . AspNetCore . SDK . Pages . Properties ;
1515using Sitecore . AspNetCore . SDK . Pages . Services ;
1616
@@ -20,17 +20,17 @@ namespace Sitecore.AspNetCore.SDK.Pages.Request.Handlers.GraphQL;
2020/// <summary>
2121/// Initializes a new instance of the <see cref="GraphQLEditingServiceHandler"/> class.
2222/// </summary>
23+ /// <param name="client">The GraphQL Client used for requests</param>
2324/// <param name="logger">The <see cref="ILogger"/> to use for logging.</param>
2425/// <param name="dictionaryService">DictionaryService used to return all dictionary items for a Sitecore site.</param>
25- /// <param name="clientFactory">The GraphQlClientFactory used to generate instances of the GraphQl client.</param>
2626/// <param name="serializer">The serializer to handle response data.</param>
27- public partial class GraphQLEditingServiceHandler ( IGraphQLClientFactory clientFactory ,
27+ public partial class GraphQLEditingServiceHandler ( IGraphQLClient client ,
2828 ISitecoreLayoutSerializer serializer ,
2929 ILogger < GraphQLEditingServiceHandler > logger ,
3030 IDictionaryService dictionaryService )
3131 : ILayoutRequestHandler
3232{
33- private readonly IGraphQLClientFactory clientFactory = clientFactory ?? throw new ArgumentNullException ( nameof ( clientFactory ) ) ;
33+ private readonly IGraphQLClient client = client ?? throw new ArgumentNullException ( nameof ( client ) ) ;
3434 private readonly ISitecoreLayoutSerializer serializer = serializer ?? throw new ArgumentNullException ( nameof ( serializer ) ) ;
3535 private readonly ILogger < GraphQLEditingServiceHandler > logger = logger ?? throw new ArgumentNullException ( nameof ( logger ) ) ;
3636 private readonly IDictionaryService dictionaryService = dictionaryService ?? throw new ArgumentNullException ( nameof ( dictionaryService ) ) ;
@@ -267,7 +267,7 @@ private static string GetRequestArgValue(SitecoreLayoutRequest request, string a
267267 return headers [ argName ] . FirstOrDefault ( ) ?? string . Empty ;
268268 }
269269
270- private static GraphQLRequest BuildEditingLayoutRequest ( SitecoreLayoutRequest request , string requestLanguage )
270+ private static GraphQLHttpRequestWithHeaders BuildEditingLayoutRequest ( SitecoreLayoutRequest request , string requestLanguage )
271271 {
272272 return new ( )
273273 {
@@ -288,14 +288,19 @@ query EditingQuery(
288288 itemId = GetRequestArgValue ( request , "sc_itemid" ) ,
289289 language = requestLanguage ,
290290 version = GetRequestArgValue ( request , "sc_version" )
291+ } ,
292+ Headers = new Dictionary < string , string >
293+ {
294+ { "sc_layoutKind" , GetRequestArgValue ( request , "sc_layoutKind" ) } ,
295+ { "sc_editmode" , ( GetRequestArgValue ( request , "mode" ) == "edit" ) . ToString ( ) }
291296 }
292297 } ;
293298 }
294299
295300 private async Task < SitecoreLayoutResponseContent ? > HandleEditingLayoutRequest ( SitecoreLayoutRequest request , string requestLanguage , List < SitecoreLayoutServiceClientException > errors )
296301 {
297- IGraphQLClient client = clientFactory . GenerateClient ( GetRequestArgValue ( request , "sc_layoutKind" ) , GetRequestArgValue ( request , "mode" ) == "edit" ) ;
298302 GraphQLResponse < EditingLayoutQueryResponse > response = await client . SendQueryAsync < EditingLayoutQueryResponse > ( BuildEditingLayoutRequest ( request , requestLanguage ) ) . ConfigureAwait ( false ) ;
303+
299304 if ( response ? . Data == null )
300305 {
301306 throw new Exception ( Resources . Exception_UableToProcessEditingResponse ) ;
0 commit comments