dotansimha/graphql-code-generator-community

[C# operations] - generates duplicate classes

Open

#105 aperta il 15 feb 2021

Vedi su GitHub
 (0 commenti) (1 reazione) (0 assegnatari)TypeScript (195 fork)github user discovery
help wanted

Metriche repository

Star
 (136 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

  4. My GraphQL schema:

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!
}

  1. My GraphQL operations:
query findUser($userId: ID!) {
  user(id: $userId) {
    ...UserFields
  }
}

fragment UserFields on User {
  id
  username
  role
  test1{
      id
  }
  test2{
      id
  }
}
  1. My codegen.yml config file:
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:

Guida contributor