dotansimha/graphql-code-generator-community

[C# operations] - generates duplicate classes

Open

#105 创建于 2021年2月15日

在 GitHub 查看
 (0 评论) (1 反应) (0 负责人)TypeScript (195 fork)github user discovery
help wanted

仓库指标

Star
 (136 star)
PR 合并指标
 (PR 指标待抓取)

描述

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:

贡献者指南