StrawberryShake vnext#9977
Open
michaelstaib wants to merge 1 commit 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 updates StrawberryShake code generation to align with “HotChocolate vnext” by switching schema handling from runtime Schema types/interceptors to MutableSchemaDefinition and ISchemaDefinition abstractions, and adjusts tests and generators accordingly.
Changes:
- Replaced schema construction/annotation via
SchemaBuilder+ interceptors with mutable schema parsing (SchemaParser) and post-parse annotation inSchemaHelper. - Updated analyzers/mappers/generators to use
I*TypeDefinition/ISchemaDefinitionAPIs and updated directive/value extraction. - Refactored tests to share StarWars schema creation and updated assertions impacted by new type/ordering behaviors.
Reviewed changes
Copilot reviewed 50 out of 50 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/SchemaHelperTests.cs | Updates scalar lookup to IScalarTypeDefinition against the new schema model. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/QueryDocumentRewriterTests.cs | Uses shared test schema factory instead of building the schema inline. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/TestSchemaHelper.cs | Adds helper to build StarWars schema and apply SDL extensions consistently across tests. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Mappers/TestDataHelper.cs | Uses shared StarWars schema helper for client model setup. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Analyzers/InterfaceTypeSelectionSetAnalyzerTests.cs | Migrates schema creation and adjusts implementation assertions affected by ordering changes. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Analyzers/FragmentHelperTests.cs | Migrates schema creation to shared helper. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Analyzers/FieldCollectorTests.cs | Migrates schema creation and updates type/variant assertions for the mutable schema model. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Analyzers/DocumentAnalyzerTests.cs | Migrates schema creation to shared helper and simplifies schema extension setup. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/StrawberryShake.CodeGeneration.Razor.Tests.csproj | Adds DI package reference needed by compiler pinning. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/CSharpCompiler.cs | Pins DI extension type to ensure it’s present during compilation tests. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/StrawberryShake.CodeGeneration.CSharp.Tests.csproj | Adds DI package reference needed by compiler pinning. |
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/CSharpCompiler.cs | Pins DI extension type to ensure it’s present during compilation tests. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/TypeNameQueryRewriter.cs | Replaces custom ordinal helper with string.Equals(..., Ordinal). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/SchemaHelper.cs | Replaces SchemaBuilder approach with mutable schema parsing and manual introspection/annotation. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/RemoveClientDirectivesRewriter.cs | Replaces custom ordinal helper with string.Equals(..., Ordinal). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/OperationDocumentHelper.cs | Generalizes validation schema parameter to ISchemaDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/LeafTypeInterceptor.cs | Removes interceptor-based leaf type annotation (superseded by mutable schema annotation). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/FragmentRewriter.cs | Replaces custom ordinal helper with string.Equals(..., Ordinal). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/EntityTypeInterceptor.cs | Removes interceptor-based entity feature annotation (superseded by mutable schema annotation). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/StrawberryShake.CodeGeneration.csproj | Replaces single Core reference with targeted abstraction/mutable/validation references. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/ScalarNames.cs | Adds centralized scalar name constants used across codegen/schema parsing. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/TypeDescriptorMapper.InputTypes.cs | Updates name comparisons to string.Equals(..., Ordinal). |
| 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 | Uses NamedType().Name and ordinal comparison to resolve argument types. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/EntityIdFactoryDescriptorMapper.cs | Uses IsLeafType() semantics rather than concrete leaf type interfaces. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/DataTypeDescriptorMapper.cs | Migrates unions/objects to IUnionTypeDefinition / IObjectTypeDefinition APIs. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Extensions/TypeExtensions.cs | Moves leaf type helpers to ITypeDefinition based feature access. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/ErrorHelper.cs | Switches schema error mapping to SchemaInitializationException-based path. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Types/SerializationTypeDirectiveType.cs | Removes runtime directive type registration (no longer used with mutable parsing). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Types/RuntimeTypeDirectiveType.cs | Removes runtime directive type registration (no longer used with mutable parsing). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Types/RenameDirectiveType.cs | Removes runtime directive type registration (no longer used with mutable parsing). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Types/EnumValueDirectiveType.cs | Removes runtime directive type registration (no longer used with mutable parsing). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Models/OperationModel.cs | Replaces ObjectType with IObjectTypeDefinition in the analyzed model. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Models/InputObjectTypeModel.cs | Replaces InputObjectType with IInputObjectTypeDefinition in the analyzed model. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Models/EnumValueModel.cs | Replaces concrete enum value type with IEnumValue. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/Models/ClientModel.cs | Switches analyzed schema to MutableSchemaDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/InputObjectTypeUsageAnalyzer.cs | Generalizes schema dependency to ISchemaDefinition and interfaces. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/IDocumentAnalyzerContext.cs | Updates operation type to IObjectTypeDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/FragmentHelper.cs | Updates ordinal comparisons to string.Equals(..., Ordinal). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/FieldCollector.cs | Updates __typename handling and comparisons for abstraction/mutable-type environment. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/EnumTypeUsageAnalyzer.cs | Generalizes schema dependency and migrates to I*TypeDefinition interfaces. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DocumentAnalyzerContext.cs | Switches schema to MutableSchemaDefinition and updates leaf-type registration logic. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DocumentAnalyzer.cs | Switches stored schema type to MutableSchemaDefinition. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DocumentAnalyzer.CollectOutputTypes.cs | Updates type checks to interface-based definitions. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DocumentAnalyzer.CollectInputObjectTypes.cs | Switches directive value extraction to string-arg helper and interface-based types. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DocumentAnalyzer.CollectEnumTypes.cs | Switches directive value extraction to string-arg helper and interface-based types. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Analyzers/DirectiveValueHelper.cs | Adds helper to read string directive arguments from IReadOnlyDirectiveCollection. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/Generators/JsonResultBuilderGenerator_DeserializeDataType.cs | Updates ordinal comparisons to string.Equals(..., Ordinal). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/Generators/DataTypeGenerator.cs | Updates ordinal comparisons to string.Equals(..., Ordinal). |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/CSharpGenerator.cs | Migrates schema creation to mutable schema path and updates schema error handling types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
+387
to
+394
| private static void AddBuiltInDirectiveDefinitions(MutableSchemaDefinition schema) | ||
| { | ||
| TryAddDirectiveDefinition(schema, BuiltIns.Include.Create(schema)); | ||
| TryAddDirectiveDefinition(schema, BuiltIns.Skip.Create(schema)); | ||
| TryAddDirectiveDefinition(schema, BuiltIns.Deprecated.Create(schema)); | ||
| TryAddDirectiveDefinition(schema, BuiltIns.SpecifiedBy.Create(schema)); | ||
| TryAddDirectiveDefinition(schema, BuiltIns.OneOf.Create()); | ||
| } |
Comment on lines
72
to
76
| 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
164
| 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
+88
to
+92
| Assert.Equal("Droid", selectionSetVariants.Variants[0].Type.Name); | ||
| Assert.Equal("Human", selectionSetVariants.Variants[1].Type.Name); | ||
|
|
||
| Assert.Collection( | ||
| selectionSetVariants.Variants[1].FragmentNodes, | ||
| selectionSetVariants.Variants[0].FragmentNodes, |
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): |
10 tasks
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.