Error when adding the UseMongoDbPaging()
when i add UseMongoDbPaging() to enable pagination, I get an error:
Unable to infer the element type from the current resolver. This often happens if the resolver is not an iterable type like IEnumerable, IQueryable, IList, etc. Ensure that you either explicitly specify the element type or that the return type of your resolver is an iterable type. (WebApplication1.GraphQL.RootQueryType)
the full exception details can be found here: https://github.com/YoussefSell/HotChocolate.Mongodb/blob/master/error.png
am using dotnet 5, and here are the packages am using in my project: "MongoDB.Driver" Version="2.12.3" "HotChocolate.AspNetCore" Version="11.2.2" "HotChocolate.AspNetCore.Authorization" Version="11.2.2" "HotChocolate.Data.MongoDb" Version="11.2.2"
I re-created the issue on a new sample project that can be found on my repository: https://github.com/YoussefSell/HotChocolate.Mongodb
The same to the post UsePaging -> UseFiltering -> UseSorting for EFCore towards PostgreSQL on NET 5. The error occurs as exactly topic mentioned.
descriptor.Field(nameof(GenericResolvers<User, string>.Filter))
.Name("filter")
.Resolve(context =>
{
var after = context.ArgumentValue<string>("after");
var first = context.ArgumentValue<int?>("first");
var sortBy = context.ArgumentValue<string>("sortBy");
IQueryable<User> users = context.Service<IGenericRepository<User, string>>().QueryAsNoTracking();
var edges = users.Select(user => new Edge<User>(user, user.Id)).ToList();
var pageInfo = new ConnectionPageInfo(false, false, null, null);
var connection = new Connection<User>(edges, pageInfo, ct => ValueTask.FromResult(0));
return connection;
})
.UsePaging();
.UseFiltering<UserFilterInputType>()
.UseSorting<User>();
However I try to change code according to instruction on homepage for make it easily to use only UsePaging middleware
descriptor.Field("users")
.UsePaging()
.Resolve(context =>
{
var queryable = context.Service<IGenericRepository<User, string>>();
return queryable.QueryAsNoTracking();
});
But the error is like above
Unable to infer the element type from the current resolver. This often happens if the resolver is not an iterable type like IEnumerable, IQueryable, IList etc. Ensure that you either explicitly specify the element type or that the return type of your resolver is an iterable type.
(QUI.AuthenticationAPI.GraphQL.AuthRootQuery)
at HotChocolate.Configuration.TypeInitializer.DiscoverTypes()
at HotChocolate.Configuration.TypeInitializer.Initialize(Func`1 schemaResolver, IReadOnlySchemaOptions options)
at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, DescriptorContext context, IBindingLookup bindingLookup, IReadOnlyList`1 types, LazySchema lazySchema)
at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder)
at HotChocolate.SchemaBuilder.Create()
at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create()
at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(NameString schemaName, RequestExecutorSetup options, IServiceProvider serviceProvider, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(NameString schemaName, RequestExecutorSetup options, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorNoLockAsync(NameString schemaName, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorAsync(NameString schemaName, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorProxy.GetRequestExecutorAsync(CancellationToken cancellationToken)
at HotChocolate.AspNetCore.HttpPostMiddleware.HandleRequestAsync(HttpContext context, AllowedContentType contentType)
at HotChocolate.AspNetCore.HttpPostMiddleware.InvokeAsync(HttpContext context)
at HotChocolate.AspNetCore.WebSocketSubscriptionMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)`
Here is the packages using
<PackageReference Include="HotChocolate.AspNetCore" Version="11.2.2" />
<PackageReference Include="HotChocolate.Data" Version="11.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.1" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.1" NoWarn="NU1605" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.1">
when i add UseMongoDbPaging() to enable pagination, I get an error:
Unable to infer the element type from the current resolver. This often happens if the resolver is not an iterable type like IEnumerable, IQueryable, IList, etc. Ensure that you either explicitly specify the element type or that the return type of your resolver is an iterable type. (WebApplication1.GraphQL.RootQueryType)
the full exception details can be found here: https://github.com/YoussefSell/HotChocolate.Mongodb/blob/master/error.png
am using dotnet 5, and here are the packages am using in my project: "MongoDB.Driver" Version="2.12.3" "HotChocolate.AspNetCore" Version="11.2.2" "HotChocolate.AspNetCore.Authorization" Version="11.2.2" "HotChocolate.Data.MongoDb" Version="11.2.2"
I re-created the issue on a new sample project that can be found on my repository: https://github.com/YoussefSell/HotChocolate.Mongodb
The return type you've specified manually is wrong: ListType<CountryGraphGraphType>.
Just omit the type and let it be inferred or use the correct type: CollectionSegmentType<CountryGraphGraphType>
The same to the post UsePaging -> UseFiltering -> UseSorting for EFCore towards PostgreSQL on NET 5. The error occurs as exactly topic mentioned.
descriptor.Field(nameof(GenericResolvers<User, string>.Filter)) .Name("filter") .Resolve(context => { var after = context.ArgumentValue<string>("after"); var first = context.ArgumentValue<int?>("first"); var sortBy = context.ArgumentValue<string>("sortBy"); IQueryable<User> users = context.Service<IGenericRepository<User, string>>().QueryAsNoTracking(); var edges = users.Select(user => new Edge<User>(user, user.Id)).ToList(); var pageInfo = new ConnectionPageInfo(false, false, null, null); var connection = new Connection<User>(edges, pageInfo, ct => ValueTask.FromResult(0)); return connection; }) .UsePaging(); .UseFiltering<UserFilterInputType>() .UseSorting<User>();However I try to change code according to instruction on homepage for make it easily to use only UsePaging middleware
descriptor.Field("users") .UsePaging() .Resolve(context => { var queryable = context.Service<IGenericRepository<User, string>>(); return queryable.QueryAsNoTracking(); });But the error is like above
Unable to infer the element type from the current resolver. This often happens if the resolver is not an iterable type like IEnumerable, IQueryable, IList etc. Ensure that you either explicitly specify the element type or that the return type of your resolver is an iterable type. (QUI.AuthenticationAPI.GraphQL.AuthRootQuery) at HotChocolate.Configuration.TypeInitializer.DiscoverTypes() at HotChocolate.Configuration.TypeInitializer.Initialize(Func`1 schemaResolver, IReadOnlySchemaOptions options) at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, DescriptorContext context, IBindingLookup bindingLookup, IReadOnlyList`1 types, LazySchema lazySchema) at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder) at HotChocolate.SchemaBuilder.Create() at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create() at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(NameString schemaName, RequestExecutorSetup options, IServiceProvider serviceProvider, CancellationToken cancellationToken) at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(NameString schemaName, RequestExecutorSetup options, CancellationToken cancellationToken) at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorNoLockAsync(NameString schemaName, CancellationToken cancellationToken) at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorAsync(NameString schemaName, CancellationToken cancellationToken) at HotChocolate.Execution.RequestExecutorProxy.GetRequestExecutorAsync(CancellationToken cancellationToken) at HotChocolate.AspNetCore.HttpPostMiddleware.HandleRequestAsync(HttpContext context, AllowedContentType contentType) at HotChocolate.AspNetCore.HttpPostMiddleware.InvokeAsync(HttpContext context) at HotChocolate.AspNetCore.WebSocketSubscriptionMiddleware.InvokeAsync(HttpContext context) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)`Here is the packages using
<PackageReference Include="HotChocolate.AspNetCore" Version="11.2.2" /> <PackageReference Include="HotChocolate.Data" Version="11.2.2" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.1" NoWarn="NU1605" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.1" NoWarn="NU1605" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.1">
In your case, if the return type of queryable.QueryAsNoTracking() is an IQueryable<User>, it should work as expected.
If it is and it doesn't work for whatever reason, you can try specifying the return type explicitly as: .Type<ConnectionType<UserType>>().
Hi @tobias-tengler, I haven't used UserType for User entity, but I change to .Type<ConnectionType<ObjectType<User>>>(). It is not working with the same error
Sorry, I got it wrong, try .UsePaging<ObjectType<User>>().
This is also covered by the documentation:

Thanks, it works, I haven't noticed about specifying the concrete node type. Anyway, thanks a lot :).
I too have a similar problem, when paginate with hotchocolate using a resolver.
I followed the documentation but it doesn't work. What am I doing wrong?
https://stackoverflow.com/questions/76500530/how-to-paginate-with-hotchocolate-using-a-resolver-i-followed-the-documentation