Skip to content
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
Expand Up @@ -154,20 +154,23 @@ public static void Arguments(FieldContext context)
var count = includeDeprecated
? directiveDef.Arguments.Count
: directiveDef.Arguments.Count(t => !t.IsDeprecated);
var list = context.FieldResult.CreateListValue(count);
using var list = context.FieldResult.CreateListValue(count).EnumerateArray().GetEnumerator();

var index = 0;
foreach (var element in list.EnumerateArray())
foreach (var argument in directiveDef.Arguments)
{
var argument = directiveDef.Arguments[index++];

if (!includeDeprecated && argument.IsDeprecated)
{
continue;
}

if (!list.MoveNext())
{
Debug.Fail("Expected enumerator of list value to be able to advance");
break;
}

context.AddRuntimeResult(argument);
element.CreateObjectValue(context.Selection, context.IncludeFlags);
list.Current.CreateObjectValue(context.Selection, context.IncludeFlags);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,23 @@ public static void Arguments(FieldContext context)
var count = includeDeprecated
? field.Arguments.Count
: field.Arguments.Count(t => !t.IsDeprecated);
var list = context.FieldResult.CreateListValue(count);
using var list = context.FieldResult.CreateListValue(count).EnumerateArray().GetEnumerator();

var index = 0;
foreach (var element in list.EnumerateArray())
foreach (var argument in field.Arguments)
{
var argument = field.Arguments[index++];

if (!includeDeprecated && argument.IsDeprecated)
{
continue;
}

if (!list.MoveNext())
{
Debug.Fail("Expected enumerator of list value to be able to advance");
break;
}

context.AddRuntimeResult(argument);
element.CreateObjectValue(context.Selection, context.IncludeFlags);
list.Current.CreateObjectValue(context.Selection, context.IncludeFlags);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using HotChocolate.Execution;
using Microsoft.Extensions.DependencyInjection;

namespace HotChocolate.Fusion.Execution.Introspection;

public sealed class FieldArgumentsIntrospectionTests : FusionTestBase
{
// __Field.args excludes deprecated arguments by default and returns the remaining
// arguments without leaving gaps, even when a deprecated argument precedes a
// non-deprecated one.
[Fact]
public async Task Fields_Args_ExcludeDeprecatedArguments()
{
// arrange
var services = new ServiceCollection();
services.AddHttpClient();
services
.AddGraphQLGateway()
.AddInMemoryConfiguration(
ComposeSchemaDocument(
"""
type Query {
field(
deprecatedArg: String @deprecated(reason: "old")
normalArg: String
): String
}
"""))
.UseDefaultPipeline();

var executor = await services
.BuildServiceProvider()
.GetRequestExecutorAsync(cancellationToken: TestContext.Current.CancellationToken);

// act
var result = await executor.ExecuteAsync(
OperationRequestBuilder.New()
.SetDocument(
"""
{
__type(name: "Query") {
fields {
name
args {
name
}
}
}
}
""")
.Build(),
TestContext.Current.CancellationToken);

// assert
result.MatchInlineSnapshot(
"""
{
"data": {
"__type": {
"fields": [
{
"name": "field",
"args": [
{
"name": "normalArg"
}
]
}
]
}
}
}
""");
}
}
Loading