Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for variables to new operation planner. #7780

Merged
merged 8 commits into from
Nov 29, 2024
Merged
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
@@ -1,6 +1,6 @@
using System.Collections.Immutable;
using System.Diagnostics;
using HotChocolate.Fusion.Types;
using HotChocolate.Fusion.Types.Collections;
using HotChocolate.Language;

namespace HotChocolate.Fusion.Planning.Nodes;
Expand All @@ -11,19 +11,31 @@ public sealed class FieldPlanNode : SelectionPlanNode

public FieldPlanNode(
FieldNode fieldNode,
CompositeOutputField field)
OutputFieldInfo field)
: base(field.Type.NamedType(), fieldNode.SelectionSet?.Selections)
{
FieldNode = fieldNode;
Field = field;
ResponseName = FieldNode.Alias?.Value ?? field.Name;

foreach (var argument in fieldNode.Arguments)
{
AddArgument(new ArgumentAssignment(argument.Name.Value, argument.Value));
}
}

public FieldPlanNode(
FieldNode fieldNode,
CompositeOutputField field)
: this(fieldNode, new OutputFieldInfo(field))
{
}

public string ResponseName { get; }

public FieldNode FieldNode { get; }

public CompositeOutputField Field { get; }
public OutputFieldInfo Field { get; }

public IReadOnlyList<ArgumentAssignment> Arguments
=> _arguments ?? (IReadOnlyList<ArgumentAssignment>)Array.Empty<ArgumentAssignment>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ namespace HotChocolate.Fusion.Planning.Nodes;
/// </summary>
public sealed class OperationPlanNode : SelectionPlanNode, IOperationPlanNodeProvider
{
private static readonly IReadOnlyDictionary<string, VariableDefinitionNode> _emptyVariableMap =
new Dictionary<string, VariableDefinitionNode>();
private List<OperationPlanNode>? _operations;
private Dictionary<string, VariableDefinitionNode>? _variables;

public OperationPlanNode(
string schemaName,
Expand Down Expand Up @@ -37,9 +40,18 @@ public OperationPlanNode(
// todo: variable representations are missing.
// todo: how to we represent state?

public IReadOnlyDictionary<string, VariableDefinitionNode> VariableDefinitions
=> _variables ?? _emptyVariableMap;

public IReadOnlyList<OperationPlanNode> Operations
=> _operations ?? (IReadOnlyList<OperationPlanNode>)Array.Empty<OperationPlanNode>();

public void AddVariableDefinition(VariableDefinitionNode variable)
{
ArgumentNullException.ThrowIfNull(variable);
(_variables ??= new Dictionary<string, VariableDefinitionNode>()).Add(variable.Variable.Name.Value, variable);
}

public void AddOperation(OperationPlanNode operation)
{
ArgumentNullException.ThrowIfNull(operation);
Expand All @@ -53,7 +65,7 @@ public OperationDefinitionNode ToSyntaxNode()
null,
null,
OperationType.Query,
Array.Empty<VariableDefinitionNode>(),
_variables?.Values.OrderBy(t => t.Variable.Name.Value).ToArray() ?? [],
Directives.ToSyntaxNode(),
Selections.ToSyntaxNode());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Immutable;
using HotChocolate.Fusion.Types;

namespace HotChocolate.Fusion.Planning.Nodes;

public class OutputFieldInfo(string name, ICompositeType type, ImmutableArray<string> sources)
{
public OutputFieldInfo(CompositeOutputField field)
: this(field.Name, field.Type, field.Sources.Schemas)
{

}

public string Name => name;

public ICompositeType Type => type;

public ImmutableArray<string> Sources => sources;
}
Loading
Loading