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

Document UserOrderByInput #15

Open
SachaG opened this issue Jun 4, 2018 · 5 comments
Open

Document UserOrderByInput #15

SachaG opened this issue Jun 4, 2018 · 5 comments

Comments

@SachaG
Copy link

SachaG commented Jun 4, 2018

It'd be nice to show an example for the UserOrderByInput type.

@SachaG
Copy link
Author

SachaG commented Jun 12, 2018

I found one here:

enum UserOrderByInput {
  # ascending and descending for all non-list scalar fields
}

query { users(orderBy: UserOrderByInput): [User!]}

query { users(orderBy: NAME_ASC) {name}}

I don't know if I'm a fan of NAME_ASC though? What about { name : 1 } or { name: -1 } like in Mongo?

@GromNaN
Copy link
Contributor

GromNaN commented Sep 24, 2018

The naming fieldName_ASC is concise and consistant with other parts of OpenCRUD like filtering.

There is an issue if we need to sort on several fields or on a field from a relation.

Proposition : orderBy could accept a list of fields:

query { users(orderBy: [UserOrderByInput] ): [User!]}
query { users(orderBy: [role_ASC, name_DESC] ) {name}}

GitHub style:

query  {
  user(login:"GromNaN") {
    issues(first:100, orderBy:{field:COMMENTS, direction:ASC}) {
      edges {
        node {
          id
          title
        }
      }
    }
  }
}

@Jannis
Copy link

Jannis commented Sep 24, 2018

Could the orderBy input type be a union, like this?

orderBy: UserOrderByInput! | [UserOrderByInput!]!

Assuming GraphiQL and other tools handle this right, they would still provide auto-completion for orderBy this way, especially in cases where only one attribute is needed.

@GromNaN
Copy link
Contributor

GromNaN commented Sep 24, 2018

Input type be a union is not supported (yet). graphql/graphql-spec#488

@sorenbs
Copy link
Contributor

sorenbs commented Nov 19, 2018

While GraphQL does not support union input types, a single input element is actually coerced into a single item list, so in this case we don't need a union type :-) See: prisma/prisma#95 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants