Skip to content
Draft
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 @@ -70,7 +70,7 @@ protected override ValueTask<ExecutionStatus> OnExecuteAsync(
}

ExecuteSelections(context, backlog);
context.AddPartialResults(resultBuilder.Build(), _responseNames);
context.AddPartialResults(resultBuilder.Build());

return new ValueTask<ExecutionStatus>(ExecutionStatus.Success);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HotChocolate.Language;
using HotChocolate.Types;

namespace HotChocolate.Fusion.Execution.Nodes;

Expand All @@ -10,7 +11,7 @@ public sealed class NodeFieldExecutionNode : ExecutionNode
{
private readonly Dictionary<string, ExecutionNode> _branches = [];
private ExecutionNode _fallbackQuery = null!;
private readonly string _responseName;
private readonly SelectionSetNode _selectionSetNode;
private readonly IValueNode _idValue;
private readonly ExecutionNodeCondition[] _conditions;

Expand All @@ -20,10 +21,19 @@ internal NodeFieldExecutionNode(
IValueNode idValue,
ExecutionNodeCondition[] conditions)
{
_responseName = responseName;
_idValue = idValue;
Id = id;
_idValue = idValue;
_conditions = conditions;

const string nodeFieldName = "node";
_selectionSetNode = new SelectionSetNode([
new FieldNode(
name: new NameNode(nodeFieldName),
alias: responseName != nodeFieldName ? new NameNode(responseName) : null,
directives: [],
arguments: [],
selectionSet: null)
]);
}

/// <inheritdoc />
Expand All @@ -50,11 +60,6 @@ internal NodeFieldExecutionNode(
/// </summary>
public IValueNode IdValue => _idValue;

/// <summary>
/// Gets the response name for the node field.
/// </summary>
public string ResponseName => _responseName;

/// <summary>
/// Gets the fallback query for the case that a valid type name was requested,
/// but we do not have a branch for that type.
Expand Down Expand Up @@ -82,7 +87,7 @@ protected override ValueTask<ExecutionStatus> OnExecuteAsync(
.SetExtension("originalValue", id)
.Build();

context.AddErrors(error, [_responseName], Path.Root);
context.AddErrors(error, _selectionSetNode, Path.Root);

return ValueTask.FromResult(ExecutionStatus.Failed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
using System.Collections.Immutable;
using System.Runtime.InteropServices;
using HotChocolate.Fusion.Execution.Clients;
using HotChocolate.Language;

namespace HotChocolate.Fusion.Execution.Nodes;

public sealed class OperationBatchExecutionNode : ExecutionNode
{
private readonly OperationRequirement[] _requirements;
private readonly string[] _forwardedVariables;
private readonly string[] _responseNames;
private readonly ExecutionNodeCondition[] _conditions;
private readonly bool _requiresFileUpload;
private readonly OperationSourceText _operation;
private readonly SelectionSetNode _selectionSetNode;
private readonly int? _batchingGroupId;
private readonly string? _schemaName;
private readonly SelectionPath[] _targets;
Expand All @@ -21,27 +21,25 @@ public sealed class OperationBatchExecutionNode : ExecutionNode
internal OperationBatchExecutionNode(
int id,
OperationSourceText operation,
SelectionSetNode selectionSetNode,
string? schemaName,
SelectionPath[] targets,
SelectionPath source,
OperationRequirement[] requirements,
string[] forwardedVariables,
string[] responseNames,
ExecutionNodeCondition[] conditions,
int? batchingGroupId,
bool requiresFileUpload)
int? batchingGroupId)
{
Id = id;
_operation = operation;
_selectionSetNode = selectionSetNode;
_batchingGroupId = batchingGroupId;
_schemaName = schemaName;
_targets = targets;
_source = source;
_requirements = requirements;
_forwardedVariables = forwardedVariables;
_responseNames = responseNames;
_conditions = conditions;
_requiresFileUpload = requiresFileUpload;
}

/// <inheritdoc />
Expand All @@ -63,11 +61,6 @@ internal OperationBatchExecutionNode(
/// </summary>
public int? BatchingGroupId => _batchingGroupId;

/// <summary>
/// Gets the response names of the target selection sets that are fulfilled by this operation.
/// </summary>
public ReadOnlySpan<string> ResponseNames => _responseNames;

/// <inheritdoc />
public override string? SchemaName => _schemaName;

Expand All @@ -92,12 +85,6 @@ internal OperationBatchExecutionNode(
/// </summary>
public ReadOnlySpan<string> ForwardedVariables => _forwardedVariables;

/// <summary>
/// Gets whether this operation contains one or more variables
/// that contain the Upload scalar.
/// </summary>
public bool RequiresFileUpload => _requiresFileUpload;

protected override async ValueTask<ExecutionStatus> OnExecuteAsync(
OperationPlanContext context,
CancellationToken cancellationToken = default)
Expand All @@ -121,8 +108,7 @@ protected override async ValueTask<ExecutionStatus> OnExecuteAsync(
BatchingGroupId = _batchingGroupId,
OperationType = _operation.Type,
OperationSourceText = _operation.SourceText,
Variables = variables,
RequiresFileUpload = _requiresFileUpload
Variables = variables
};

var index = 0;
Expand Down Expand Up @@ -209,7 +195,7 @@ protected override async ValueTask<ExecutionStatus> OnExecuteAsync(
singleResult.Dispose();
}

AddErrors(context, exception, variables, _responseNames);
AddErrors(context, exception, variables, _selectionSetNode);
return ExecutionStatus.Failed;
}

Expand All @@ -220,7 +206,7 @@ protected override async ValueTask<ExecutionStatus> OnExecuteAsync(
context.AddPartialResults(
_source,
buffer.AsSpan(0, index),
_responseNames,
_selectionSetNode,
hasSomeErrors);
}
else if (singleResult is not null)
Expand All @@ -229,15 +215,15 @@ protected override async ValueTask<ExecutionStatus> OnExecuteAsync(
context.AddPartialResults(
_source,
MemoryMarshal.CreateReadOnlySpan(ref firstResult, 1),
_responseNames,
_selectionSetNode,
hasSomeErrors);
}
else
{
context.AddPartialResults(
_source,
[],
_responseNames,
_selectionSetNode,
hasSomeErrors);
}
}
Expand All @@ -251,7 +237,7 @@ protected override async ValueTask<ExecutionStatus> OnExecuteAsync(
catch (Exception exception)
{
diagnosticEvents.SourceSchemaStoreError(context, this, schemaName, exception);
AddErrors(context, exception, variables, _responseNames);
AddErrors(context, exception, variables, _selectionSetNode);
return ExecutionStatus.Failed;
}
finally
Expand All @@ -276,13 +262,13 @@ private static void AddErrors(
OperationPlanContext context,
Exception exception,
ImmutableArray<VariableValues> variables,
ReadOnlySpan<string> responseNames)
SelectionSetNode selectionSetNode)
{
var error = ErrorBuilder.FromException(exception).Build();

if (variables.Length == 0)
{
context.AddErrors(error, responseNames, Path.Root);
context.AddErrors(error, selectionSetNode, Path.Root);
}
else
{
Expand All @@ -309,7 +295,7 @@ private static void AddErrors(
}
}

context.AddErrors(error, responseNames, pathBuffer.AsSpan(0, pathBufferLength));
context.AddErrors(error, selectionSetNode, pathBuffer.AsSpan(0, pathBufferLength));
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
using System.Runtime.InteropServices;
using HotChocolate.Fusion.Diagnostics;
using HotChocolate.Fusion.Execution.Clients;
using HotChocolate.Language;

namespace HotChocolate.Fusion.Execution.Nodes;

public sealed class OperationExecutionNode : ExecutionNode
{
private readonly OperationRequirement[] _requirements;
private readonly string[] _forwardedVariables;
private readonly string[] _responseNames;
private readonly ExecutionNodeCondition[] _conditions;
private readonly bool _requiresFileUpload;
private readonly OperationSourceText _operation;
private readonly SelectionSetNode _selectionSetNode;
private readonly int? _batchingGroupId;
private readonly string? _schemaName;
private readonly SelectionPath _target;
Expand All @@ -24,25 +25,25 @@ public sealed class OperationExecutionNode : ExecutionNode
internal OperationExecutionNode(
int id,
OperationSourceText operation,
SelectionSetNode selectionSetNode,
string? schemaName,
SelectionPath target,
SelectionPath source,
OperationRequirement[] requirements,
string[] forwardedVariables,
string[] responseNames,
ExecutionNodeCondition[] conditions,
int? batchingGroupId,
bool requiresFileUpload)
{
Id = id;
_operation = operation;
_selectionSetNode = selectionSetNode;
_batchingGroupId = batchingGroupId;
_schemaName = schemaName;
_target = target;
_source = source;
_requirements = requirements;
_forwardedVariables = forwardedVariables;
_responseNames = responseNames;
_conditions = conditions;
_requiresFileUpload = requiresFileUpload;
}
Expand All @@ -62,14 +63,14 @@ internal OperationExecutionNode(
public OperationSourceText Operation => _operation;

/// <summary>
/// Gets the deterministic batching group identifier assigned at planning time.
/// Gets the <see cref="HotChocolate.Language.SelectionSetNode"/> at <see cref="Source"/> in the <see cref="Operation"/>.
/// </summary>
public int? BatchingGroupId => _batchingGroupId;
public SelectionSetNode SelectionSetNode => _selectionSetNode;

/// <summary>
/// Gets the response names of the <see cref="Target"/> selection set that are fulfilled by this operation.
/// Gets the deterministic batching group identifier assigned at planning time.
/// </summary>
public ReadOnlySpan<string> ResponseNames => _responseNames;
public int? BatchingGroupId => _batchingGroupId;

/// <inheritdoc />
public override string? SchemaName => _schemaName;
Expand Down Expand Up @@ -213,7 +214,7 @@ protected override async ValueTask<ExecutionStatus> OnExecuteAsync(
singleResult.Dispose();
}

AddErrors(context, exception, variables, _responseNames);
AddErrors(context, exception, variables, _selectionSetNode);
return ExecutionStatus.Failed;
}

Expand All @@ -224,7 +225,7 @@ protected override async ValueTask<ExecutionStatus> OnExecuteAsync(
context.AddPartialResults(
_source,
buffer.AsSpan(0, index),
_responseNames,
_selectionSetNode,
hasSomeErrors);
}
else if (singleResult is not null)
Expand All @@ -233,15 +234,15 @@ protected override async ValueTask<ExecutionStatus> OnExecuteAsync(
context.AddPartialResults(
_source,
MemoryMarshal.CreateReadOnlySpan(ref firstResult, 1),
_responseNames,
_selectionSetNode,
hasSomeErrors);
}
else
{
context.AddPartialResults(
_source,
[],
_responseNames,
_selectionSetNode,
hasSomeErrors);
}
}
Expand All @@ -255,7 +256,7 @@ protected override async ValueTask<ExecutionStatus> OnExecuteAsync(
catch (Exception exception)
{
diagnosticEvents.SourceSchemaStoreError(context, this, schemaName, exception);
AddErrors(context, exception, variables, _responseNames);
AddErrors(context, exception, variables, _selectionSetNode);
return ExecutionStatus.Failed;
}
finally
Expand Down Expand Up @@ -315,7 +316,7 @@ internal async Task<SubscriptionResult> SubscribeAsync(
}
catch (Exception ex)
{
AddErrors(context, ex, variables, _responseNames);
AddErrors(context, ex, variables, _selectionSetNode);
context.DiagnosticEvents.SubscriptionTransportError(context, this, schemaName, subscriptionId, ex);
return SubscriptionResult.Failed(subscriptionId, ex);
}
Expand All @@ -325,13 +326,13 @@ private static void AddErrors(
OperationPlanContext context,
Exception exception,
ImmutableArray<VariableValues> variables,
ReadOnlySpan<string> responseNames)
SelectionSetNode selectionSetNode)
{
var error = ErrorBuilder.FromException(exception).Build();

if (variables.Length == 0)
{
context.AddErrors(error, responseNames, Path.Root);
context.AddErrors(error, selectionSetNode, Path.Root);
}
else
{
Expand All @@ -358,7 +359,7 @@ private static void AddErrors(
}
}

context.AddErrors(error, responseNames, pathBuffer.AsSpan(0, pathBufferLength));
context.AddErrors(error, selectionSetNode, pathBuffer.AsSpan(0, pathBufferLength));
}
finally
{
Expand Down Expand Up @@ -483,14 +484,14 @@ public async ValueTask<bool> MoveNextAsync()
_node.SchemaName ?? _context.GetDynamicSchemaName(_node),
_subscriptionId,
exception);
_context.AddErrors(error, _node._responseNames);
_context.AddErrors(error, _node._selectionSetNode);
return false;
}

if (hasResult)
{
_resultBuffer[0] = _resultEnumerator.Current;
_context.AddPartialResults(_node._source, _resultBuffer, _node._responseNames);
_context.AddPartialResults(_node._source, _resultBuffer, _node._selectionSetNode);

Current = new EventMessageResult(
_node.Id,
Expand Down
Loading