11
11
using EPiServer . ServiceLocation ;
12
12
using EPiServer . ContentGraph . Helpers . Text ;
13
13
using EPiServer . ContentGraph . Helpers ;
14
+ using EPiServer . ContentGraph . Tracing ;
14
15
15
16
namespace EPiServer . ContentGraph . Api . Querying
16
17
{
17
- public class GraphQueryBuilder : IQuery
18
+ public class GraphQueryBuilder : IQuery , ITraceable
18
19
{
19
20
private readonly IHttpClientFactory _httpClientFactory ;
20
21
private readonly HttpClient _httpClient ;
@@ -24,7 +25,9 @@ public class GraphQueryBuilder : IQuery
24
25
private const string UnCachedPath = "?cache=false" ;
25
26
private Dictionary < string , IFragmentBuilder > _fragmentBuilders ;
26
27
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 ( ) ;
28
31
29
32
public GraphQueryBuilder ( )
30
33
{
@@ -116,6 +119,7 @@ public GraphQueryBuilder OperationName(string op)
116
119
}
117
120
private string GetServiceUrl ( )
118
121
{
122
+ UpdateQueryPath ( ) ;
119
123
return _optiGraphOptions . GatewayAddress + _optiGraphOptions . QueryPath ;
120
124
}
121
125
private string GetAuthorization ( string body )
@@ -311,19 +315,22 @@ private void AdditionalInformation(JsonRequest request, string body)
311
315
{
312
316
request . AddRequestHeader ( "cg-include-deleted" , "true" ) ;
313
317
}
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 ) ;
321
318
}
322
- internal void ApplyRequestActions ( JsonRequest request )
319
+ private void UpdateQueryPath ( )
323
320
{
324
- if ( RequestActions . IsNotNull ( ) )
321
+ Regex regex = new Regex ( @"\?cache=\w*" ) ;
322
+ if ( regex . IsMatch ( _optiGraphOptions . QueryPath ) )
325
323
{
326
- RequestActions ( request ) ;
324
+ _optiGraphOptions . QueryPath =
325
+ _optiGraphOptions . QueryPath
326
+ . Replace ( regex . Match ( _optiGraphOptions . QueryPath ) . Value , $ "?cache={ _optiGraphOptions . Cache . ToString ( ) . ToLower ( ) } ") ;
327
+ }
328
+ else
329
+ {
330
+ _optiGraphOptions . QueryPath = $ "{ _optiGraphOptions . QueryPath } ?cache={ _optiGraphOptions . Cache . ToString ( ) . ToLower ( ) } ";
331
+ }
332
+ if ( GraphOptionsAction . IsNotNull ( ) ) {
333
+ GraphOptionsAction ( _optiGraphOptions ) ;
327
334
}
328
335
}
329
336
public void AddQuery ( string typeQuery )
0 commit comments