dotansimha / graphql-code-generator-community

MIT License
119 stars 156 forks source link

C# Plugin Should Respect namingConvention #798

Closed mariusmuntean closed 3 months ago

mariusmuntean commented 3 months ago

Which packages are impacted by your issue?

@graphql-codegen/c-sharp @graphql-codegen/c-sharp-operation

Describe the bug

The C# plugin doesn't take into account what the value of the config parameter namingConvention is. In C# it is customary for public property names to be pascal-case, but the plugin generates camel-case property names.

Your Example Website or App

https://codesandbox.io/p/devbox/github/mariusmuntean/graphql-code-generator-issue-sandbox-template-namingConventionIssue/tree/master/?file=%2Fcodegen.ts

Steps to Reproduce the Bug or Issue

  1. add namingConvention: 'change-case-all#pascalCase' to the config
  2. generate C# types
  3. All generated class properties have camel case names.

Expected behavior

As a user I expect the namingConvention config parameter to have an effect on the generated class property names, but the output always contains properties with camel case names.

Screenshots or Videos

No response

Platform

Codegen Config File

No response

Additional context

it('Should generate a C# class with pascal case property names for type', async () => {
      const schema = buildSchema(/* GraphQL */ `
        type User {
          id: Int
          chosenName: String
        }
      `);
      const result = await plugin(
        schema,
        [],
        {
          namingConvention: 'change-case-all#pascalCase',
        },
        {
          outputFile: '',
        },
      );
      expect(result).toBeSimilarStringTo(`
          [JsonProperty("id")]
          public int? Id { get; set; }

          [JsonProperty("chosenName")]
          public string ChosenName { get; set; }
          `);
    });
mariusmuntean commented 3 months ago

I'd like to work on this issue because I'd profit from it in my personal projects. Currently, after each code generation, I have to manually rename all the class members to pascal case.

mariusmuntean commented 3 months ago

Already have a working solution for controlling the naming convention for class names: https://github.com/mariusmuntean/graphql-code-generator-community/tree/fix/CSharpMemberNameCasing

saihaj commented 3 months ago

do you want to send in a PR @mariusmuntean ?

mariusmuntean commented 3 months ago

Yes, I'm familiarizing myself with the codebase and working on the improvement.

mariusmuntean commented 3 months ago

@saihaj my draft PR is ready. Please have a look and advise on how to proceed.

mariusmuntean commented 3 months ago

Fully addressed by #806 and #816

saihaj commented 2 months ago

released @graphql-codegen/c-sharp@5.1.0, @graphql-codegen/c-sharp-common@1.1.0, @graphql-codegen/c-sharp-operations@3.1.0