Skip to content

Add better schema formatting options#9510

Merged
michaelstaib merged 10 commits intomainfrom
mst/schema-formatter
Apr 9, 2026
Merged

Add better schema formatting options#9510
michaelstaib merged 10 commits intomainfrom
mst/schema-formatter

Conversation

@michaelstaib
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 8, 2026 06:09
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

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 PrintWidth to SyntaxSerializerOptions and threaded it through SyntaxSerializer to enable width-based line breaking.
  • Added Column tracking to ISyntaxWriter and implemented it in the StringSyntaxWriter implementations 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.

@tobias-tengler
Copy link
Copy Markdown
Member

I just noticed this weird formatting in the operation plan step operations today:
CleanShot 2026-04-08 at 10 31 57@2x
Maybe this PR can also fix this?

@michaelstaib
Copy link
Copy Markdown
Member Author

Thanks @tobias-tengler! This was caused by a double-indentation bug in the variable definition serializer — WriteMany's auto-indent-after-newline was conflicting with VisitVariableDefinition's own WriteIndent(). Fixed now — variable definitions will have consistent indentation in multi-line format.

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.

3 participants