dotansimha / dotansimha/graphql-code-generator-community
[c-sharp-operations] not handling interface as return type
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
### 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:
```GraphQL
type Query {
sampleQuery: [IMyReturnType!]!
}
interface IMyReturnType {
id: ID!
}
type MyReturnType implements IMyReturnType {
id: ID!
}
```
Operations:
```GraphQL
query GetSampleQuery {
sampleQuery {
id
}
}
```
codegen.yml:
```Yaml
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.:
```C#
using System;
using Newtonsoft.Json;
using GraphQL;
using GraphQL.Client.Abstractions;
namespace GraphQLCodeGen {
public class GetSampleQueryGQL {
///
/// GetSampleQueryGQL.Request
///
public static GraphQLRequest Request() {
return new GraphQLRequest {
Query = GetSampleQueryDocument,
OperationName = "GetSampleQuery"
};
}
/// This method is obsolete. Use Request instead.
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> SendQueryAsync(IGraphQLClient client, System.Threading.CancellationToken cancellationToken = default) {
return client.SendQueryAsync(Request(), cancellationToken);
}
}
}
```
### Screenshots or Videos

### Platform
- `@graphql-codegen/*` version: 2.7.0
### Codegen Config File
_No response_
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.