Skip to content

Commit 606a1d5

Browse files
authored
Added Operation Plan Formatter (#8475)
1 parent ee723de commit 606a1d5

File tree

93 files changed

+2302
-1051
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2302
-1051
lines changed

src/HotChocolate/Core/src/Execution.Abstractions/Execution/ExecutionResult.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using HotChocolate.Features;
2+
13
namespace HotChocolate.Execution;
24

35
/// <summary>
@@ -23,6 +25,9 @@ protected ExecutionResult(Func<ValueTask>[] cleanupTasks)
2325
/// <inheritdoc cref="IExecutionResult" />
2426
public abstract IReadOnlyDictionary<string, object?>? ContextData { get; }
2527

28+
/// <inheritdoc cref="IFeatureProvider" />
29+
public IFeatureCollection Features { get; } = new FeatureCollection();
30+
2631
private protected Func<ValueTask>[] CleanupTasks => _cleanupTasks;
2732

2833
/// <inheritdoc cref="IExecutionResult" />

src/HotChocolate/Core/src/Execution.Abstractions/Execution/IExecutionResult.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using HotChocolate.Features;
2+
13
namespace HotChocolate.Execution;
24

35
/// <summary>
@@ -8,7 +10,7 @@ namespace HotChocolate.Execution;
810
/// them allows it to give back its used memory to the execution
911
/// engine result pools.
1012
/// </remarks>
11-
public interface IExecutionResult : IAsyncDisposable
13+
public interface IExecutionResult : IFeatureProvider, IAsyncDisposable
1214
{
1315
/// <summary>
1416
/// Gets the result kind.

src/HotChocolate/Core/src/Features/FeatureCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ public IEnumerator<KeyValuePair<Type, object>> GetEnumerator()
179179

180180
private sealed class KeyComparer : IEqualityComparer<KeyValuePair<Type, object>>
181181
{
182-
public bool Equals(KeyValuePair<Type, object> x, KeyValuePair<Type, object> y) =>
183-
x.Key.Equals(y.Key);
182+
public bool Equals(KeyValuePair<Type, object> x, KeyValuePair<Type, object> y)
183+
=> x.Key.Equals(y.Key);
184184

185185
public int GetHashCode(KeyValuePair<Type, object> obj) =>
186186
obj.Key.GetHashCode();

src/HotChocolate/Fusion-vnext/src/Fusion.AspNetCore/DependencyInjection/FusionServerServiceCollectionExtensions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,35 @@ private static IFusionGatewayBuilder AddGraphQLGatewayServerCore(
6565
return builder;
6666
}
6767

68+
public static IFusionGatewayBuilder AddHttpRequestInterceptor<T>(
69+
this IFusionGatewayBuilder builder)
70+
where T : IHttpRequestInterceptor, new()
71+
{
72+
ArgumentNullException.ThrowIfNull(builder);
73+
74+
return builder.ConfigureSchemaServices(
75+
(_, s) =>
76+
{
77+
s.RemoveAll<IHttpRequestInterceptor>();
78+
s.AddSingleton<IHttpRequestInterceptor>(new T());
79+
});
80+
}
81+
82+
public static IFusionGatewayBuilder AddHttpRequestInterceptor(
83+
this IFusionGatewayBuilder builder,
84+
Func<IServiceProvider, IHttpRequestInterceptor> factory)
85+
{
86+
ArgumentNullException.ThrowIfNull(builder);
87+
ArgumentNullException.ThrowIfNull(factory);
88+
89+
return builder.ConfigureSchemaServices(
90+
(_, s) =>
91+
{
92+
s.RemoveAll<IHttpRequestInterceptor>();
93+
s.AddSingleton(factory);
94+
});
95+
}
96+
6897
private static IFusionGatewayBuilder AddDefaultHttpRequestInterceptor(
6998
this IFusionGatewayBuilder builder)
7099
=> builder.ConfigureSchemaServices(

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/Extensions/FusionRequestContextExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class FusionRequestContextExtensions
1919
/// The request context.
2020
/// </param>
2121
/// <returns>
22-
/// The <see cref="OperationExecutionPlan"/> if it exists, otherwise <c>null</c>.
22+
/// The <see cref="OperationPlan"/> if it exists, otherwise <c>null</c>.
2323
/// </returns>
2424
public static string GetOperationId(
2525
this RequestContext context)
@@ -37,15 +37,15 @@ public static string GetOperationId(
3737
}
3838

3939
/// <summary>
40-
/// Gets the <see cref="OperationExecutionPlan"/> from the request context.
40+
/// Gets the <see cref="OperationPlan"/> from the request context.
4141
/// </summary>
4242
/// <param name="context">
4343
/// The request context.
4444
/// </param>
4545
/// <returns>
46-
/// The <see cref="OperationExecutionPlan"/> if it exists, otherwise <c>null</c>.
46+
/// The <see cref="OperationPlan"/> if it exists, otherwise <c>null</c>.
4747
/// </returns>
48-
public static OperationExecutionPlan? GetOperationPlan(
48+
public static OperationPlan? GetOperationPlan(
4949
this RequestContext context)
5050
{
5151
ArgumentNullException.ThrowIfNull(context);
@@ -73,7 +73,7 @@ public static void SetOperationId(
7373
}
7474

7575
/// <summary>
76-
/// Sets the <see cref="OperationExecutionPlan"/> on the request context.
76+
/// Sets the <see cref="OperationPlan"/> on the request context.
7777
/// </summary>
7878
/// <param name="context">
7979
/// The request context.
@@ -83,7 +83,7 @@ public static void SetOperationId(
8383
/// </param>
8484
public static void SetOperationPlan(
8585
this RequestContext context,
86-
OperationExecutionPlan plan)
86+
OperationPlan plan)
8787
{
8888
ArgumentNullException.ThrowIfNull(context);
8989
ArgumentNullException.ThrowIfNull(plan);

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/FusionOperationInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal sealed class FusionOperationInfo : RequestFeature
77
{
88
public string? OperationId { get; set; }
99

10-
public OperationExecutionPlan? OperationPlan { get; set; }
10+
public OperationPlan? OperationPlan { get; set; }
1111

1212
protected override void Reset()
1313
{

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/FusionRequestExecutorManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private static void AddOperationPlanner(IServiceCollection services)
300300
static sp =>
301301
{
302302
var options = sp.GetRequiredService<ISchemaDefinition>().GetRequestOptions();
303-
return new Cache<OperationExecutionPlan>(
303+
return new Cache<OperationPlan>(
304304
options.OperationExecutionPlanCacheSize,
305305
options.OperationExecutionPlanCacheDiagnostics);
306306
});

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/FusionRequestOptions.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public sealed class FusionRequestOptions : ICloneable
1010
private CacheDiagnostics? _operationExecutionPlanCacheDiagnostics;
1111
private int _operationDocumentCacheSize = 256;
1212
private int _sourceSchemaOperationCacheSize = 256;
13+
private bool _collectOperationPlanTelemetry;
1314
private bool _isReadOnly;
1415

1516
/// <summary>
@@ -99,6 +100,20 @@ public int SourceSchemaOperationCacheSize
99100
}
100101
}
101102

103+
public bool CollectOperationPlanTelemetry
104+
{
105+
get => _collectOperationPlanTelemetry;
106+
set
107+
{
108+
if (_isReadOnly)
109+
{
110+
throw new InvalidOperationException("The request options are read-only.");
111+
}
112+
113+
_collectOperationPlanTelemetry = value;
114+
}
115+
}
116+
102117
/// <summary>
103118
/// Clones the request options into a new mutable instance.
104119
/// </summary>
@@ -111,6 +126,9 @@ public FusionRequestOptions Clone()
111126
clone._executionTimeout = _executionTimeout;
112127
clone._operationExecutionPlanCacheSize = _operationExecutionPlanCacheSize;
113128
clone._operationExecutionPlanCacheDiagnostics = _operationExecutionPlanCacheDiagnostics;
129+
clone._operationDocumentCacheSize = _operationDocumentCacheSize;
130+
clone._sourceSchemaOperationCacheSize = _sourceSchemaOperationCacheSize;
131+
clone._collectOperationPlanTelemetry = _collectOperationPlanTelemetry;
114132
return clone;
115133
}
116134

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
using System.Diagnostics;
2+
13
namespace HotChocolate.Fusion.Execution.Nodes;
24

3-
public record ExecutionNodeResult(int Id, ExecutionStatus Status, TimeSpan Duration);
5+
public record ExecutionNodeResult(
6+
int Id,
7+
Activity? Activity,
8+
ExecutionStatus Status,
9+
TimeSpan Duration,
10+
Exception? Exception = null);

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/Nodes/IntrospectionExecutionNode.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@ public sealed class IntrospectionExecutionNode : ExecutionNode
99

1010
public IntrospectionExecutionNode(int id, Selection[] selections)
1111
{
12+
ArgumentNullException.ThrowIfNull(selections);
13+
14+
if (selections.Length == 0)
15+
{
16+
throw new ArgumentException(
17+
"There must be at least one introspection selection.",
18+
nameof(selections));
19+
}
20+
1221
Id = id;
1322
_selections = selections;
1423
}
1524

1625
public override int Id { get; }
1726

27+
public ReadOnlySpan<Selection> Selections => _selections;
28+
1829
public override ReadOnlySpan<ExecutionNode> Dependencies => default;
1930

2031
public override Task<ExecutionNodeResult> ExecuteAsync(
@@ -43,7 +54,12 @@ public override Task<ExecutionNodeResult> ExecuteAsync(
4354
ExecuteSelections(context, backlog);
4455
context.AddPartialResults(root, _selections);
4556

46-
return Task.FromResult(new ExecutionNodeResult(Id, ExecutionStatus.Success, Stopwatch.GetElapsedTime(start)));
57+
return Task.FromResult(
58+
new ExecutionNodeResult(
59+
Id,
60+
Activity.Current,
61+
ExecutionStatus.Success,
62+
Stopwatch.GetElapsedTime(start)));
4763
}
4864

4965
private static void ExecuteSelections(

0 commit comments

Comments
 (0)