ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.06k stars 723 forks source link

Nested Paging entity Framework #4841

Open s-leonard opened 2 years ago

s-leonard commented 2 years ago

Is there an existing issue for this?

Describe the bug

I'm using the entity framework integration and I have tried doing paging on a child collection with annotations

 public class Person 
  {
      [GraphQLDescription("Name of the member")]
      public string Name { get; set; }

      [GraphQLDescription("Things they like")]
      [UsePaging]
      public ICollection<Interest> Interests { get; set; } = new List<Interest>();
  }

which didn't work and I found another issue https://github.com/ChilliCream/hotchocolate/issues/4214 which suggests you cannot get nested paging to work with annotations.

So, I've tried to make a PersonType and define a resolver but it just breaks the schema and the just says encountered an error fetching the schema.


public class PersonType : ObjectType<Person>
{
    protected override void Configure(IObjectTypeDescriptor<Person> descriptor)
    {
        descriptor
               .Field(p => p.Name)
               .Description("Name of the member");

        descriptor
            .Field(p => p.Interests)
            .UsePaging()
            .ResolveWith<Resolvers>(p => p.GetInterests(default!, default!))
            .UseDbContext<AppDbContext>()
            .Description("Things they like");

    }

    private class Resolvers
    {
        public IQueryable<Interest> GetInterests([Parent] Person person, [ScopedService] AppDbContext context)
        {
            return context.Interests.Where(x => x.PersonId == person.Id);
        }
    }
}

If I remove the .UsePaging() the collection works but when I add it back the schema breaks and I cant find any docs on how to do paging for a collection within another object?

Steps to reproduce

Use entity framework integration, add child collection to a type apply add paging.

Relevant log output

No response

Additional Context?

No response

Product

Hot Chocolate

Version

12.0.0

PascalSenn commented 2 years ago

What error do you get when you define the type?

s-leonard commented 2 years ago

The UI says encountered an error fetching the schema but I'm not sure what the error is or how to see it

s-leonard commented 2 years ago

@PascalSenn I found how to get the schema error which I fixed by .UseDbContext<AppDbContext>() above .UsePaging()

and now it goes back to the same error I got when I was using the annotations which is

Type 'System.Collections.Generic.ICollection`1[App.Interest]' does not have a default constructor (Parameter 'type')
zyofeng commented 2 years ago

Have you ever got to the bottom of this issue?

@PascalSenn I found how to get the schema error which I fixed by .UseDbContext<AppDbContext>() above .UsePaging()

and now it goes back to the same error I got when I was using the annotations which is

Type 'System.Collections.Generic.ICollection`1[App.Interest]' does not have a default constructor (Parameter 'type')
PascalSenn commented 2 years ago

@zyofeng nested pagination is currently not projectiable i guess this is the issue

zyofeng commented 2 years ago

@zyofeng nested pagination is currently not projectiable i guess this is the issue

Not just pagination, UseFirstOrDefault also does not work. I tried opting out of Projection by using IsProjected attribute on the property but that does not seem to have made any difference.

marek-nereca commented 1 year ago

This issue is blocking for our project, any updates on this?

candidodmv commented 1 year ago

Hello @PascalSenn If I'm not missunderstood, currently is not possible to paginate nested objects with EF data provider?

BjornFrierPedersen commented 7 months ago

No news on this? @PascalSenn

capitlux commented 3 weeks ago

Hi, @PascalSenn: Any News ? Thx !

PascalSenn commented 3 weeks ago

@capitlux @BjornFrierPedersen

While it's not "automatic" projection, the following new concepts are avaialbe in v14: https://www.youtube.com/watch?v=kOGS7HI3lEA