dgs-framework icon indicating copy to clipboard operation
dgs-framework copied to clipboard

bug:

Open hrdoujak opened this issue 3 years ago • 2 comments

Classes and constants in generated class DgsConstants.java do not follows common Java naming conventions, neither Kotlin naming convetions.

Also generated classes for clients has underscores in its names, which is not common for Java/Kotlin classes.

Expected behavior

Expected generated output:

public static class Employee {
    public static final String TYPE_NAME = "Employee";

    public static final String USERNAME = "username";

    public static final String FIRST_NAME = "firstName";

    public static final String LAST_NAME = "lastName";

    public static final String AGE = "age";
  }

Actual behavior

Example of generated class:

public static class EMPLOYEE {
    public static final String TYPE_NAME = "Employee";

    public static final String Username = "username";

    public static final String FirstName = "firstName";

    public static final String LastName = "lastName";

    public static final String Age = "age";
  }

Steps to reproduce

Generate DgsConstants.java class from any schema.graphqls.

Note: Maybe there is idea behind not-convention naming style; if so, i would really appreciate any explanation, thank you.

hrdoujak avatar Oct 25 '22 12:10 hrdoujak

I suppose we went with capitalizing the parent types and the field names are all lower case for readability. No other strong arguments one way or another. However, since it has been this way, it would be a breaking change to update this behavior. Is this causing particular problems for you, besides the fact that it is not what you expect?

srinivasankavitha avatar Oct 25 '22 16:10 srinivasankavitha

Thank you for your answer. We have problem with readability, to be honest. Java code in all projects meets given name conventions, developers are use to it, and we don't want to have at once on one place in code something different - it can be misleading at first sight. I believe that we are not the first team which can be little bit confused by seeing DgsConstants.EMPLOYEE.Username instead of DgsConstants.Employee.USERNAME in the code. One can think, that Username is not a constant.

Of course, it is a matter of style. I absolutely understand, that it would be a breaking change. But what about add possibility to customize constant generating to meet official java name convention? Does that make sense to you?

hrdoujak avatar Oct 25 '22 17:10 hrdoujak

Closing this as it's not something we're planning to change.

paulbakker avatar Aug 16 '24 21:08 paulbakker