Add better schema formatting options#9510
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a print-width–aware formatting mode for GraphQL schema/query serialization, aiming to keep argument/variable/directive lists on one line when they fit, and wrap them when they exceed a configured width.
Changes:
- Added
PrintWidthtoSyntaxSerializerOptionsand threaded it throughSyntaxSerializerto enable width-based line breaking. - Added
Columntracking toISyntaxWriterand implemented it in theStringSyntaxWriterimplementations to support width measurement. - Updated many snapshot tests and formatter defaults to reflect the new single-line formatting when within
PrintWidth.
Reviewed changes
Copilot reviewed 64 out of 65 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Nitro/CommandLine/src/CommandLine.FusionCompatibility/FusionGraphPackage.cs | Switches serializer options to use PrintWidth default behavior. |
| src/HotChocolate/Mutable/src/Types.Mutable/Serialization/SchemaFormatter.cs | Uses PrintWidth = 80 for schema formatting output. |
| src/HotChocolate/Language/test/Language.Tests/Visitors/snapshots/SyntaxRewriterTests.Rename_Field.snap | Snapshot updated for new argument formatting output. |
| src/HotChocolate/Language/test/Language.Tests/Utilities/snapshots/SyntaxPrinterTests.Serialize_KitchenSinkWithIndentation_OutputIsFormatted.snap | Snapshot updated for compact variable definition formatting. |
| src/HotChocolate/Language/test/Language.Tests/Parser/snapshots/SchemaParserTests.ParserSimpleObjectType.snap | Snapshot normalization/formatting update. |
| src/HotChocolate/Language/test/Language.Tests/Parser/snapshots/SchemaParserTests.ParserSimpleInterfaceType.snap | Snapshot normalization/formatting update. |
| src/HotChocolate/Language/test/Language.Tests/Parser/snapshots/QueryParserTests.KitchenSinkQueryQuery.graphql | Snapshot updated for compact variable definition formatting. |
| src/HotChocolate/Language/test/Language.Tests/Parser/snapshots/KitchenSinkParserTests.ParseFacebookKitchenSinkSchema.snap | Snapshot updated for compact argument formatting. |
| src/HotChocolate/Language/test/Language.Tests/Parser/snapshots/KitchenSinkParserTests.ParseFacebookKitchenSinkQuery.snap | Snapshot updated for compact variable definition formatting. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/Utilities/snapshots/SchemaSyntaxPrinterTests.Serialize_ObjectTypeDefWithDescriptionWithIndent_OutHasIndentation.snap | Snapshot updated for compact argument formatting. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/Utilities/snapshots/SchemaSyntaxPrinterTests.Serialize_ObjectTypeDefWithArgsWithIndent_OutHasIndentation.snap | Snapshot updated for comma-separated args on one line. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/Utilities/snapshots/SchemaSyntaxPrinterTests.Serialize_InterfaceTypeDefWithDescriptionWithIndent_OutHasIndentation.snap | Snapshot updated for compact argument formatting. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/Utilities/snapshots/SchemaSyntaxPrinterTests.Serialize_InterfaceTypeDefWithArgsWithIndent_OutHasIndentation.snap | Snapshot updated for comma-separated args on one line. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/Utilities/snapshots/QuerySyntaxPrinterTests.Serialize_KitchenSinkWithoutIndentation_OutputIsOneLine.snap | Snapshot updated for compact variable definition formatting. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/Utilities/snapshots/QuerySyntaxPrinterTests.Serialize_KitchenSinkWithIndentation_OutputIsFormatted.snap | Snapshot updated for compact variable definition formatting. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/Utilities/snapshots/QuerySyntaxPrinterTests.Serialize_KitchenSinkWithIndentation_CanBeParsed.snap | Snapshot updated for compact variable definition formatting. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/SyntaxWriterTests.cs | Adjusts assertions to new print-width behavior for variable definitions. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/snapshots/SyntaxWriterTests.VariableDefinition_WithDefaultObjectValue_Indented_MatchesSnapshot.graphql | Snapshot updated for inline default object value formatting. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/snapshots/SyntaxWriterTests.DirectiveDefinition_Indented_MatchesSnapshot.graphql | Snapshot updated for comma-separated directive arguments. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/snapshots/SyntaxWriterTests.ArgumentsWithDirectives_Indented_MatchesSnapshot.graphql | Snapshot updated for comma-separated arguments with directives. |
| src/HotChocolate/Language/test/Language.SyntaxTree.Tests/snapshots/DirectiveDefinitionNodeTests.DirectiveDefinition_WithArgument_ToString.graphql | Snapshot updated for directive argument formatting. |
| src/HotChocolate/Language/src/Language.SyntaxTree/Utilities/SyntaxSerializerOptions.cs | Adds PrintWidth option (default 80). |
| src/HotChocolate/Language/src/Language.SyntaxTree/Utilities/SyntaxSerializer.SchemaSyntax.cs | Implements print-width-aware formatting for SDL argument definitions/directives. |
| src/HotChocolate/Language/src/Language.SyntaxTree/Utilities/SyntaxSerializer.QuerySyntax.cs | Implements print-width-aware formatting for operation variable definitions and field arguments. |
| src/HotChocolate/Language/src/Language.SyntaxTree/Utilities/SyntaxSerializer.cs | Threads PrintWidth into SyntaxSerializer. |
| src/HotChocolate/Language/src/Language.SyntaxTree/Utilities/StringSyntaxWriter.cs | Adds column tracking to support print-width decisions. |
| src/HotChocolate/Language/src/Language.SyntaxTree/Utilities/ISyntaxWriter.cs | Adds Column API to writers. |
| src/HotChocolate/Fusion/test/Fusion.Connectors.ApolloFederation.Tests/snapshots/SchemaTransformationIntegrationTests.Transform_FederationSubgraph_Should_ProduceValidCompositeSchema.graphql | New/updated snapshot for transformed schema output. |
| src/HotChocolate/Fusion/test/Fusion.Connectors.ApolloFederation.Tests/snapshots/SchemaTransformationIntegrationTests.Rewriter_Should_RewriteLookupToEntities_FromTransformedSchema.graphql | New/updated snapshot for rewritten entity query output. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaPreprocessorTests.cs | Snapshot strings updated (currently contains unresolved conflict markers). |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.Union.Tests.cs | Snapshot strings updated (currently contains unresolved conflict markers). |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.TagDirective.Tests.cs | Snapshot strings updated (currently contains unresolved conflict markers). |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.SerializeAsDirective.Tests.cs | Snapshot strings updated for compact directive formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.Scalar.Tests.cs | Snapshot strings updated for compact directive formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.OutputField.Tests.cs | Snapshot strings updated (currently contains unresolved conflict markers). |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.OneOfDirective.Tests.cs | Snapshot strings updated for compact input object formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.Object.Tests.cs | Snapshot strings updated (currently contains unresolved conflict markers). |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.McpToolAnnotationsDirective.Tests.cs | Snapshot strings updated for compact directive definition formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.ListSizeDirective.Tests.cs | Snapshot strings updated for compact directive formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.Interface.Tests.cs | Snapshot strings updated (currently contains unresolved conflict markers). |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.InputObject.Tests.cs | Snapshot strings updated for compact input object formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.InputField.Tests.cs | Snapshot strings updated for compact input field formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.GlobalObjectIdentification.Tests.cs | Snapshot strings updated for compact formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.EnumValue.Tests.cs | Snapshot strings updated for compact enum value formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.Enum.Tests.cs | Snapshot strings updated for compact enum formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.CostDirective.Tests.cs | Snapshot strings updated (currently contains unresolved conflict markers). |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.CacheControlDirective.Tests.cs | Snapshot strings updated for compact formatting and directive printing. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.AuthorizeDirective.Tests.cs | Snapshot strings updated for compact formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.Argument.Tests.cs | Snapshot strings updated (currently contains unresolved conflict markers). |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/snapshots/SourceSchemaPreprocessorTests.Preprocess_InferKeysFromLookupsEnabled_AppliesInferredKeyDirectives.graphql | Snapshot updated (currently contains unresolved conflict markers). |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/snapshots/SourceSchemaMergerTests.Merge_FourNamedSchemas_AddsFusionDefinitions.graphql | Snapshot updated for directive argument wrapping/formatting. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_SimpleEntity.md | Adds/updates formatted markdown snapshot output. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_RequiresDirective.md | Adds/updates formatted markdown snapshot output. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_ProvidesDirective.md | Adds/updates formatted markdown snapshot output. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_NonResolvableKey.md | Adds/updates formatted markdown snapshot output. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_NonResolvableAndResolvableKeys.md | Adds/updates formatted markdown snapshot output. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_MultipleKeys.md | Adds/updates formatted markdown snapshot output. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_KeyResolvableArgument.md | Adds/updates formatted markdown snapshot output. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_FullIntegration.md | Adds/updates formatted markdown snapshot output. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_ExternalDirective.md | Adds/updates formatted markdown snapshot output. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_CompositeKey.md | Adds/updates formatted markdown snapshot output. |
| src/HotChocolate/Fusion/src/Fusion.Language/StringSyntaxWriter.cs | Adds column tracking for fusion language writer. |
| src/HotChocolate/Fusion/src/Fusion.Language/ISyntaxWriter.cs | Adds Column API for fusion language writer interface. |
| src/HotChocolate/Fusion/src/Fusion.Execution.Types/Serialization/SchemaFormatter.cs | Uses PrintWidth = 80 for schema formatting output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks @tobias-tengler! This was caused by a double-indentation bug in the variable definition serializer — |

No description provided.