Skip to content

GraphQL Cursor-Based Pagination Error – Unable to Fetch More Than 50 Records (Max Page Size Limit) #8281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Kishan5139 opened this issue May 9, 2025 · 1 comment

Comments

@Kishan5139
Copy link

Product

Hot Chocolate

Version

14.3.0

Link to minimal reproduction

https://github.com/Kishan5139/GraphqlPagination

Steps to reproduce

I’ve implemented GraphQL in my project and I'm encountering an issue with cursor-based pagination. When I try to fetch more than 50 records using first: 51 or higher, I receive error maxAllowedItems: 50.

I have shared repository link. Please clone the repository and run graphql project and try to run this query

query {
  laltexPimCoreSupplierData(
    userID: "1fda6f80-f4f4-4307-a73e-873759f0c488"
    isUpdateCall: false
    page: 0
    pageSize: 10
    first: 1000
    after: null
  ) {
    edges {
      cursor
      node {
        _id
        availableColours
        Description
        WebDescription
        KeyWords
        
      }
    }
  }
}

Sample MongoDB Document
{ "status": "1", "ProductCode": "Ad12", "ProductName": "asdsad", "ProductTitle": "asfas", "Description": "sadasd", "WebDescription": "asdasdsk", "KeyWords": "sadsadasdday" }

This is my graphql api code

using GraphQLPagination.ApiService.Models;
using MongoDB.Driver;

namespace SupplierEngine.GraphQLServer.GraphQL.Laltex.Queries
{
    public class PIMCoreLaltexSupplierQueries(IMongoDatabase _mongoDatabase) : IPIMCoreLaltexSupplierQueries
    {
        private IMongoCollection<Suppliers> GetUserLaltexCollection(string userID, bool IsUpdateCall)
        {
            if (string.IsNullOrEmpty(userID))
            {
                throw new UnauthorizedAccessException("User ID is not found.");
            }

            var collectionName = IsUpdateCall ? $"laltex_{userID}_updated" : $"laltex_{userID}";
            return _mongoDatabase.GetCollection<Suppliers>(collectionName);
        }

        public IQueryable<Suppliers> GetLaltexPimCoreSupplierData(string UserID, bool IsUpdateCall, int page, int pageSize)
        {
            return GetUserLaltexCollection(UserID, IsUpdateCall).AsQueryable()
                .OrderBy(x => x.ItemCodeProductCode);
        }
    }
}

Repo link: https://github.com/Kishan5139/GraphqlPagination

What is expected?

Is there a way to increase the maximum first value allowed in a cursor-based pagination query using Hot Chocolate GraphQL?
I want to be able to fetch up to 1000 records per page, as my MongoDB collection contains over 18,000 documents.
Please advise on how to configure the maximum allowed page size on the server side.

What is actually happening?

Error Response:
{ "errors": [ { "message": "The maximum allowed items per page were exceeded.", "locations": [ { "line": 2, "column": 3 } ], "path": [ "laltexPimCoreSupplierData" ], "extensions": { "code": "HC0051", "fieldCoordinate": "QueriesResolver.laltexPimCoreSupplierData", "requestedItems": 51, "maxAllowedItems": 50 } } ], "data": { "laltexPimCoreSupplierData": null } }

Relevant log output

Additional context

Hello Team,
CC: @goldytech

Question:
Is there a way to increase the maximum first value allowed in a cursor-based pagination query using Hot Chocolate GraphQL?
I want to be able to fetch up to 1000 records per page, as my MongoDB collection contains over 18,000 documents.
Please advise on how to configure the maximum allowed page size on the server side.

Thanks in advance for your help!

@glen-84
Copy link
Collaborator

glen-84 commented May 9, 2025

Did you read the documentation?

You'll probably also need to adjust the Cost Analysis configuration.

Note that it's generally best not to return more than ~50-100 items at a time, as this can have an impact on memory efficiency (see this comment for more details).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants