dotansimha / dotansimha/graphql-code-generator-community

[c-sharp-operations] not handling interface as return type

Open
#201 1 comment 1 reaction 0 assignees View on GitHub
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

![GraphQLCodeGeneratorError](https://user-images.githubusercontent.com/11717447/177503678-150f643e-4925-4575-85df-4d01a27d8673.png)

### 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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.