graphql-platform: UseSelection combined with UsePaging throws an exception on query
I’ve found a potential bug within UseSelection feature, made in #1446.
Let’s build following context:
public class Query
{
[UseSelection]
[UseFiltering]
[UseSorting]
public IQueryable<Post> GetPosts([Service] PostDbContext db) => db.Posts;
}
When i create following GraphQL query:
query {
posts(order_by: {id: DESC} where: {id_gt: 25}) {
id
}
}
i get nice optimized SQL query:
SELECT [p].[Id]
FROM [Posts] AS [p]
WHERE [p].[Id] > 25
ORDER BY [p].[Id] DESC
But when i add [UsePaging] attribute as well:
public class Query
{
[UseSelection]
[UsePaging] //Added
[UseFiltering]
[UseSorting]
public IQueryable<Post> GetPosts([Service] PostDbContext db) => db.Posts;
}
and perform the essentially same GraphQL query (with Id wrapped inside nodes field):
query {
posts(order_by: {id: DESC} where: {id_gt: 25}) {
nodes {
id
}
}
}
i get exception:
Value cannot be null. (Parameter 'source')
at System.Linq.Queryable.Select[TSource,TResult](IQueryable`1 source, Expression`1 selector)\r\n
at HotChocolate.Types.SelectionMiddleware`1.InvokeAsync(IMiddlewareContext context) in ...\\Core\\Types.Selection\\SelectionMiddleware~1.cs:line 41\r\n
at HotChocolate.Execution.ExecutionStrategyBase.ExecuteMiddlewareAsync(ResolverContext resolverContext, IErrorHandler errorHandler) in ...\\Core\\Core\\Execution\\ExecutionStrategyBase.Resolver.cs:line 40
and if, for instance, i perform GraphQL query requesting only totalCount:
query {
posts(order_by: {id: DESC} where: {id_gt: 25}) {
totalCount
}
}
i get exception:
Type 'HotChocolate.Types.Relay.IConnection' does not have a default constructor (Parameter 'type')
at System.Linq.Expressions.Expression.New(Type type)\r\n
at HotChocolate.Types.Selections.SelectionClosure.CreateMemberInit() in ...\\Core\\Types.Selection\\SelectionClosure.cs:line 35\r\n
at HotChocolate.Types.Selections.SelectionClosure.CreateMemberInitLambda() in ...\\Core\\Types.Selection\\SelectionClosure.cs:line 41\r\n
at HotChocolate.Types.Selections.SelectionVisitor.Project[T]() in ...\\Core\\Types.Selection\\SelectionVisitor.cs:line 41\r\n
at HotChocolate.Types.SelectionMiddleware`1.InvokeAsync(IMiddlewareContext context) in ...\\Core\\Types.Selection\\SelectionMiddleware~1.cs:line 41\r\n
at HotChocolate.Execution.ExecutionStrategyBase.ExecuteMiddlewareAsync(ResolverContext resolverContext, IErrorHandler errorHandler)
in ...\\Core\\Core\\Execution\\ExecutionStrategyBase.Resolver.cs:line 40
Additional context: I’m using version 10.0.4-preview.17 i’ve pulled and manually built all required assemblies i’ve later included in my project, so there may be some hidden issue within that, but i wanted to share this problem anyway.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (10 by maintainers)
Commits related to this issue
- feat(Selection): fix paging meta data Adresses: #1534 — committed to ChilliCream/graphql-platform by PascalSenn 4 years ago
It appears this is working now.
I believe I can confirm, in my testing, that this works, as my test project which I migrated from my implementation to the official implementation was ordered the correct way as mentioned and I did not have a problem.
However, I’m using the fluent syntax, not the attribute syntax, so I can’t confirm that.