Skip to content

Add Mutable to StrawberryShake#9976

Open
michaelstaib wants to merge 2 commits into
mainfrom
mst/strawberry-shake-mutable
Open

Add Mutable to StrawberryShake#9976
michaelstaib wants to merge 2 commits into
mainfrom
mst/strawberry-shake-mutable

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings June 23, 2026 22:07
@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall coverage in the branch remains at 49%, unchanged from the branch.

Show a code coverage summary of the most impacted files.
File 303ba5f b35148b +/-
/home/runner/wo...ons.Document.cs 78% 66% -12%
/home/runner/wo...PromiseCache.cs 81% 78% -3%
/home/runner/wo...SchemaHelper.cs 90% 92% +2%
/home/runner/wo...peDefinition.cs 54% 73% +19%
/home/runner/wo...Ins/BuiltIns.cs 60% 80% +20%
/home/runner/wo.../ErrorHelper.cs 39% 68% +29%
/home/runner/wo...peDefinition.cs 50% 81% +31%
/home/runner/wo...eValueHelper.cs 0% 78% +78%
/home/runner/wo...veDefinition.cs 0% 86% +86%
/home/runner/wo...veDefinition.cs 0% 86% +86%

Code Coverage is in Public Preview. Learn more and provide us with your feedback.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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.Load now returns MutableSchemaDefinition).
  • Update analyzers/mappers to use I*TypeDefinition abstractions and directive argument access via DirectiveValueHelper.
  • Refactor tests to use a shared TestSchemaHelper and 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):
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.

2 participants