Stabilize queries generated object typedefs#1298
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces a deterministic sorting mechanism for generating object typedefs by grouping and ordering codec fields consistently. Key changes include the definition of a new FieldDef type, the introduction of a sorting function (getSortPriority) for codec fields, and updates to object generation functions to use the sorted fields.
Comments suppressed due to low confidence (1)
packages/gel/src/reflection/analyzeQuery.ts:263
- [nitpick] Adding inline comments in the unwrapSetCodec function to clarify why only fields with cardinality 'Many' or 'AtLeastOne' are unwrapped could help maintainers understand the decision logic better.
function unwrapSetCodec(field: FieldDef) {
Different instances can produce different field orders for Object codecs, so we should have an fully ordered sorting algorithm to stabilize the order. This should help codegen to be deterministic, or at least get us a little closer.
7e43ef1 to
e6658fe
Compare
1st1
left a comment
There was a problem hiding this comment.
Maybe it does make sense to add a test -- like we must make sure we never reorder named tuples... :)
Although... I guess JS doesn't care about positional access for named tuples. |
Yeah, exactly. Since types are structural, we can't easily detect if the order of properties is different other than comparing strings. We do already test it functionally, so hopefully that will cover this specific regression idea. |
Different instances can produce different field orders for Object codecs, so we should have an fully ordered sorting algorithm to stabilize the order. This should help codegen to be deterministic, or at least get us a little closer.
The sorting is now grouped in a logic manner like this:
Within those groups, fields are sorted by name.
After:
Before:
Diff: