Skip to content

Commit

Permalink
Fixed field merging issue for skip/include. (#6621)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Oct 24, 2023
1 parent f0b3707 commit 5a52375
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static async Task ExecuteAsync(

var sdl = schema.Schema.Print();

if (output is { })
if (output is not null)
{
await File.WriteAllTextAsync(output.FullName, sdl, Encoding.UTF8, cancellationToken);
}
Expand Down
5 changes: 3 additions & 2 deletions src/HotChocolate/Core/src/Execution/Processing/Selection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Linq;
using HotChocolate.Execution.Properties;
using HotChocolate.Execution.Serialization;
using HotChocolate.Language;
using HotChocolate.Resolvers;
using HotChocolate.Types;
Expand Down Expand Up @@ -244,9 +245,9 @@ private static FieldNode MergeField(
temp[next++] = directives[i];
}

for (var i = 0; i < first.Directives.Count; i++)
for (var i = 0; i < other.Directives.Count; i++)
{
temp[next++] = first.Directives[i];
temp[next++] = other.Directives[i];
}

directives = temp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Threading.Tasks;
using CookieCrumble;
using HotChocolate.Language;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Xunit;

namespace HotChocolate.Execution.Processing;

Expand Down Expand Up @@ -306,6 +303,80 @@ person @skip(if: true) @include(if: true) {
}
""");
}

[Fact]
public async Task Skip_Include_Merge_Issue_6550_True()
{
var result =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<Query>()
.ExecuteRequestAsync(
QueryRequestBuilder.New()
.SetQuery(
"""
query($shouldSkip: Boolean! = true) {
person @skip(if: $shouldSkip) {
a: name
}
person @skip(if: $shouldSkip) {
b: name
}
person @skip(if: $shouldSkip) {
c: name
}
}
""")
.SetVariableValue("shouldSkip", true)
.Create());

result.MatchInlineSnapshot(
"""
{
"data": {}
}
""");
}

[Fact]
public async Task Skip_Include_Merge_Issue_6550_False()
{
var result =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<Query>()
.ExecuteRequestAsync(
QueryRequestBuilder.New()
.SetQuery(
"""
query($shouldSkip: Boolean! = true) {
person @skip(if: $shouldSkip) {
a: name
}
person @skip(if: $shouldSkip) {
b: name
}
person @skip(if: $shouldSkip) {
c: name
}
}
""")
.SetVariableValue("shouldSkip", false)
.Create());

result.MatchInlineSnapshot(
"""
{
"data": {
"person": {
"a": "hello",
"b": "hello",
"c": "hello"
}
}
}
""");
}

[Fact]
public async Task Variables_Skip_True_Include_True_Should_Be_Empty_Result()
Expand Down

0 comments on commit 5a52375

Please sign in to comment.