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

Getter methods for boolean types #1209

Open
ramonaborg opened this issue May 19, 2023 · 2 comments
Open

Getter methods for boolean types #1209

ramonaborg opened this issue May 19, 2023 · 2 comments
Labels
breaking-change Breaking change enhancement New feature or request

Comments

@ramonaborg
Copy link

Getter methods for boolean types generated for both classes and interfaces, mirrored from the GraphQL schema are prefixed with get, however, the common practice is to have these prefixed with 'is'.

For instance, getter method for the boolean property active should be generated as isActive() and not getActive() as illustrated in the code snipped below.

Currently generated as:

public class Animal {
  String getName();
  String getType();
  Boolean getAdopted();
}

Should be generated like this:

public class Animal {
  String getName();
  String getType();
  Boolean isAdopted();
}
@esfomeado
Copy link
Contributor

The is convention applies only for the boolean primitive and not to Boolean.

Since the generated code produces a Boolean it should use get instead of is.

@ramonaborg
Copy link
Author

Yes, you are right Boolean should be generated with ‘get’ and the primitive type boolean should be with ‘is’. In the docs, there is listed that when a property is non-nullable it should be generated with primitive types. In this case the non-nullable boolean property should be generated with ‘is’

If we take into consideration the below code:

Interface ItemDefinition {
  Title: String!
  Description: String!
  Available: Boolean!
 } 

The code generated with the plugin will be like the below example (since the field is non-nullable it will use the boolean primitive type):

public Interface ItemDefinition {
  String getTitle();
  String getDescription();
  boolean getAvailable();   
 } 

@kobylynskyi kobylynskyi added enhancement New feature or request breaking-change Breaking change labels May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Breaking change enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants