-
Notifications
You must be signed in to change notification settings - Fork 54
feat: add support for mapping transient fields with entity class hierarchy introspection #168
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
Conversation
…tion fix(IntrospectoinUtils): throw RuntimeException for non existing fields fix: Jacoco RTE fix: add test coverage for transient fields with class hierarchy support fix: test typo
Codecov Report
@@ Coverage Diff @@
## master #168 +/- ##
============================================
+ Coverage 68.12% 68.36% +0.23%
- Complexity 502 513 +11
============================================
Files 33 33
Lines 2576 2598 +22
Branches 431 431
============================================
+ Hits 1755 1776 +21
- Misses 644 645 +1
Partials 177 177
Continue to review full report at Codecov.
|
} | ||
|
||
private static boolean isAnnotationPresent(Class<?> entity, String propertyName, Class<? extends Annotation> annotation){ | ||
private static Optional<Boolean> isAnnotationPresent(Class<?> entity, String propertyName, Class<? extends Annotation> annotation){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning Optional<Boolean>
is a little bit misleading in this case. In my opinion calling isXXX methods should always return pure boolean value by convention. Using API with Optional<Boolean>
leads us to the three-state logic we need to deal with. What do you think?
public static boolean isIgnored(Class<?> entity, String propertyName) { | ||
return isAnnotationPresent(entity, propertyName, GraphQLIgnore.class); | ||
return isAnnotationPresent(entity, propertyName, GraphQLIgnore.class) | ||
.orElseThrow(() -> new RuntimeException(new NoSuchFieldException(propertyName))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The orElse(false)
was added before to make sure that the application can start even if the field is not found. There may be a case that we have a getter that is not directly connected with any of the class' properties but is still mapped to the column in the database e.g.
public boolean isValuePresent(){
return value != null;
}
But you are right that we should probably throw this error anyway and try to deal with such failure on the higher level. What do you think?
This PR adds support for mapping entity fields that use Java
transient
modifier JPA transient fields mapping specification, i.e.The transient Java fields can be excluded from schema using
@GraphQLIgnore
annotation.