Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Plugin Should Respect namingConvention #798

Closed
mariusmuntean opened this issue Jul 29, 2024 · 7 comments
Closed

C# Plugin Should Respect namingConvention #798

mariusmuntean opened this issue Jul 29, 2024 · 7 comments

Comments

@mariusmuntean
Copy link
Contributor

mariusmuntean commented Jul 29, 2024

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

  • OS: macOS
  • NodeJS: v16.13.2
  • @graphql-codegen/c-sharp version(s): 5.0.0
  • @graphql-codegen/c-sharp-operations version(s): 3.0.0

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Collaborator

saihaj commented Aug 1, 2024

do you want to send in a PR @mariusmuntean ?

@mariusmuntean
Copy link
Contributor Author

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

@mariusmuntean
Copy link
Contributor Author

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

@mariusmuntean
Copy link
Contributor Author

Fully addressed by #806 and #816

@saihaj
Copy link
Collaborator

saihaj commented Sep 5, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants