1111using EPiServer . ServiceLocation ;
1212using EPiServer . ContentGraph . Helpers . Text ;
1313using EPiServer . ContentGraph . Helpers ;
14+ using EPiServer . ContentGraph . Tracing ;
1415
1516namespace EPiServer . ContentGraph . Api . Querying
1617{
17- public class GraphQueryBuilder : IQuery
18+ public class GraphQueryBuilder : IQuery , ITraceable
1819 {
1920 private readonly IHttpClientFactory _httpClientFactory ;
2021 private readonly HttpClient _httpClient ;
@@ -24,7 +25,9 @@ public class GraphQueryBuilder : IQuery
2425 private const string UnCachedPath = "?cache=false" ;
2526 private Dictionary < string , IFragmentBuilder > _fragmentBuilders ;
2627 private readonly List < string > typeQueries = new List < string > ( ) ;
27- public Action < JsonRequest > RequestActions ;
28+ public Action < OptiGraphOptions > GraphOptionsAction ;
29+
30+ Guid ITraceable . TraceId => Guid . NewGuid ( ) ;
2831
2932 public GraphQueryBuilder ( )
3033 {
@@ -116,6 +119,7 @@ public GraphQueryBuilder OperationName(string op)
116119 }
117120 private string GetServiceUrl ( )
118121 {
122+ UpdateQueryPath ( ) ;
119123 return _optiGraphOptions . GatewayAddress + _optiGraphOptions . QueryPath ;
120124 }
121125 private string GetAuthorization ( string body )
@@ -311,19 +315,22 @@ private void AdditionalInformation(JsonRequest request, string body)
311315 {
312316 request . AddRequestHeader ( "cg-include-deleted" , "true" ) ;
313317 }
314- if ( ! _optiGraphOptions . Cache )
315- {
316- Regex regex = new Regex ( @"\?cache=\w*" ) ;
317- _optiGraphOptions . QueryPath = _optiGraphOptions . QueryPath . Replace ( regex . Match ( _optiGraphOptions . QueryPath ) . Value , UnCachedPath ) ;
318- }
319- //apply actions on request before send
320- ApplyRequestActions ( request ) ;
321318 }
322- internal void ApplyRequestActions ( JsonRequest request )
319+ private void UpdateQueryPath ( )
323320 {
324- if ( RequestActions . IsNotNull ( ) )
321+ Regex regex = new Regex ( @"\?cache=\w*" ) ;
322+ if ( regex . IsMatch ( _optiGraphOptions . QueryPath ) )
325323 {
326- RequestActions ( request ) ;
324+ _optiGraphOptions . QueryPath =
325+ _optiGraphOptions . QueryPath
326+ . Replace ( regex . Match ( _optiGraphOptions . QueryPath ) . Value , $ "?cache={ _optiGraphOptions . Cache } ") ;
327+ }
328+ else
329+ {
330+ _optiGraphOptions . QueryPath = $ "{ _optiGraphOptions . QueryPath } ?cache={ _optiGraphOptions . Cache } ";
331+ }
332+ if ( GraphOptionsAction . IsNotNull ( ) ) {
333+ GraphOptionsAction ( _optiGraphOptions ) ;
327334 }
328335 }
329336 public void AddQuery ( string typeQuery )
0 commit comments