graphql-platform
graphql-platform copied to clipboard
UseProjection breaks @defer and loads everything in one go
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
When using the UseProjection attribute, @defer does not work anymore. I could not find any info if this scenario is currently not supported or if it is a bug.
Easily reproducible with this setup:
public class Book
{
public string Cheap => "Foo";
public async Task<string> Expensive()
{
await Task.Delay(10000);
return "Bar";
}
}
public class Query
{
private static readonly Book _book = new();
public Book GetBook() => _book;
}
Then sending this query:
query Test {
book {
cheap
... @defer(label: "deferredValue") {
expensive
}
}
}

Works perfectly fine. If you put [UseProjection] on the GetBook method it breaks and takes 10 seconds to load with the same query.
public class Query
{
private static readonly Book _book = new();
[UseProjection]
public Book GetBook() => _book;
}

This issue is maybe linked to the same problem: #5386
Steps to reproduce
- Use code from above without UseProjection attribute -> works fine
- Put UseProjection attribute on GetBook method -> does not work anymore, loading takes 10 seconds even with @defer
Relevant log output
No response
Additional Context?
No response
Product
Hot Chocolate
Version
12.15.0
[UseProjection]
public Book GetBook() => _book;
this would never work since projection needs an IQueryable
@PascalSenn is there a way that we throw at schema build time if you put UseProjection on something that is not projectable? Can we figure that out?
@michaelstaib yes this would be possible
[UseProjection] public Book GetBook() => _book;this would never work since projection needs an
IQueryable
Sorry, my bad, this was indeed a bad example. But the issue remains with a correct example though.
public class Query
{
private static readonly IQueryable<Book> _books = new[] { new Book(), new Book() }.AsQueryable();
[UseProjection]
public IQueryable<Book> GetBooks() => _books;
}
With UseProjection:

Without UseProjection:
