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

Allow shallow sorting with lexicographicSortSchema #3971

Closed
kbrooks opened this issue Sep 15, 2023 · 2 comments
Closed

Allow shallow sorting with lexicographicSortSchema #3971

kbrooks opened this issue Sep 15, 2023 · 2 comments

Comments

@kbrooks
Copy link

kbrooks commented Sep 15, 2023

The lexicographicSortSchema function currently sorts both the top level types and the internal types of the provided schema. This has created an issue with code generation for me because the order of my graphql enums is being sorted which has a runtime impact on my code.

I would like to propose an optional parameter to this function which disables this "deep" sorting, instead only sorting the top level declarations.

dotansimha/graphql-code-generator#6935

@kbrooks
Copy link
Author

kbrooks commented Sep 16, 2023

For anybody who finds this issue I turned off the sorting with this patch
[email protected]

@IvanGoncharov
Copy link
Member

@kbrooks The purpose of lexicographicSortSchema is to sort everything is much as possible.
If you want to sort just top-level types, this can be done easily:

const schemaConfig = schema.toConfig();
const sortedSchema = new GraphQLSchema({
  ...schemaConfig,
  types: [...schemaConfig.types].sort((a, b) => a.name.localeCompare(b.name)),
});

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

2 participants