dotansimha / dotansimha/graphql-code-generator-community

[c-sharp-operations] Duplicate type definition in response type

Open
#153 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

**Describe the bug**
Consider the mutation mentioned below inside the issue template at point 2:

Both fields, user and object share the same complex type(ObjectId). The following Response class is being generated:
The type for the selection is being generated twice as marked by the comments.
```csharp
public class Response {

public class UpdateObjectOutputSelection {

[JsonProperty("result")]
public string result { get; set; }

public class ObjectSelection {

// !!! Duplicate !!!
public class ObjectIdSelection {

[JsonProperty("id")]
public string id { get; set; }

}

[JsonProperty("object")]
public ObjectIdSelection object { get; set; }

// !!! Duplicate !!!
public class ObjectIdSelection {

[JsonProperty("id")]
public string id { get; set; }

}

[JsonProperty("user")]
public ObjectIdSelection user { get; set; }

}

[JsonProperty("updatedObject")]
public ObjectSelection updatedObject { get; set; }

}

[JsonProperty("move")]
public UpdateObjectOutputSelection move { get; set; }

}
```

1. My GraphQL schema:

```graphql
type UpdateObjectOutput {
result: String
updatedObject: Object
}

type Object {
object: ObjectId
user: ObjectId
}

type ObjectId {
id: String
}
```

2. My GraphQL operations:

```graphql
mutation Move($input: MoveInput) {
move(input: $input) {
result
updatedObject{
object{
id
}
user{
id
}
}
}
}
```

3. My `codegen.yml` config file:

```yml
...
src/operations.cs:
plugins:
- c-sharp-operations
config:
typesafeOperation: true
...
```

**Expected behavior**
The selection types should be based on the name of the field they exist for instead of the type of the field.
I already have a proposed change ready in my fork [here](https://github.com/smaktacular/graphql-code-generator/blob/49d0dcf3f125becb2ec4ffef21900a27a2dea1fb/packages/plugins/c-sharp/c-sharp-operations/src/visitor.ts#L313).

**Environment:**

- OS: Win 10
- `@graphql-codegen/c-sharp-operations 2.16`:
- NodeJS: 14.x

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.