Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order by totalCount with per-query custom filtering applied #36

Closed
jiqiang90 opened this issue Jan 10, 2023 · 2 comments
Closed

Order by totalCount with per-query custom filtering applied #36

jiqiang90 opened this issue Jan 10, 2023 · 2 comments
Labels
question Further information is requested

Comments

@jiqiang90
Copy link

Summary

Allow order by with totalCount

Additional context

I think this will expand on this issue #25

Currently we can filter with aggregate result, but not allow output to order by it.

For example, we have schema as follow:

type Author @entity{
  id:ID!
}

type Book @entity{
  id:ID!
  author: Author! //Fk author_id
  year: Int!
}

And we want to sort authors by the amount of books written after a certain year.

With pg-aggregates and connection-filter I could query list of authors and books written after year 1995,

However, the BOOKS_COUNT_DESC does not order by filtered result, it counts all books belong to author and order desc.

query {
  authors(
    orderBy: BOOKS_COUNT_DESC
    filter: {
      books: { 
        aggregates: { 
          distinctCount: { id: { greaterThan:"0" } } } 
      }
    }
  ) {
    nodes {
      id
      books(filter:{year:{greaterThanOrEqualTo:1995}}){
        totalCount
        nodes{
          id,
          year
        }
      }
    }
  }
}

Is there a generic solution for this? Rather than something like create additional plugin and make sortable on compute column. Thank you !

@benjie
Copy link
Member

benjie commented Jan 10, 2023

I don't think so.

@benjie benjie added the question Further information is requested label Jan 10, 2023
@benjie benjie changed the title Order by totalCount Order by totalCount with per-query custom filtering applied Jan 10, 2023
@benjie
Copy link
Member

benjie commented Oct 11, 2023

[semi-automated message] Thanks for your question. This doesn't currently seem to be a bug in the library so I'm going to close the issue, but please feel free to keep requesting help below and if it does turn out to be a bug we can definitely re-open it 👍

You can also ask for help in the #help-and-support channel in our Discord chat.

@benjie benjie closed this as completed Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants