Skip to content

Commit 2e22212

Browse files
authored
[fusion] Fixed error caused by empty string arguments (#8618)
1 parent 69c7181 commit 2e22212

File tree

5 files changed

+149
-3
lines changed

5 files changed

+149
-3
lines changed

src/HotChocolate/Fusion-vnext/test/Fusion.AspNetCore.Tests/BookStoreTests.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,77 @@ public async Task Fetch_Books_With_Requirements_To_SourceSchema1_X_Times(int ite
540540
}
541541
}
542542

543+
[Fact]
544+
public async Task Ensure_String_Literals_Can_Be_Empty()
545+
{
546+
// arrange
547+
using var server1 = CreateSourceSchema(
548+
"a",
549+
b => b.AddQueryType<SourceSchema1.Query>());
550+
551+
using var server2 = CreateSourceSchema(
552+
"b",
553+
b => b.AddQueryType<SourceSchema2.Query>());
554+
555+
// act
556+
using var gateway = await CreateCompositeSchemaAsync(
557+
[
558+
("a", server1),
559+
("b", server2)
560+
]);
561+
562+
// assert
563+
using var client = GraphQLHttpClient.Create(gateway.CreateClient());
564+
565+
using var result = await client.PostAsync(
566+
"""
567+
{
568+
formatTitle(title: "")
569+
}
570+
""",
571+
new Uri("http://localhost:5000/graphql"));
572+
573+
// act
574+
using var response = await result.ReadAsResultAsync();
575+
response.MatchSnapshot();
576+
}
577+
578+
[Fact]
579+
public async Task Ensure_String_Variables_Can_Be_Empty()
580+
{
581+
// arrange
582+
using var server1 = CreateSourceSchema(
583+
"a",
584+
b => b.AddQueryType<SourceSchema1.Query>());
585+
586+
using var server2 = CreateSourceSchema(
587+
"b",
588+
b => b.AddQueryType<SourceSchema2.Query>());
589+
590+
// act
591+
using var gateway = await CreateCompositeSchemaAsync(
592+
[
593+
("a", server1),
594+
("b", server2)
595+
]);
596+
597+
// assert
598+
using var client = GraphQLHttpClient.Create(gateway.CreateClient());
599+
600+
using var result = await client.PostAsync(
601+
"""
602+
query ($s: String!) {
603+
formatTitle(title: $s)
604+
}
605+
""",
606+
variables: new Dictionary<string, object?> { { "s", "" } },
607+
new Uri("http://localhost:5000/graphql"));
608+
609+
// act
610+
using var response = await result.ReadAsResultAsync();
611+
response.MatchSnapshot();
612+
}
613+
543614
public static class SourceSchema1
544615
{
545616
public record Book(int Id, string Title, Author Author);
@@ -564,6 +635,9 @@ public Book GetBookById(int id)
564635
[UsePaging]
565636
public IEnumerable<Book> GetBooks()
566637
=> _books.Values;
638+
639+
public string FormatTitle(string title)
640+
=> title;
567641
}
568642
}
569643

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"data": {
3+
"formatTitle": ""
4+
},
5+
"extensions": {
6+
"fusion": {
7+
"operationPlan": {
8+
"id": "5f6d4777b547101a6afdcba10ab494bb886423fc03256b1499cc4d743d51d37e",
9+
"operation": {
10+
"kind": "Query",
11+
"document": "{\n formatTitle(title: \"\")\n}",
12+
"id": "db37b9bf699a3623f803777a91ad4002",
13+
"hash": "db37b9bf699a3623f803777a91ad4002",
14+
"shortHash": "db37b9bf"
15+
},
16+
"nodes": [
17+
{
18+
"id": 1,
19+
"type": "Operation",
20+
"schema": "a",
21+
"operation": {
22+
"name": "Op_db37b9bf_1",
23+
"type": "Query",
24+
"document": "query Op_db37b9bf_1 {\n formatTitle(title: \"\")\n}",
25+
"hash": "f008a17a4990239900f3bc520624a85106689c0364d27a015aea3f7e2731b816",
26+
"shortHash": "f008a17a"
27+
},
28+
"responseNames": [
29+
"formatTitle"
30+
]
31+
}
32+
]
33+
}
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"data": {
3+
"formatTitle": ""
4+
},
5+
"extensions": {
6+
"fusion": {
7+
"operationPlan": {
8+
"id": "d44a8ae58827d46da9c1a91590831908b04ec6c80f67e71ed0f4b0101cdd056d",
9+
"operation": {
10+
"kind": "Query",
11+
"document": "query(\n $s: String!\n) {\n formatTitle(title: $s)\n}",
12+
"id": "577373a9b2c16f480ac5c2645f109b7b",
13+
"hash": "577373a9b2c16f480ac5c2645f109b7b",
14+
"shortHash": "577373a9"
15+
},
16+
"nodes": [
17+
{
18+
"id": 1,
19+
"type": "Operation",
20+
"schema": "a",
21+
"operation": {
22+
"name": "Op_577373a9_1",
23+
"type": "Query",
24+
"document": "query Op_577373a9_1(\n $s: String!\n) {\n formatTitle(title: $s)\n}",
25+
"hash": "9e1437a320d35e130c8630097be0d047b93df036081428b716822d6f0df8ae47",
26+
"shortHash": "9e1437a3"
27+
},
28+
"responseNames": [
29+
"formatTitle"
30+
]
31+
}
32+
]
33+
}
34+
}
35+
}
36+
}

src/HotChocolate/Utilities/src/Utilities.Buffers/ArrayMemoryOwner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public ArrayMemoryOwner(byte[] buffer, int start, int length)
3232
#if NET8_0_OR_GREATER
3333
ArgumentNullException.ThrowIfNull(buffer);
3434
ArgumentOutOfRangeException.ThrowIfLessThan(start, 0);
35-
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(length, 0);
35+
ArgumentOutOfRangeException.ThrowIfLessThan(length, 0);
3636
#else
3737
if (buffer is null)
3838
{

src/HotChocolate/Utilities/src/Utilities.Buffers/ReadOnlyMemorySegment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ReadOnlyMemorySegment(IMemoryOwner<byte> owner, int start, int length)
3030
#if NET8_0_OR_GREATER
3131
ArgumentNullException.ThrowIfNull(owner);
3232
ArgumentOutOfRangeException.ThrowIfLessThan(start, 0);
33-
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(length, 0);
33+
ArgumentOutOfRangeException.ThrowIfLessThan(length, 0);
3434
#else
3535
if (owner is null)
3636
{
@@ -81,7 +81,7 @@ public ReadOnlyMemorySegment(byte[] buffer, int start, int length)
8181
#if NET8_0_OR_GREATER
8282
ArgumentNullException.ThrowIfNull(buffer);
8383
ArgumentOutOfRangeException.ThrowIfLessThan(start, 0);
84-
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(length, 0);
84+
ArgumentOutOfRangeException.ThrowIfLessThan(length, 0);
8585
#else
8686
if (buffer is null)
8787
{

0 commit comments

Comments
 (0)