Skip to content

Commit 2c9abe9

Browse files
authored
Added a separate pagination error message for missing first value (#8693)
1 parent 762bb52 commit 2c9abe9

File tree

7 files changed

+164
-31
lines changed

7 files changed

+164
-31
lines changed

src/HotChocolate/Core/src/Types.CursorPagination/CursorPagingHandler.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ public void ValidateContext(IResolverContext context)
6060

6161
if (RequirePagingBoundaries && first is null && last is null)
6262
{
63-
throw ThrowHelper.PagingHandler_NoBoundariesSet(
63+
if (AllowBackwardPagination)
64+
{
65+
throw ThrowHelper.PagingHandler_NoBoundariesSet(
66+
context.Selection.Field,
67+
context.Path);
68+
}
69+
70+
throw ThrowHelper.PagingHandler_FirstValueNotSet(
6471
context.Selection.Field,
6572
context.Path);
6673
}

src/HotChocolate/Core/src/Types.CursorPagination/Properties/CursorResources.Designer.cs

Lines changed: 86 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HotChocolate/Core/src/Types.CursorPagination/Properties/CursorResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<data name="ThrowHelper_PagingHandler_NoBoundariesSet" xml:space="preserve">
4343
<value>You must provide a `first` or `last` value to properly paginate the `{0}`.</value>
4444
</data>
45+
<data name="ThrowHelper_PagingHandler_FirstValueNotSet" xml:space="preserve">
46+
<value>You must provide a `first` value to properly paginate the `{0}`.</value>
47+
</data>
4548
<data name="Edge_Cursor_CursorAndResolverNull" xml:space="preserve">
4649
<value>The edge state is invalid and has no cursor.</value>
4750
</data>

src/HotChocolate/Core/src/Types.CursorPagination/Utilities/ThrowHelper.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ public static GraphQLException PagingHandler_NoBoundariesSet(
4747
.SetFieldCoordinate(field.Coordinate)
4848
.Build());
4949

50+
public static GraphQLException PagingHandler_FirstValueNotSet(
51+
IOutputFieldDefinition field,
52+
Path path)
53+
=> new GraphQLException(
54+
ErrorBuilder.New()
55+
.SetMessage(
56+
ThrowHelper_PagingHandler_FirstValueNotSet,
57+
field.Type.TypeName())
58+
.SetCode(ErrorCodes.Paging.FirstValueNotSet)
59+
.SetPath(path)
60+
.SetFieldCoordinate(field.Coordinate)
61+
.Build());
62+
5063
public static SchemaException PagingObjectFieldDescriptorExtensions_InvalidType()
5164
=> new SchemaException(
5265
SchemaErrorBuilder.New()

src/HotChocolate/Core/test/Types.CursorPagination.Tests/IntegrationTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,32 @@ await executor
115115
.MatchSnapshotAsync();
116116
}
117117

118+
[Fact]
119+
public async Task First_Value_Not_Set()
120+
{
121+
var executor =
122+
await new ServiceCollection()
123+
.AddGraphQL()
124+
.AddQueryType<QueryType>()
125+
.ModifyPagingOptions(o =>
126+
{
127+
o.RequirePagingBoundaries = true;
128+
o.AllowBackwardPagination = false;
129+
})
130+
.Services
131+
.BuildServiceProvider()
132+
.GetRequestExecutorAsync();
133+
134+
await executor
135+
.ExecuteAsync(@"
136+
{
137+
letters {
138+
nodes
139+
}
140+
}")
141+
.MatchSnapshotAsync();
142+
}
143+
118144
[Fact]
119145
public async Task Attribute_Simple_StringList_Default_Items()
120146
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"errors": [
3+
{
4+
"message": "You must provide a `first` value to properly paginate the `LettersConnection`.",
5+
"locations": [
6+
{
7+
"line": 3,
8+
"column": 21
9+
}
10+
],
11+
"path": [
12+
"letters"
13+
],
14+
"extensions": {
15+
"code": "HC0090",
16+
"fieldCoordinate": "Query.letters"
17+
}
18+
}
19+
],
20+
"data": {
21+
"letters": null
22+
}
23+
}

src/HotChocolate/Primitives/src/Primitives/ErrorCodes.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ public static class Paging
354354
/// </summary>
355355
public const string NoPagingBoundaries = "HC0052";
356356

357+
/// <summary>
358+
/// You must provide a `first` value to properly paginate the connection.
359+
/// </summary>
360+
public const string FirstValueNotSet = "HC0090";
361+
357362
/// <summary>
358363
/// The requested number of values per page must be at least 0.
359364
/// </summary>

0 commit comments

Comments
 (0)