dotansimha / dotansimha/graphql-code-generator-community
@graphql-codegen/c-sharp does not generate required introspection types for Hot Chocolate EnableSemanticIntrospection
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
### Which packages are impacted by your issue?
@graphql-codegen/c-sharp
### Describe the bug
When generating a C# client from a Hot Chocolate schema with EnableSemanticIntrospection enabled, the generated client is incomplete and does not compile.
The generated code references the GraphQL introspection types __Type, __Field and __InputValue, however these types are not generated by the C# code generator.
As a result, the generated client cannot be compiled without manually adding these missing types.
### Your Example Website or App
none
### Steps to Reproduce the Bug or Issue
1. Create a Hot Chocolate GraphQL server.
2. Enable `EnableSemanticIntrospection`.
3. Generate a C# client using `@graphql-codegen/c-sharp`.
4. Build the generated client.
The generated code references __Type, __Field and __InputValue, but these types are not present in the generated output, causing compilation to fail.
### Expected behavior
The generated client should compile successfully.
If the generated code references GraphQL introspection types such as `__Type`, `__Field` and `__InputValue`, the generator should also emit the corresponding C# types.
### Screenshots or Videos
_No response_
### Platform
- OS: Windows
- graphql version: 16.14.1
- @graphql-codegen/cli: 7.2.0
- @graphql-codegen/c-sharp: 6.0.1
- @graphql-codegen/c-sharp-operations: 4.0.1
- @graphql-codegen/introspection: 6.1.0
- Hot Chocolate: 16.5.0
### Codegen Config File
```yaml
overwrite: true
schema: ./graphql.schema.json
documents: ./*.graphql
allowPartialOutputs: true
generates:
./Generated/Operations.cs:
plugins:
- c-sharp-operations
config:
namespaceName: MyClient
querySuffix: QueryService
mutationSuffix: MutationService
subscriptionSuffix: SubscriptionService
./Generated/Types.cs:
plugins:
- c-sharp
config:
namespaceName: MyClient
emitRecords: true
scalars:
DateTime: DateTime
LocalDate: DateOnly
Date: DateOnly
TimeSpan: TimeSpan
Duration: TimeSpan
Long: long
useIndexSignature: true
jsonAttributesSource: 'System.Text.Json'
memberNameConvention: 'pascalCase'
```
### Additional context
As a temporary workaround I added the missing introspection types manually:
```csharp
public abstract record __SchemaDefinition;
public record __Type : __SchemaDefinition
{
[JsonPropertyName("__typename")]
public string? TypeName { get; init; }
}
public record __Field : __SchemaDefinition
{
[JsonPropertyName("__typename")]
public string? TypeName { get; init; }
}
public record __InputValue : __SchemaDefinition
{
[JsonPropertyName("__typename")]
public string? TypeName { get; init; }
}
```
After adding these types, the generated client compiled and worked correctly against the Hot Chocolate server.
This suggests the generator is correctly generating references to these introspection types but is not generating the corresponding C# definitions.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the issue with the supplied Codegen config and inspect Generated/Types.cs for references to __Type, __Field, and __InputValue. Trace the @graphql-codegen/c-sharp generation path, then verify that the corresponding C# definitions are emitted and that the generated client compiles against the Hot Chocolate schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100