graphql-code-generator
graphql-code-generator copied to clipboard
[c-sharp-operations] not handling interface as return type
Describe the bug
There seems to be an issue with the c-sharp-operations plug-in when trying to generate code for a query which returns an interface.
Using the live demo I'm getting the error message: "Cannot read properties of undefined (reading 'fields')"
Schema:
type Query {
sampleQuery: [IMyReturnType!]!
}
interface IMyReturnType {
id: ID!
}
type MyReturnType implements IMyReturnType {
id: ID!
}
Operations:
query GetSampleQuery {
sampleQuery {
id
}
}
codegen.yml:
generates:
src/main/c-sharp/my-org/my-app/Types.cs:
plugins:
- c-sharp-operations
config:
typesafeOperation: true
Your Example Website or App
Steps to Reproduce the Bug or Issue
Use the live demo (https://www.graphql-code-generator.com/) with the supplied schema and operations.
Expected behavior
I would expect the result to be similar to the result if the query returned MyReturnType e.g.:
using System;
using Newtonsoft.Json;
using GraphQL;
using GraphQL.Client.Abstractions;
namespace GraphQLCodeGen {
public class GetSampleQueryGQL {
/// <summary>
/// GetSampleQueryGQL.Request
/// </summary>
public static GraphQLRequest Request() {
return new GraphQLRequest {
Query = GetSampleQueryDocument,
OperationName = "GetSampleQuery"
};
}
/// <remarks>This method is obsolete. Use Request instead.</remarks>
public static GraphQLRequest getGetSampleQueryGQL() {
return Request();
}
public static string GetSampleQueryDocument = @"
query GetSampleQuery {
sampleQuery {
id
}
}
";
public class Response {
public class MyReturnTypeSelection {
[JsonProperty("id")]
public string id { get; set; }
}
[JsonProperty("sampleQuery")]
public MyReturnTypeSelection sampleQuery { get; set; }
}
public static System.Threading.Tasks.Task<GraphQLResponse<Response>> SendQueryAsync(IGraphQLClient client, System.Threading.CancellationToken cancellationToken = default) {
return client.SendQueryAsync<Response>(Request(), cancellationToken);
}
}
}
Screenshots or Videos

Platform
@graphql-codegen/*version: 2.7.0
Codegen Config File
No response
Additional context
No response