This gives C# developers more flexibility to enhance the generated types and it also allows to fix the current shortcoming of the plugin regarding GraphQL union types, which aren't supported.
If a generated class A is marked with the partial keyword, the developer can add another file next to the generated one and enhance the class A, e.g. make it inherit from an interface to fix the unsupported union type or add helper methods.
Class generated by the plugin GeneratedTypes.cs
internal partial class GeneratedTypes
{
internal partial class A
{
public int Idx { get; set; }
}
}
Class manually added by the dev GeneratedTypes.Partial.cs
internal partial class GeneratedTypes
{
internal interface IUnionType
{
}
internal partial class A : IUnionType
{
}
}
Proposal: extend the current plugin config with an option called partialTypes.
Possible values by type:
string: none (turns feature off), classes (marks all classes as partial), record (marks all record as partial), interfaces (marks all interfaces as partial), all (marks all classes, records and interfaces as partial).
predicate function (typeName: string) => bool: decides for every type individually if it should be marked as partial
set: a JavaScript set containing the types to mark as partial
No repro needed, just an enhancement to allow more flexibility.
Expected behavior
As a C# developer I expect to be able to extend the generated types with new functionality by using the C# partial class feature, but the generated classes aren't marked as partial.
Which packages are impacted by your issue?
@graphql-codegen/c-sharp
Describe the bug
The C# plugin should be configurable to allow generating C# partial classes. See docs: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/partial-type
This gives C# developers more flexibility to enhance the generated types and it also allows to fix the current shortcoming of the plugin regarding GraphQL union types, which aren't supported.
If a generated class A is marked with the
partial
keyword, the developer can add another file next to the generated one and enhance the class A, e.g. make it inherit from an interface to fix the unsupported union type or add helper methods.Class generated by the plugin
GeneratedTypes.cs
Class manually added by the dev
GeneratedTypes.Partial.cs
Proposal: extend the current plugin config with an option called
partialTypes
. Possible values by type:Your Example Website or App
https://codesandbox.io/p/devbox/github/mariusmuntean/graphql-code-generator-issue-sandbox-template-csharp-partial-types/tree/main/
Steps to Reproduce the Bug or Issue
No repro needed, just an enhancement to allow more flexibility.
Expected behavior
As a C# developer I expect to be able to extend the generated types with new functionality by using the C# partial class feature, but the generated classes aren't marked as partial.
Screenshots or Videos
No response
Platform
@graphql-codegen/c-sharp
version(s): 5.0.0Codegen Config File
No response
Additional context
No response