Skip to content

Commit

Permalink
Allow TransformAction to clone options
Browse files Browse the repository at this point in the history
When the client is used to query different graph
sources the transform action passed to
CreateFromConfig can be used to manipulate the
keys sent. However the changes are applied to the
global options and doesnt reset after the client
has finished its query.

By introducing a behaviour it is possible to
dictatate if the developer wants to be able to
apply the transformation on a clone of the
options.

The default behaviour is that the current behavior
where the options are global.
  • Loading branch information
DeepRed authored and ManhOptimizely committed Dec 16, 2024
1 parent 330133f commit af7e021
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public static GraphQueryBuilder CreateFromConfig(Action<OptiGraphOptions> transf
var httpClientFactory = ServiceLocator.Current.GetService(typeof(IHttpClientFactory)) as IHttpClientFactory;
if (transformAction != null)
{
if (options.TransformActionBehaviour == TransformActionBehaviour.Clone)
{
var clonedOptions = (OptiGraphOptions)options.Clone();
transformAction(clonedOptions);

return new GraphQueryBuilder(clonedOptions, httpClientFactory);
}

transformAction(options);
}
if (options != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace EPiServer.ContentGraph.Configuration
{
[Options]
public class OptiGraphOptions
public class OptiGraphOptions : ICloneable
{
public const string ConfigSection = "Optimizely:ContentGraph";

Expand Down Expand Up @@ -57,5 +57,12 @@ public string Authorization
return $"epi-single {SingleKey}";
}
}

public TransformActionBehaviour TransformActionBehaviour { get; set; }

public object Clone()
{
return this.MemberwiseClone();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EPiServer.ContentGraph.Configuration
{
/// <summary>
/// Configures how OptiGraphOptions should handle the output of TransformAction when creating options
/// </summary>
public enum TransformActionBehaviour
{
/// <summary>
/// Default, transform action changes the global options
/// </summary>
Default,
/// <summary>
/// Clone, transform action clones the options and applies transformation only on the clone
/// </summary>
Clone
}
}

0 comments on commit af7e021

Please sign in to comment.