ardatan / ardatan/graphql-tools
Allow sorting only top level declarations in schema
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 830
- Avg merge
- 10h 59m
- Merged PRs (30d)
- 45
Description
**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
```js
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**
Contributor guide
Research direction
Start at the loadSchemaSync options and the existing lexicographicSortSchema path described in the issue. Check how GraphQLSchema is rebuilt from its config, then add an option that sorts only top-level declarations while preserving nested ordering; done means graphql-code-generator can use the new behavior without patching graphql-js.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100