TriPSs / nestjs-query

Easy CRUD for GraphQL.
https://tripss.github.io/nestjs-query/
MIT License
151 stars 41 forks source link

Nested sorting #194

Open ValentinVignal opened 10 months ago

ValentinVignal commented 10 months ago

Is your feature request related to a problem? Please describe.

There were some issues on https://github.com/doug-martin/nestjs-query about being able to sort by nested fields:

which could be super helpful. I would like to be able to sort a list of Todos by their linked project name:

query myTodos {
  todos(
    # Sort by project name here
  ) {
    id # ID!
    name  # String!
    completed # Boolean!
    project {  # Project!
      id # ID!
      name # String!
    }
  }
}

In my case, I only have the need for "one-to-one" or "one-to-many" relationships (1 todo won't be linked to multiple projects)

Have you read the Contributing Guidelines?

Yes

Describe the solution you'd like

The solution offered https://github.com/doug-martin/nestjs-query/issues/559#issuecomment-713290342 was not too bad:

TodoSortFields {
  id
  name
  project__id
  project__name
}

Describe alternatives you've considered Writing my own custom resolver where I can implement my own sorting.

dvins commented 9 months ago

Separating the table from the column using a . might be better syntax.

ValentinVignal commented 9 months ago

Separating the table from the column using a . might be better syntax.

I don't think that possible, see this comment https://github.com/doug-martin/nestjs-query/issues/559#issuecomment-713290342

dvins commented 9 months ago

Thanks for pointing out @ValentinVignal, the double underscore makes sense.

dvins commented 1 month ago

By chance @TriPSs have you been able to look at this or have any insights on a preferred approach?

TriPSs commented 1 month ago

Have not looked at it, __ think it's good, changes of that colliding with other fields should be pretty low.