Skip to content

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

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

Open
Kishan5139 opened this issue May 6, 2025 · 0 comments

Comments

@Kishan5139
Copy link
Owner

Kishan5139 commented May 6, 2025

Hello Team,
CC: @goldytech

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 the following error:

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 } }

Here is my Graphql Query

query {
  laltexPimCoreSupplierData(
    userID: "1fda6f80-f4f4-4307-a73e-873759f0c488"
    isUpdateCall: false
    page: 0
    pageSize: 10
    first: 51
    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);
        }
    }
}

I have created a sample project which you can use to reproduce the issue. Here is my repository link.
https://github.com/Kishan5139/GraphqlPagination

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!

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

No branches or pull requests

1 participant