pub fn normalize_schema(schema: Schema) -> Normalized<Schema>Expand description
For any two Schemas that are considered “equal”, normalizing them with this function will make it such that:
- They compare as equal via PartialEq/Eq.
- They serialize to the same string via std::fmt::Display.
Schema “equality” in this context is invariant to the order of:
- Schema definitions/extensions, type definitions/extensions, and directive definitions
- Field definitions
- Argument definitions
- Input field definitions
- Enum value definitions
- Root operation types in schema definitions/extensions
- Members in union definitions/extensions
- Implemented interfaces in object/interface definitions/extensions
- Locations in directive definitions
- Directive applications
- Arguments of directive applications
- Input fields in arguments of directive applications
- Input fields in default values of argument/input field definitions
Note that PartialEq/Eq ignores whether a component comes from a schema/type definition or a schema/type extension, while std::fmt::Display serializes components per-extension. Accordingly, it may be preferable to serialize via std::fmt::Display to check for equality if component origin is relevant. We support this by specifically sorting component containers (e.g. directive lists) by content first, and then by component origin (where component origin sort order is determined by the content with that origin).
Also note that Schema uses vectors for (and accordingly PartialEq/Eq does not ignore the order of):
- Argument definitions
- Locations in directive definitions
- Directive applications
- Arguments of directive applications
- Input fields in arguments of directive applications
- Input fields in default values of argument/input field definitions