dotansimha/graphql-code-generator-community

[C# operations] - generates duplicate classes

Open

#105 geöffnet am 15. Feb. 2021

Auf GitHub ansehen
 (0 Kommentare) (1 Reaktion) (0 zugewiesene Personen)TypeScript (195 Forks)github user discovery
help wanted

Repository-Metriken

Stars
 (136 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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:

Contributor Guide