dotansimha / graphql-code-generator-community

MIT License
119 stars 156 forks source link

Codegen c-sharp generate duplicate class definition on Response #901

Open eddeee888 opened 22 hours ago

eddeee888 commented 22 hours ago

Which packages are impacted by your issue?

@graphql-codegen/c-sharp

Describe the bug

Which packages are impacted by your issue?

No response

Describe the bug

When im generated c-sharp types from graphql schema i got multiple class generation for same Response. Exemple, :

public class GearSetupTypeSelection {

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

          public class ItemTypeSelection {

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

          }

          [JsonProperty("primaryWeapon")]
          public ItemTypeSelection primaryWeapon { get; set; }

          public class ItemTypeSelection {

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

          }

          [JsonProperty("secondaryWeapon")]
          public ItemTypeSelection secondaryWeapon { get; set; }

          public class ItemTypeSelection {

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

          }

          [JsonProperty("classItem")]
          public ItemTypeSelection classItem { get; set; }
}

I just want to have one public class ItemTypeSelection { ... } My graphql got fields like : primaryWeapon { ...ItemFields } secondaryWeapon { ...ItemFields} classItem {...ItemFields}

My nodejs codegen config is :

config: {
          namespaceName: 'Eva.GG.Client',
          typesafeOperation: true,
          defaultScalarType: 'object',
        },`

Your Example Website or App

havent

Steps to Reproduce the Bug or Issue

Have multiple identicals fragment on a query or mutation

Expected behavior

Just have one class definition

Screenshots or Videos

No response

Platform

Codegen Config File

import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  schema:
    'libs/shared/graphql/util-generator/src/lib/apps/backend/game/schema.graphql',
  documents:
    'libs/shared/graphql/util-generator/src/lib/apps/backend/game/operations/**/*.graphql',
  generates: {
    'libs/shared/graphql/util-generator/src/lib/apps/backend/game/output/Generated-v2.cs':
      {
        plugins: ['c-sharp-operations'],
        config: {
          namespaceName: 'Eva.GG.Client',
          typesafeOperation: true,
          defaultScalarType: 'object',
        },
      },
  },
};
export default config;

Additional context

No response

eddeee888 commented 22 hours ago

Hi @NicolasTarbouriech, I've transferred your issue here as this is the repo for the plugin/s in question