-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sort object members in typegen (conditionally) (#3808)
Summary: # This diff stack * This diff stack will sort the following items in generated graphql types: * Sorting of Inexact and Exact object keys * Sorting of fragment names in the right hand side of `$fragmentSpreads: Foo$fragmentType` * Sorting of union types * Addition of parentheses around union types * Sorting these is controlled by a rollout parameter, so we can change all the files in www in parts. # This diff * Sorts the props of Exact and InexactObjects (if the config option is enabled, or omitted) * Sorts props in the following order: ``` enum PropSortOrder { Typename, ClientId, KeyValuePair, GetterSetterPair, ObjectSpread, FragmentSpread, } ``` * Sort props at the creation time of Exact and Inexact objects, not at write time * Why sort things? There are a variety of situations in which the ordering of fields in the emitted output is arbitrary. For example, the order of fields in a linked field with inline fragments that gets merged into a linked field with optional keys is arbitrary. A developer might refactor relay-typegen to be more efficient but in the process change that arbitrary order. This change will make that refactor easier to land. * Within a Prop, sort by the ASTStringKey sort order of the prop name (either lefthand side or the spread value). * Also, derive Ord, Eq, PartialOrd and PartialEq for AST and related items. # Files to review * flow.rs and typescript.rs -> the only changes are to tests, you can safely ignore these files * lib.rs -> uses the new APIs. Mostly, this means passing `self.should_sort_typegen_items` whenever an `InexactObject` or `ExactObject` is created * writer.rs -> impl Ord in a custom way for Prop, sort props when creating InexactObjects and ExactObjects * other files -> generated changes cc kassens ---- Trying to start split #3280 into smaller parts. When writing objects (whether exact or inexact) in typegen, sort the object's members by name. The used sorting is a bit subjective, so I'm open to suggestions. rbalicki2 Pull Request resolved: #3808 Test Plan: Changes to generated files for the test project and fixtures. See D34469747 for changes this would do to generated files in xplat with rollout: 100. TLDR works as expected. Reviewed By: mofeiZ Differential Revision: D34439437 Pulled By: rbalicki2 fbshipit-source-id: a0c3825dc6259cb047d876e22c4ac8fcbd01eccc
- Loading branch information
1 parent
8beb0cb
commit b04b2b7
Showing
815 changed files
with
2,503 additions
and
2,402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.