graphql-platform
graphql-platform copied to clipboard
Bug UsePaging with MongoDb : is not supported for mongo paging
Is there an existing issue for this?
- [X] I have searched the existing issues
Product
Hot Chocolate
Describe the bug
When request totalCount
only is error like The provided source Services.Models.ProductCategory[] is not supported for mongo paging

But request with nodes
is normal working

Steps to reproduce
- Create project using MongoDb
- Service register like
services
.AddGraphQLServer()
.AddAuthorization()
.AddGlobalObjectIdentification()
.AddMongoDbPagingProviders(defaultProvider: true)
.SetPagingOptions(new PagingOptions()
{
IncludeTotalCount = true
})
.AddMongoDbProjections()
.AddMongoDbSorting()
.AddMongoDbFiltering()
.AddQueryType<Query>()
.AddMutationConventions(applyToAllMutations: true)
.ModifyOptions(o => o.EnableOneOf = true)
.AddMutationType<Mutation>();
- Define field in Query
[UsePaging]
[UseProjection]
[UseSorting]
[UseFiltering]
public IExecutable<ProductCategory> ProductCategories([Service] DbContext context)
{
var query = context.ProductCategories
.Find(e => e.ParentProductCategoryId == null)
.AsExecutable();
return query;
}
- Execute request follow as describe
Relevant log output
{
"errors": [
{
"message": "The provided source Services.Models.ProductCategory[] is not supported for mongo paging",
"extensions": {
"code": "HC0025"
}
}
],
"data": {
"productCategories": null
}
}
Additional Context?
No response
Version
13.0.5
Hi @sabuydee Thanks for reporting this issue. We have this under test, so this has to be a combination of things. Can you provide a simple repro of the issue in a github project?
Hi @PascalSenn this is simple repo https://github.com/sabuydee/MongoHotchocolateDebug
Any word on this one? Was there a work around @sabuydee?
@PascalSenn This place shouldn't throw
https://github.com/ChilliCream/graphql-platform/blob/9a08ac26af7baed29f351e266debf9fffe055c86/src/HotChocolate/MongoDb/src/Data/Paging/MongoDbOffsetPagingHandler.cs#L39
But this can be solved @sabuydee
using HotChocolate;
namespace ErpLite.Backend.Application.Common.Interfaces;
public interface IUserRepository
{
IExecutable<User> GetExecutable();
}
public class UserRepository : IUserRepository
{
private readonly IMongoCollection<User> _users;
public UserRepository(IMongoDbContext context)
{
_users = context.GetCollection<User>("Users");
}
public async Task<User?> GetByIdAsync(string id)
{
return await _users.Find(u => u.Id == id).FirstOrDefaultAsync();
}
public IExecutable<User> GetExecutable()
{
return _users.AsExecutable(); // Notice this! return .AsExecutable, but .AsQueryable().AsExecutable()
}
[UseOffsetPaging(typeof(User), IncludeTotalCount = true)]
[UseProjection]
[UseSorting]
[UseFiltering]
[Authorize(Policy = Permissionss.Users.View)]
public IExecutable<User> GetUsers([Service] IUserRepository userRepository) =>
userRepository.GetExecutable();