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

Nested Paging entity Framework

Open s-leonard opened this issue 3 years ago • 9 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

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

s-leonard avatar Mar 14 '22 10:03 s-leonard

What error do you get when you define the type?

PascalSenn avatar Mar 14 '22 11:03 PascalSenn

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 avatar Mar 14 '22 13:03 s-leonard

@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')

s-leonard avatar Mar 14 '22 14:03 s-leonard

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 13 '22 15:05 stale[bot]

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')

zyofeng avatar May 19 '22 22:05 zyofeng

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

PascalSenn avatar May 20 '22 14:05 PascalSenn

@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.

zyofeng avatar May 25 '22 05:05 zyofeng

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

marek-nereca avatar Aug 18 '22 10:08 marek-nereca

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

candidodmv avatar Sep 02 '22 19:09 candidodmv

No news on this? @PascalSenn

BjornFrierPedersen avatar Nov 30 '23 08:11 BjornFrierPedersen

Hi, @PascalSenn: Any News ? Thx !

capitlux avatar Jun 04 '24 16:06 capitlux

@capitlux @BjornFrierPedersen

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

PascalSenn avatar Jun 04 '24 16:06 PascalSenn