dotansimha / dotansimha/graphql-code-generator-community
[C# operations] - generates duplicate classes
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
**Describe the bug**
When more properties of the same type are included in the same query/mutation, generator outputs duplicated classes with the same name in result cs file
**To Reproduce**
1. Include more fields with the same non-primitive type but different name in the schema
2. Make query/mutation to return all of the fields with the same type
3. Generate result cs file
Using example data in this issue, it generates TestSelection class 2-times in the same subclass which results to syntax error in C#.
1. My GraphQL schema:
```graphql
scalar Date
schema {
query: Query
}
type Query {
me: User!
another: User!
user(id: ID!): User
allUsers: [User]
search(term: String!): [SearchResult!]!
myChats: [Chat!]!
}
enum Role {
USER,
ADMIN,
}
interface Node {
id: ID!
}
union SearchResult = User | Chat | ChatMessage
type User implements Node {
id: ID!
username: String!
email: String!
role: Role!
test1: Test!
test2: Test!
}
type Test{
id: ID!
message: String!
}
type Chat implements Node {
id: ID!
users: [User!]!
messages: [ChatMessage!]!
}
type ChatMessage implements Node {
id: ID!
content: String!
time: Date!
fromUser: User!
toUser: User!
}
```
2. My GraphQL operations:
```graphql
query findUser($userId: ID!) {
user(id: $userId) {
...UserFields
}
}
fragment UserFields on User {
id
username
role
test1{
id
}
test2{
id
}
}
```
3. My `codegen.yml` config file:
```yml
generates:
src/main/c-sharp/my-org/my-app/Operations.cs:
plugins:
- c-sharp-operations
config:
typesafeOperation: true
```
**Expected behavior**
"Selection" classes should be named by fieldName instead of fieldType =>
1. public class Test1Selection
2. public class Test2Selection
**Environment:**
- `@graphql-codegen/c-sharp-operations`:
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the c-sharp-operations plugin entry point and reproduce the issue using the schema, UserFields operation, and codegen.yml shown here. Inspect the generated src/main/c-sharp/my-org/my-app/Operations.cs and verify that the result contains distinct Test1Selection and Test2Selection classes without a C# syntax error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, graphql, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100