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

Support for sorting and projections on filtered relation count

Open elad-legit opened this issue 2 years ago • 2 comments

Product

Hot Chocolate

Is your feature request related to a problem?

No

The solution you'd like

Hi - I would like to have the option to get count of filtered relations, and also sort on that count

Given the following EF schema:

Class A
{
    public string Id {get;set;}
    public string FieldA1 {get;set;}
    public string FieldA2 {get;set;}
    public IReadOnlyCollection<B> BList {get;set;}
}

class B
{
    public string Id {get;set;}
    public string FieldB1 {get;set;}
    public string FieldB2 {get;set;}
}

class Query
{
    public IQueryable<A> GetAllA();
}

i would like to be able to query using the following graphql request:

query {
  repositories (
      order: [{bCount:  ASC /* sort by the filter of bCount*/}]
  )
      {
    items {
        id
        fieldA1
        
        bCount(where: {fieldB: {some - filter})
      }
    totalCount
 }

I was looking through the docs and didn't find a native way to achieve this Can i achieve this with the existing features?

Thanks!

elad-legit avatar Mar 30 '23 15:03 elad-legit

cc @PascalSenn

michaelstaib avatar Apr 06 '23 20:04 michaelstaib

Hi @elad-legit

Currently, this is not possible. We cannot project nested pagination (which would provide a total count) or project a custom field. We also do not yet support sorting on custom expressions. These are features we plan to address once we finish the work on Fusion.

We already have a good idea of how to solve one of your issues. Sorting on the count of a subcollection is new though, but I understand the use case.

PascalSenn avatar Apr 06 '23 21:04 PascalSenn