[UseProjection] not working
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Product
Hot Chocolate
Describe the bug
Projection not working following document : ⚠️ Note: If you use more than one middleware, keep in mind that ORDER MATTERS. The correct order is UsePaging > UseProjection > UseFiltering > UseSorting
Steps to reproduce
here is my code
[UsePaging(MaxPageSize = 10)]
[UseProjection]
[UseFiltering]
[UseSorting]
public async Task<List<Project>> GetProjectsAsync(
[Service] IMediator mediator,
CancellationToken cancellationToken)
{
return await mediator.Send(new GetProjectsQuery(), cancellationToken);
}
public class GetProjectsQueryHandler : IRequestHandler<GetProjectsQuery, List<Project>>
{
private readonly IProjectRepository _repository;
public GetProjectsQueryHandler(IProjectRepository repository)
{
_repository = repository;
}
public async Task<List<Project>> Handle(GetProjectsQuery request, CancellationToken cancellationToken)
=> await _repository.GetAllProjects().ToListAsync(cancellationToken);
}
public class ProjectRepository : IProjectRepository
{
private readonly DbContext _context;
public ProjectRepository(DbContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
}
IQueryable<Project> IProjectRepository.GetAllProjects()
=> _context.Projects.AsQueryable().AsNoTracking();
}
Out put console
SELECT [p].[Id], [p].[CreatedBy], [p].[CreatedDate], [p].[Description], [p].[DueDate], [p].[Name], [p].[Status], [p].[UpdatedBy], [p].[UpdatedDate]
FROM [Projects] AS [p]
Program.cs
// This adds the GraphQL server core service and declares a schema.
builder.Services
.AddMemoryCache()
.AddGraphQLServer()
.AddAuthorization()
.AddQueryType()
.AddMutationType()
.AddDataLoaders()
.AddProjections()
.AddFiltering()
.AddSorting()
.AddInMemorySubscriptions()
.AddMutationConventions()
.AddTypeExtension<ProjectQueries>()
.AddTypeExtension<ProjectMutations>()
.AddTypeExtension<UserMutations>()
.InitializeOnStartup();
My Query
query{
projects{
nodes{
id
name
description
}
}
}
Relevant log output
SELECT [p].[Id], [p].[CreatedBy], [p].[CreatedDate], [p].[Description], [p].[DueDate], [p].[Name], [p].[Status], [p].[UpdatedBy], [p].[UpdatedDate]
FROM [Projects] AS [p]
Additional Context?
No response
Version
13.5.0-preview.8
Issue Analytics
- State:
- Created 2 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
UseProjection does not work on UnionType · Issue #6312
Expect to be able to UseProjection even when a UnionType is returned. If the resolver does not return an IQueryable then projection middleware ......
Read more >Am I misunderstanding Projections in HotChocolate?
public class Queries { [UseDbContext(typeof(DbAccess))] [UseProjection] public IQueryable<Name> GetNames([ScopedService] DbAccess db) ...
Read more >Projections - Hot Chocolate - ChilliCream GraphQL Platform
Fields that define a customer resolver cannot be projected to the database. If the middleware encounters a field that specifies UseProjection() ...
Read more >Projections - GRAPHQL API IN .NET w/ HOT CHOCOLATE #7.4
GraphQL - Running Queries (An introduction for .NET Developers [Using .NET 6 and C# 10]). DotNet Core Central•10K views.
Read more >Understanding Middleware in Hot Chocolate - YouTube
Hi everyone, I am Michael, and in this video, I will dive deep into the Hot Chocolate core to see what middleware is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Paging is also not working… its slicing in memory … which is not what you want.
Another issue you will run into is scoping btw…
In your case … the layering also makes no sense … as your repository exposes a queryable … this should not be the case and makes the repository pattern useless.
this is where you already execute against the DB … after this all is done.