Skip to content

Commit

Permalink
Merge branch 'main' into fusion-options
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Apr 2, 2024
2 parents 5007d39 + dcff6fc commit f2d95fa
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/HotChocolate/Core/src/Abstractions/ErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ public static class Paging
/// </summary>
public const string NoPagingBoundaries = "HC0052";

/// <summary>
/// The requested number of values per page must be at least 0.
/// </summary>
public const string MinPaginationItems = "HC0079";

/// <summary>
/// The cursor format is invalid.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public void ValidateContext(IResolverContext context)
context.Path);
}

if (first < 0)
{
throw ThrowHelper.PagingHandler_MinPageSize(
(int)first,
context.Selection.Field,
context.Path);
}

if (first > MaxPageSize)
{
throw ThrowHelper.PagingHandler_MaxPageSize(
Expand All @@ -79,6 +87,14 @@ public void ValidateContext(IResolverContext context)
context.Path);
}

if (last < 0)
{
throw ThrowHelper.PagingHandler_MinPageSize(
(int)last,
context.Selection.Field,
context.Path);
}

if (last > MaxPageSize)
{
throw ThrowHelper.PagingHandler_MaxPageSize(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@
<data name="ThrowHelper_InvalidIndexCursor_Message" xml:space="preserve">
<value>The cursor specified in `{0}` has an invalid format.</value>
</data>
<data name="ThrowHelper_PagingHandler_MinPageSize" xml:space="preserve">
<value>The requested number of values per page must be at least 0.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ namespace HotChocolate.Utilities;

internal static class ThrowHelper
{
public static GraphQLException PagingHandler_MinPageSize(
int requestedItems,
IObjectField field,
Path path)
=> new GraphQLException(
ErrorBuilder.New()
.SetMessage(ThrowHelper_PagingHandler_MinPageSize)
.SetCode(ErrorCodes.Paging.MinPaginationItems)
.SetPath(path)
.SetExtension(nameof(field), field.Coordinate.ToString())
.SetExtension(nameof(requestedItems), requestedItems)
.Build());

public static GraphQLException PagingHandler_MaxPageSize(
int requestedItems,
int maxAllowedItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,39 @@ await executor
.MatchSnapshotAsync();
}

[Fact]
public async Task MinPageSizeReached_First()
{
Snapshot.FullName();

var executor =
await new ServiceCollection()
.AddGraphQL()
.AddQueryType<QueryType>()
.Services
.BuildServiceProvider()
.GetRequestExecutorAsync();

await executor
.ExecuteAsync(@"
{
letters(first: -1) {
edges {
node
cursor
}
nodes
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}")
.MatchSnapshotAsync();
}

[Fact]
public async Task MaxPageSizeReached_First()
{
Expand Down Expand Up @@ -211,6 +244,39 @@ await executor
.MatchSnapshotAsync();
}

[Fact]
public async Task MinPageSizeReached_Last()
{
Snapshot.FullName();

var executor =
await new ServiceCollection()
.AddGraphQL()
.AddQueryType<QueryType>()
.Services
.BuildServiceProvider()
.GetRequestExecutorAsync();

await executor
.ExecuteAsync(@"
{
letters(last: -1) {
edges {
node
cursor
}
nodes
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}")
.MatchSnapshotAsync();
}

[Fact]
public async Task MaxPageSizeReached_Last()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"errors": [
{
"message": "The requested number of values per page must be at least 0.",
"path": [
"letters"
],
"extensions": {
"code": "HC0079",
"field": "Query.letters",
"requestedItems": -1
}
}
],
"data": {
"letters": null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"errors": [
{
"message": "The requested number of values per page must be at least 0.",
"path": [
"letters"
],
"extensions": {
"code": "HC0079",
"field": "Query.letters",
"requestedItems": -1
}
}
],
"data": {
"letters": null
}
}

0 comments on commit f2d95fa

Please sign in to comment.