Skip to content

Add the covariant field merging opt-in to StrawberryShake codegen - #10414

Merged
glen-84 merged 1 commit into
mainfrom
gai/strawberry-shake-covariant-field-merging
Sep 21, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/strawberry-shake-covariant-field-merging

Conversation

@glen-84

@glen-84 glen-84 commented Sep 21, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds an enableCovariantFieldMerging setting to the strawberryShake extension in .graphqlrc.json, off by default. When enabled, both document validators in the code generator (the one in CSharpGenerator and the one behind DocumentAnalyzer) accept operations that merge fields whose return types differ only in nullability, matching the server-side EnableCovariantFieldMerging schema option from Add opt-in covariant field merging to selection set validation #10413.
  • Type generation is unchanged. Fields are already typed per concrete object type, so an implementation declaring String! gets string while a sibling declaring String gets string?, and a fragment on the interface keeps the interface's nullability.
  • Documents the setting on the StrawberryShake configuration page.

Test plan

  • Snapshot tests for both merge shapes with the setting enabled: inline fragments on sibling implementations, and an interface fragment spread next to a concrete selection.
  • A test that the existing field-conflict errors are still reported with the setting disabled, and one that the file-based generator entry point accepts the same document with it enabled.
  • The .graphqlrc.json deserialization test covers the new key.
  • The StrawberryShake.CodeGeneration and StrawberryShake.Tooling solutions built and tested with -p:EnforceCodeStyleInBuild=true.

Copilot AI lite review requested due to automatic review settings September 21, 2026 12:50
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ strawberry shake labels Sep 21, 2026

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.

Copilot review overview

🟢 Approval recommended

No unresolved review comments were supplied, and the configuration, validation, and generation paths are covered by tests.

Review effort: Lite
Findings: None

What changed in this PR

Adds opt-in covariant field merging to StrawberryShake configuration and code generation.

Changes:

  • Adds and documents enableCovariantFieldMerging.
  • Propagates the option through validation and generation.
  • Adds configuration, validation, generation, and snapshot tests.
File Description
website/​content/​docs/​strawberryshake/​configuration.md Documents the new setting.
src/​StrawberryShake/​Tooling/​test/​Configuration.Tests/​GraphQLConfigTests.cs Tests configuration deserialization.
src/​StrawberryShake/​Tooling/​test/​Configuration.Tests/​__snapshots__/​GraphQLConfigTests.Load_Json.snap Updates configuration snapshot.
src/​StrawberryShake/​Tooling/​test/​Configuration.Tests/​__snapshots__/​GraphQLConfigTests.Load_Json_With_Transport_Profiles.snap Updates transport profile snapshot.
src/​StrawberryShake/​Tooling/​test/​Configuration.Tests/​__snapshots__/​GraphQLConfigTests.Load_Json_With_Records.snap Updates records snapshot.
src/​StrawberryShake/​Tooling/​test/​Configuration.Tests/​__snapshots__/​GraphQLConfigTests.Load_Json_With_Documents_Array.snap Updates documents array snapshot.
src/​StrawberryShake/​Tooling/​src/​dotnet-graphql/​GeneratorHelpers.cs Maps configuration to generator settings.
src/​StrawberryShake/​Tooling/​src/​Configuration/​StrawberryShakeSettings.cs Adds the configuration property.
src/​StrawberryShake/​CodeGeneration/​test/​CodeGeneration.CSharp.Tests/​ResultTypeGeneratorTests.cs Tests covariant generated types.
src/​StrawberryShake/​CodeGeneration/​test/​CodeGeneration.CSharp.Tests/​GeneratorTestHelper.cs Supports generator test setup.
src/​StrawberryShake/​CodeGeneration/​test/​CodeGeneration.CSharp.Tests/​ErrorGeneratorTests.cs Tests validation errors.
src/​StrawberryShake/​CodeGeneration/​test/​CodeGeneration.CSharp.Tests/​__snapshots__/​ResultTypeGeneratorTests.Generate_Should_TypeFieldPerImplementation_When_CovariantMergingEnabled.snap Captures generated output.
src/​StrawberryShake/​CodeGeneration/​test/​CodeGeneration.CSharp.Tests/​__snapshots__/​ResultTypeGeneratorTests.Generate_Should_KeepInterfaceFragmentNullable_When_CovariantMergingEnabled.snap Captures nullable interface output.
src/​StrawberryShake/​CodeGeneration/​test/​CodeGeneration.CSharp.Tests/​__resources__/​CovariantFieldsSchema.graphql Adds schema fixture.
src/​StrawberryShake/​CodeGeneration/​test/​CodeGeneration.CSharp.Tests/​__resources__/​CovariantFieldsQuery.graphql Adds query fixture.
src/​StrawberryShake/​CodeGeneration/​src/​CodeGeneration/​Utilities/​OperationDocumentHelper.cs Configures document validation.
src/​StrawberryShake/​CodeGeneration/​src/​CodeGeneration/​Analyzers/​DocumentAnalyzer.cs Supports covariant merging during analysis.
src/​StrawberryShake/​CodeGeneration/​src/​CodeGeneration.CSharp/​CSharpGeneratorSettings.cs Adds the generator option.
src/​StrawberryShake/​CodeGeneration/​src/​CodeGeneration.CSharp/​CSharpGenerator.cs Applies covariant validation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

93.3% of changed lines covered (28/30)

File Covered Changed Patch %
…/src/CodeGeneration/Utilities/OperationDocumentHelper.cs 15 17 88.2% 🟡
…/CodeGeneration/src/CodeGeneration.CSharp/CSharpGenerator.cs 5 5 100.0% 🟢
…/src/CodeGeneration.CSharp/CSharpGeneratorSettings.cs 1 1 100.0% 🟢
…/src/CodeGeneration/Analyzers/DocumentAnalyzer.cs 6 6 100.0% 🟢
…/Tooling/src/Configuration/StrawberryShakeSettings.cs 1 1 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "1a398838ce9f8913c61fbf7bcaf9b8ecd88be3dc",
  "files": [
    { "path": "src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/OperationDocumentHelper.cs", "ranges": [[70, 71]] }
  ]
}

Project coverage: 58.4% (294410/504031 lines)

@glen-84
glen-84 merged commit ad47ef2 into main Sep 21, 2026
152 checks passed
@glen-84
glen-84 deleted the gai/strawberry-shake-covariant-field-merging branch September 21, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ strawberry shake

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants