Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -386,19 +386,19 @@ private static int ResolveVariableIndex(
private static bool TryGetResultPath(
SourceSchemaClientRequest request,
int variableIndex,
out Path path,
out ImmutableArray<Path> additionalPaths)
out CompactPath path,
out ImmutableArray<CompactPath> additionalPaths)
{
if (request.Variables.Length == 0)
{
path = Path.Root;
path = CompactPath.Root;
additionalPaths = [];
return true;
}

if ((uint)variableIndex >= (uint)request.Variables.Length)
{
path = Path.Root;
path = CompactPath.Root;
additionalPaths = [];
return false;
}
Expand Down Expand Up @@ -489,8 +489,8 @@ private void WriteResultToChannel(
OperationPlanContext context,
ExecutionNode node,
NodeResponse nodeResponse,
Path path,
ImmutableArray<Path> additionalPaths,
CompactPath path,
ImmutableArray<CompactPath> additionalPaths,
SourceResultDocument document)
{
var sourceSchemaResult = additionalPaths.IsDefaultOrEmpty
Expand Down Expand Up @@ -561,7 +561,7 @@ public override async IAsyncEnumerable<SourceSchemaResult> ReadAsResultStreamAsy
{
await foreach (var result in response.ReadAsResultStreamAsync().WithCancellation(cancellationToken))
{
var sourceSchemaResult = new SourceSchemaResult(Path.Root, result);
var sourceSchemaResult = new SourceSchemaResult(CompactPath.Root, result);

configuration.OnSourceSchemaResult?.Invoke(context, node, sourceSchemaResult);

Expand All @@ -575,7 +575,7 @@ public override async IAsyncEnumerable<SourceSchemaResult> ReadAsResultStreamAsy
case 0:
{
var result = await response.ReadAsResultAsync(cancellationToken);
var sourceSchemaResult = new SourceSchemaResult(Path.Root, result);
var sourceSchemaResult = new SourceSchemaResult(CompactPath.Root, result);

configuration.OnSourceSchemaResult?.Invoke(context, node, sourceSchemaResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@ public sealed class SourceSchemaResult : IDisposable
/// <param name="final">Whether this is the final message in a streaming response.</param>
/// <param name="additionalPaths">Any additional paths where this result should also be merged.</param>
public SourceSchemaResult(
Path path,
CompactPath path,
SourceResultDocument document,
FinalMessage final = FinalMessage.Undefined,
ImmutableArray<Path> additionalPaths = default)
ImmutableArray<CompactPath> additionalPaths = default)
: this(path, document, final, ownsDocument: true, additionalPaths)
{
}

private SourceSchemaResult(
Path path,
CompactPath path,
SourceResultDocument document,
FinalMessage final,
bool ownsDocument,
ImmutableArray<Path> additionalPaths)
ImmutableArray<CompactPath> additionalPaths)
{
ArgumentNullException.ThrowIfNull(path);
ArgumentNullException.ThrowIfNull(document);

_document = document;
Expand All @@ -54,13 +53,13 @@ private SourceSchemaResult(
/// <summary>
/// The primary path in the composite result into which this source schema result will be merged.
/// </summary>
public Path Path { get; }
public CompactPath Path { get; }

/// <summary>
/// Additional paths where this result should also be merged, used when a single source
/// schema response satisfies multiple selection sets at different locations.
/// </summary>
public ImmutableArray<Path> AdditionalPaths { get; }
public ImmutableArray<CompactPath> AdditionalPaths { get; }

/// <summary>
/// The <c>data</c> element of the source schema response, or an empty element if the
Expand Down Expand Up @@ -132,7 +131,7 @@ public SourceResultElement Extensions
/// of the underlying document. Used internally when the same result needs to be referenced
/// at a different location in the composite result.
/// </summary>
internal SourceSchemaResult WithPath(Path path)
internal SourceSchemaResult WithPath(CompactPath path)
=> new(path, _document, Final, ownsDocument: false, additionalPaths: []);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ public int OperationDocumentCacheSize
}
} = 256;

/// <summary>
/// Gets or sets the initial capacity of the local path segment pool used during result composition.
/// <c>64</c> by default. <c>1</c> is the minimum.
/// </summary>
public int PathSegmentLocalPoolCapacity
{
get;
set
{
ExpectMutableOptions();

if (value < 1)
{
throw new ArgumentException(
"The path segment local pool capacity must be at least 1.");
}

field = value;
}
} = 64;

/// <summary>
/// Gets or sets the default error handling mode.
/// <see cref="ErrorHandlingMode.Propagate"/> by default.
Expand Down Expand Up @@ -160,6 +181,7 @@ public FusionOptions Clone()
OperationExecutionPlanCacheSize = OperationExecutionPlanCacheSize,
OperationExecutionPlanCacheDiagnostics = OperationExecutionPlanCacheDiagnostics,
OperationDocumentCacheSize = OperationDocumentCacheSize,
PathSegmentLocalPoolCapacity = PathSegmentLocalPoolCapacity,
DefaultErrorHandlingMode = DefaultErrorHandlingMode,
LazyInitialization = LazyInitialization,
NodeIdSerializerFormat = NodeIdSerializerFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using HotChocolate.Execution;
using HotChocolate.Fusion.Execution.Clients;
using HotChocolate.Fusion.Text.Json;

namespace HotChocolate.Fusion.Execution.Nodes;

Expand Down Expand Up @@ -294,7 +295,7 @@ private static void AddErrors(
pathBufferLength += 1 + variables[i].AdditionalPaths.Length;
}

var pathBuffer = ArrayPool<Path>.Shared.Rent(pathBufferLength);
var pathBuffer = ArrayPool<CompactPath>.Shared.Rent(pathBufferLength);

try
{
Expand All @@ -315,7 +316,7 @@ private static void AddErrors(
finally
{
pathBuffer.AsSpan(0, pathBufferLength).Clear();
ArrayPool<Path>.Shared.Return(pathBuffer);
ArrayPool<CompactPath>.Shared.Return(pathBuffer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using HotChocolate.Execution;
using HotChocolate.Fusion.Diagnostics;
using HotChocolate.Fusion.Execution.Clients;
using HotChocolate.Fusion.Text.Json;

namespace HotChocolate.Fusion.Execution.Nodes;

Expand Down Expand Up @@ -343,7 +344,7 @@ private static void AddErrors(
pathBufferLength += 1 + variables[i].AdditionalPaths.Length;
}

var pathBuffer = ArrayPool<Path>.Shared.Rent(pathBufferLength);
var pathBuffer = ArrayPool<CompactPath>.Shared.Rent(pathBufferLength);

try
{
Expand All @@ -364,7 +365,7 @@ private static void AddErrors(
finally
{
pathBuffer.AsSpan(0, pathBufferLength).Clear();
ArrayPool<Path>.Shared.Return(pathBuffer);
ArrayPool<CompactPath>.Shared.Return(pathBuffer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Format(IBufferWriter<byte> writer, OperationPlan plan, OperationPlan
}

jsonWriter.WritePropertyName("nodes");
WriteNodes(jsonWriter, plan.AllNodes, trace);
WriteNodes(jsonWriter, plan.AllNodes, trace, plan.Operation);

jsonWriter.WriteEndObject();
}
Expand All @@ -72,7 +72,7 @@ internal void Format(IBufferWriter<byte> writer, Operation operation, ImmutableA
WriteOperation(jsonWriter, operation);

jsonWriter.WritePropertyName("nodes");
WriteNodes(jsonWriter, allNodes, null);
WriteNodes(jsonWriter, allNodes, null, operation);

jsonWriter.WriteEndObject();
}
Expand Down Expand Up @@ -101,7 +101,8 @@ private static void WriteOperation(
private static void WriteNodes(
Utf8JsonWriter jsonWriter,
ImmutableArray<ExecutionNode> allNodes,
OperationPlanTrace? trace)
OperationPlanTrace? trace,
Operation operation)
{
jsonWriter.WriteStartArray();

Expand All @@ -113,19 +114,19 @@ private static void WriteNodes(
switch (node)
{
case OperationExecutionNode operationNode:
WriteOperationNode(jsonWriter, operationNode, nodeTrace);
WriteOperationNode(jsonWriter, operationNode, nodeTrace, operation);
break;

case OperationBatchExecutionNode batchNode:
WriteOperationBatchNode(jsonWriter, batchNode, nodeTrace);
WriteOperationBatchNode(jsonWriter, batchNode, nodeTrace, operation);
break;

case IntrospectionExecutionNode introspectionNode:
WriteIntrospectionNode(jsonWriter, introspectionNode, nodeTrace);
WriteIntrospectionNode(jsonWriter, introspectionNode, nodeTrace, operation);
break;

case NodeFieldExecutionNode nodeExecutionNode:
WriteNodeFieldNode(jsonWriter, nodeExecutionNode, nodeTrace);
WriteNodeFieldNode(jsonWriter, nodeExecutionNode, nodeTrace, operation);
break;
}
}
Expand All @@ -136,7 +137,8 @@ private static void WriteNodes(
private static void WriteOperationNode(
Utf8JsonWriter jsonWriter,
OperationExecutionNode node,
ExecutionNodeTrace? trace)
ExecutionNodeTrace? trace,
Operation operation)
{
jsonWriter.WriteStartObject();
jsonWriter.WriteNumber("id", node.Id);
Expand Down Expand Up @@ -229,15 +231,16 @@ private static void WriteOperationNode(
jsonWriter.WriteEndArray();
}

TryWriteNodeTrace(jsonWriter, trace);
TryWriteNodeTrace(jsonWriter, trace, operation);

jsonWriter.WriteEndObject();
}

private static void WriteOperationBatchNode(
Utf8JsonWriter jsonWriter,
OperationBatchExecutionNode node,
ExecutionNodeTrace? trace)
ExecutionNodeTrace? trace,
Operation operation)
{
jsonWriter.WriteStartObject();
jsonWriter.WriteNumber("id", node.Id);
Expand Down Expand Up @@ -334,15 +337,16 @@ private static void WriteOperationBatchNode(
jsonWriter.WriteEndArray();
}

TryWriteNodeTrace(jsonWriter, trace);
TryWriteNodeTrace(jsonWriter, trace, operation);

jsonWriter.WriteEndObject();
}

private static void WriteIntrospectionNode(
Utf8JsonWriter jsonWriter,
IntrospectionExecutionNode node,
ExecutionNodeTrace? trace)
ExecutionNodeTrace? trace,
Operation operation)
{
jsonWriter.WriteStartObject();
jsonWriter.WriteNumber("id", node.Id);
Expand All @@ -363,12 +367,16 @@ private static void WriteIntrospectionNode(

TryWriteConditions(jsonWriter, node);

TryWriteNodeTrace(jsonWriter, trace);
TryWriteNodeTrace(jsonWriter, trace, operation);

jsonWriter.WriteEndObject();
}

private static void WriteNodeFieldNode(Utf8JsonWriter jsonWriter, NodeFieldExecutionNode node, ExecutionNodeTrace? trace)
private static void WriteNodeFieldNode(
Utf8JsonWriter jsonWriter,
NodeFieldExecutionNode node,
ExecutionNodeTrace? trace,
Operation operation)
{
jsonWriter.WriteStartObject();
jsonWriter.WriteNumber("id", node.Id);
Expand All @@ -390,12 +398,12 @@ private static void WriteNodeFieldNode(Utf8JsonWriter jsonWriter, NodeFieldExecu

TryWriteConditions(jsonWriter, node);

TryWriteNodeTrace(jsonWriter, trace);
TryWriteNodeTrace(jsonWriter, trace, operation);

jsonWriter.WriteEndObject();
}

private static void TryWriteNodeTrace(Utf8JsonWriter jsonWriter, ExecutionNodeTrace? trace)
private static void TryWriteNodeTrace(Utf8JsonWriter jsonWriter, ExecutionNodeTrace? trace, Operation operation)
{
if (trace is not null)
{
Expand All @@ -413,7 +421,7 @@ private static void TryWriteNodeTrace(Utf8JsonWriter jsonWriter, ExecutionNodeTr

foreach (var variableSet in trace.VariableSets)
{
jsonWriter.WritePropertyName(variableSet.Path.ToString());
jsonWriter.WritePropertyName(variableSet.Path.ToPath(operation).Print());
WriteObjectValueNode(jsonWriter, variableSet.Values);
}

Expand Down
Loading
Loading