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 sorting only top level declarations in schema #5605

Open
kbrooks opened this issue Sep 19, 2023 · 1 comment
Open

Allow sorting only top level declarations in schema #5605

kbrooks opened this issue Sep 19, 2023 · 1 comment

Comments

@kbrooks
Copy link

kbrooks commented Sep 19, 2023

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

This library is a dependency of graphql-code-generator which is used to produce a generated schema file.

dotansimha/graphql-code-generator#6935

I opened an issue on graphql-js here graphql/graphql-js#3971 but it was closed due to there being a trivial work-around. We can use this approach in this library to resolve my issue.

Describe the solution you'd like

Add a field to the options on loadSchemaSync which enables sorting only the top level declarations

    return options.sort
       ? lexicographicSortSchema(sources[0].schema) 
       : options.sortShallow // naming?
       ? shallowSortSchema(sources[0].schema) 
       : sources[0].schema;

...

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

I can prepare a PR for this myself.

Describe alternatives you've considered

Currently I am applying a patch to the graphql-js lexicographicSortSchema function in order to produce my desired output.

Additional context

@erwan-joly
Copy link

Facing the same issue so would love to see this :)

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