graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

UseProjection breaks @defer and loads everything in one go

Open DavidErben opened this issue 3 years ago • 4 comments

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
    }
  }
}

grafik

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;
    }

grafik

This issue is maybe linked to the same problem: #5386

Steps to reproduce

  1. Use code from above without UseProjection attribute -> works fine
  2. 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

DavidErben avatar Oct 11 '22 14:10 DavidErben

 [UseProjection]
        public Book GetBook() => _book;

this would never work since projection needs an IQueryable

michaelstaib avatar Oct 15 '22 11:10 michaelstaib

@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 avatar Oct 15 '22 11:10 michaelstaib

@michaelstaib yes this would be possible

PascalSenn avatar Oct 15 '22 13:10 PascalSenn

 [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: grafik

Without UseProjection: grafik

DavidErben avatar Oct 17 '22 06:10 DavidErben