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

If the sortSchema option is true, you want to sort the types, but not the fields. #3119

Closed
1 task done
dogemad opened this issue Feb 2, 2024 · 1 comment
Closed
1 task done
Labels

Comments

@dogemad
Copy link

dogemad commented Feb 2, 2024

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

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

The sortSchema: true option in GraphqlConfig performs alphabetical sorting. However, because it returns sorted results including all fields as well as type, there is a problem that the structure is not intuitive when looking at the schema.

Describe the solution you'd like

I think it would be very useful, if possible, to break down the options like this:

sortSchema?: boolean | {
    type?: boolean,
    field?: boolean
}

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

Let's say schema.graphql, built with sortSchema: false, looks like this:

type Board {
  id: ID!
  createdAt: DateTime!
  updatedAt: DateTime!
  text: String!

  author: Author!
}

type Author {
  id: ID!
  createdAt: DateTime!
  updatedAt: DateTime!

  boards: [Board!]
}

Even though Board is declared before Author, the roles and relationships of each type are explained in an intuitive and easy-to-understand manner.

But I want Author to be before Board in alphabetical sort order, so if I do the sortSchema: true option, the result will be:

type Author {
  boards: [Board!]
  createdAt: DateTime!
  id: ID!
  updatedAt: DateTime!
}

type Board {
  author: Author!
  createdAt: DateTime!
  id: ID!
  text: String!
  updatedAt: DateTime!
}

How do you feel? Is it easy to recognize? Probably not most people who see this type.
So I would like to get output like this:

type Author {
  id: ID!
  createdAt: DateTime!
  updatedAt: DateTime!

  boards: [Board!]
}

type Board {
  id: ID!
  createdAt: DateTime!
  updatedAt: DateTime!
  text: String!

  author: Author!
}
@dogemad dogemad added the feature label Feb 2, 2024
@kamilmysliwiec
Copy link
Member

Thanks for your suggestion!

This has been discussed in the past and we decided to not implement it in the foreseeable future.

If you think your request could live outside Nest's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

@nestjs nestjs locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants