Add Mutable to StrawberryShake#9976
Open
michaelstaib wants to merge 2 commits into
Open
Conversation
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in the branch remains at 49%, unchanged from the branch. Show a code coverage summary of the most impacted files.
Code Coverage is in Public Preview. Learn more and provide us with your feedback. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates StrawberryShake’s code generation pipeline from HotChocolate.Schema (runtime schema) to HotChocolate.Types.Mutable.MutableSchemaDefinition / ISchemaDefinition, aligning analyzers and mappers with the mutable type system and reducing reliance on runtime schema-building infrastructure.
Changes:
- Replace runtime schema usage with mutable schema parsing/annotation (
SchemaHelper.Loadnow returnsMutableSchemaDefinition). - Update analyzers/mappers to use
I*TypeDefinitionabstractions and directive argument access viaDirectiveValueHelper. - Refactor tests to use a shared
TestSchemaHelperand adjust expectations for mutable schema behavior.
Reviewed changes
Copilot reviewed 50 out of 50 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/SchemaHelperTests.cs | Updates scalar lookup to IScalarTypeDefinition for mutable schema types. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/QueryDocumentRewriterTests.cs | Refactors test schema creation to use TestSchemaHelper. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/TestSchemaHelper.cs | Adds shared helper to build a StarWars schema and load it as mutable schema. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Mappers/TestDataHelper.cs | Refactors schema creation to use TestSchemaHelper. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Analyzers/InterfaceTypeSelectionSetAnalyzerTests.cs | Uses TestSchemaHelper; adjusts assertions for implementation ordering. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Analyzers/FragmentHelperTests.cs | Uses TestSchemaHelper to create schema. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Analyzers/FieldCollectorTests.cs | Uses TestSchemaHelper; switches to definition interfaces and explicit null-checks. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Analyzers/DocumentAnalyzerTests.cs | Uses TestSchemaHelper and passes schema extensions through helper. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/StrawberryShake.CodeGeneration.Razor.Tests.csproj | Adds DI package reference for compilation/reference pinning. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/CSharpCompiler.cs | Pins DI extension type to ensure assembly reference availability during Roslyn compilation. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/StrawberryShake.CodeGeneration.CSharp.Tests.csproj | Adds DI package reference for compilation/reference pinning. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/CSharpCompiler.cs | Pins DI extension type to ensure assembly reference availability during Roslyn compilation. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/TypeNameQueryRewriter.cs | Replaces EqualsOrdinal usage with StringComparison.Ordinal equality. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/SchemaHelper.cs | Replaces runtime schema building with mutable schema parsing + feature annotation and introspection injection. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/RemoveClientDirectivesRewriter.cs | Updates directive name comparisons to StringComparison.Ordinal. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/OperationDocumentHelper.cs | Updates schema parameter type to ISchemaDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/LeafTypeInterceptor.cs | Removes runtime schema interceptor (superseded by mutable schema annotation). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/FragmentRewriter.cs | Updates directive name comparisons to StringComparison.Ordinal. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/EntityTypeInterceptor.cs | Removes runtime schema interceptor (superseded by mutable schema annotation). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/StrawberryShake.CodeGeneration.csproj | Replaces HotChocolate.Core dependency with abstractions + mutable schema references. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/ScalarNames.cs | Adds StrawberryShake-local scalar name constants used during parsing/annotation. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/TypeDescriptorMapper.InputTypes.cs | Switches to ordinal string comparison without EqualsOrdinal. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/TypeDescriptorMapper.cs | Updates type checks to I*TypeDefinition interfaces and ordinal comparisons. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/OperationDescriptorMapper.cs | Resolves argument named type via NamedType().Name + ordinal compare. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/EntityIdFactoryDescriptorMapper.cs | Treats leaf-ness via IsLeafType() instead of ILeafType pattern. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/DataTypeDescriptorMapper.cs | Switches to definition interfaces for unions/objects and union membership lookup. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Extensions/TypeExtensions.cs | Generalizes runtime/serialization type access from ILeafType to ITypeDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/ErrorHelper.cs | Replaces schema error handling with SchemaInitializationException mapping. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Types/SerializationTypeDirectiveType.cs | Removes runtime directive type (mutable parser/directive inspection used instead). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Types/RuntimeTypeDirectiveType.cs | Removes runtime directive type (mutable parser/directive inspection used instead). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Types/RenameDirectiveType.cs | Removes runtime directive type (mutable parser/directive inspection used instead). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Types/EnumValueDirectiveType.cs | Removes runtime directive type (mutable parser/directive inspection used instead). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Models/OperationModel.cs | Updates operation root type from ObjectType to IObjectTypeDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Models/InputObjectTypeModel.cs | Updates input object type from InputObjectType to IInputObjectTypeDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Models/EnumValueModel.cs | Updates enum value type from EnumValue to IEnumValue. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Models/ClientModel.cs | Updates schema storage from runtime Schema to MutableSchemaDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/InputObjectTypeUsageAnalyzer.cs | Switches analyzer input from Schema to ISchemaDefinition + definition interfaces. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/IDocumentAnalyzerContext.cs | Updates operation root type to IObjectTypeDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/FragmentHelper.cs | Switches string comparisons to ordinal Equals. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/FieldCollector.cs | Updates __typename field handling to be schema-definition based and uses TypeNameField.For(type). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/EnumTypeUsageAnalyzer.cs | Switches analyzer input from Schema to ISchemaDefinition + definition interfaces. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DocumentAnalyzerContext.cs | Updates stored schema type and leaf-type registration logic to mutable definitions. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DocumentAnalyzer.cs | Updates analyzer schema field/type to MutableSchemaDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DocumentAnalyzer.CollectOutputTypes.cs | Switches type-kind checks to I*TypeDefinition interfaces. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DocumentAnalyzer.CollectInputObjectTypes.cs | Switches to directive-argument reading via DirectiveValueHelper and definition interfaces. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DocumentAnalyzer.CollectEnumTypes.cs | Switches to directive-argument reading via DirectiveValueHelper and definition interfaces. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DirectiveValueHelper.cs | Adds helper to read string arguments from directive instances in mutable schema. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/Generators/JsonResultBuilderGenerator_DeserializeDataType.cs | Switches __typename checks to ordinal Equals. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/Generators/DataTypeGenerator.cs | Switches __typename checks to ordinal Equals. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/CSharpGenerator.cs | Switches schema creation/validation to mutable schema and updates schema error handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
42
to
70
| @@ -59,56 +66,40 @@ public static Schema Load( | |||
| } | |||
| else | |||
| { | |||
| foreach (var scalar in document.Definitions.OfType<ScalarTypeDefinitionNode>()) | |||
| { | |||
| if (!BuiltInScalarNames.IsBuiltInScalar(scalar.Name.Value)) | |||
| { | |||
| builder.AddType(new AnyType( | |||
| scalar.Name.Value, | |||
| scalar.Description?.Value)); | |||
| } | |||
| else if (scalar.Name.Value == ScalarNames.Any) | |||
| { | |||
| builder.AddType(new AnyType()); | |||
| } | |||
| else if (scalar.Name.Value == "JSON") | |||
| { | |||
| builder.AddType(new AnyType()); | |||
| } | |||
| } | |||
|
|
|||
| builder.AddDocument(document); | |||
| definitions.AddRange(document.Definitions.Select(NormalizeDefinition)); | |||
| } | |||
Comment on lines
25
to
27
| var typeInfos = new TypeInfos(); | ||
| var lookup = new Dictionary<ISyntaxNode, string>(); | ||
| IndexSyntaxNodes(schemaFiles, lookup); |
Comment on lines
22
to
+23
| ArgumentNullException.ThrowIfNull(schemaFiles); | ||
| _ = strictValidation; |
Comment on lines
+83
to
+86
| AddIntrospectionFields(schema); | ||
| AnnotateSchema(schema, leafTypes, globalEntityPatterns, typeEntityPatterns); | ||
|
|
||
| return schema; |
Comment on lines
+450
to
+456
| private static void TryAddScalarDefinition(MutableSchemaDefinition schema, string typeName) | ||
| { | ||
| if (!schema.Types.TryGetType(typeName, out _)) | ||
| { | ||
| schema.Types.Add(new MutableScalarTypeDefinition(typeName) { IsSpecScalar = true }); | ||
| } | ||
| } |
Comment on lines
72
to
+75
| Assert.Collection( | ||
| context.GetImplementations(result), | ||
| model => Assert.Equal("IGetHero_Hero_Human", model.Name), | ||
| model => Assert.Equal("IGetHero_Hero_Droid", model.Name)); | ||
| model => Assert.Equal("IGetHero_Hero_Droid", model.Name), | ||
| model => Assert.Equal("IGetHero_Hero_Human", model.Name)); |
Comment on lines
160
to
+163
| Assert.Collection( | ||
| context.GetImplementations(result), | ||
| model => Assert.Equal("IGetHero_Hero_Human", model.Name), | ||
| model => Assert.Equal("IGetHero_Hero_Droid", model.Name)); | ||
| model => Assert.Equal("IGetHero_Hero_Droid", model.Name), | ||
| model => Assert.Equal("IGetHero_Hero_Human", model.Name)); |
Comment on lines
+15
to
20
| if (current.Directives.Any(t => t.Name.Value.Equals(Returns, StringComparison.Ordinal))) | ||
| { | ||
| var directiveNodes = current.Directives.ToList(); | ||
| directiveNodes.RemoveAll(static t => t.Name.Value.EqualsOrdinal(Returns)); | ||
| directiveNodes.RemoveAll( | ||
| static t => t.Name.Value.Equals(Returns, StringComparison.Ordinal)); | ||
| current = current.WithDirectives(directiveNodes); |
Comment on lines
+378
to
+384
| foreach (var scalarName in scalarNames) | ||
| { | ||
| if (!declaredTypeNames.Contains(scalarName)) | ||
| { | ||
| TryAddScalarDefinition(schema, scalarName); | ||
| } | ||
| } |
Comment on lines
+509
to
+516
| foreach (var complexType in complexTypes) | ||
| { | ||
| if (globalEntityPatterns.FirstOrDefault( | ||
| pattern => DoesPatternMatch(complexType, pattern)) is { } matchedPattern) | ||
| { | ||
| complexType.Features.Set(new EntityFeature(matchedPattern)); | ||
| } | ||
| } |
| parentRuntimeTypeName = GetInterfaceName(outputType.Type.Name); | ||
| break; | ||
| case InterfaceType when (implementedBy?.Any(t => t.IsEntity()) == true): | ||
| case IInterfaceTypeDefinition when (implementedBy?.Any(t => t.IsEntity()) == true): |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.