graphql-tools
graphql-tools copied to clipboard
Allow sorting only top level declarations in schema
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.
https://github.com/dotansimha/graphql-code-generator/issues/6935
I opened an issue on graphql-js here https://github.com/graphql/graphql-js/issues/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
Facing the same issue so would love to see this :)