Skip to content

Split enum value sorting from field sorting#9711

Merged
michaelstaib merged 3 commits into
mainfrom
mst/enum-sort
May 16, 2026
Merged

Split enum value sorting from field sorting#9711
michaelstaib merged 3 commits into
mainfrom
mst/enum-sort

Conversation

@michaelstaib
Copy link
Copy Markdown
Member

Fixes #9708

Copilot AI review requested due to automatic review settings May 15, 2026 21:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes regression where SortFieldsByName = true also sorted enum values in v16. Introduces a separate SortEnumValuesByName option (default false), restoring v15 behavior while still allowing opt-in enum sorting.

Changes:

  • Adds SortEnumValuesByName to IReadOnlySchemaOptions / SchemaOptions and a corresponding OrderEnumValuesByName to SchemaFormatterOptions.
  • Updates EnumType initialization and SchemaFormatter to sort enum values based on the new option (decoupled from field sorting).
  • Adds tests and an introspection snapshot covering the new behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs Adds SortEnumValuesByName to the read-only options interface.
src/HotChocolate/Core/src/Types/SchemaOptions.cs Adds the mutable property and propagates it in FromOptions.
src/HotChocolate/Core/src/Types/StoreGlobalSchemaOptionsTypeInterceptor.cs Forwards the new option into SchemaFormatterOptions.
src/HotChocolate/Core/src/Types/Types/EnumType.Initialization.cs Sorts enum values during type completion only when the new option is true.
src/HotChocolate/Core/src/Types.Abstractions/Serialization/SchemaFormatterOptions.cs Adds OrderEnumValuesByName and updates OrderFieldsByName doc.
src/HotChocolate/Core/src/Types.Abstractions/Serialization/SchemaFormatter.cs Uses the new option when ordering enum values during formatting.
src/HotChocolate/Core/test/Types.Tests/Types/EnumTypeTests.cs Adds tests for the new option (incl. introspection).
src/HotChocolate/Core/test/Types.Tests/Types/snapshots/EnumTypeTests.SortEnumValuesByName_Should_SortIntrospectionResult.md Snapshot for sorted introspection result.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@michaelstaib michaelstaib merged commit 4094138 into main May 16, 2026
8 of 9 checks passed
@michaelstaib michaelstaib deleted the mst/enum-sort branch May 16, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SchemaOptions.SortFieldsByName now also sorts enum values in v16 (regression vs v15)

2 participants