-
Notifications
You must be signed in to change notification settings - Fork 96
Fix method data fetcher #175
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
…not from the environment field
Field field = source.getClass().getDeclaredField(fieldName); | ||
field.setAccessible(true); | ||
return field.get(source); | ||
private Object getGraphQLFieldValue(Object source, String fieldName) throws IllegalAccessException, NoSuchFieldException, InvocationTargetException { |
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.
Separate to few methods, one that deals with fields and one that deals with methods
return field.get(source); | ||
private Object getGraphQLFieldValue(Object source, String fieldName) throws IllegalAccessException, NoSuchFieldException, InvocationTargetException { | ||
Method method = getMethod(source.getClass(), fieldName, ""); | ||
Method getMethod = getMethod(source.getClass(), fieldName, "get"); |
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.
call this method only if necessary (reflection takes a lot of time)
private Object getGraphQLFieldValue(Object source, String fieldName) throws IllegalAccessException, NoSuchFieldException, InvocationTargetException { | ||
Method method = getMethod(source.getClass(), fieldName, ""); | ||
Method getMethod = getMethod(source.getClass(), fieldName, "get"); | ||
Method isMethod = getMethod(source.getClass(), fieldName, "is"); |
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.
call this method only if necessary (reflection takes a lot of time)
package graphql.annotations.processor.util; | ||
|
||
public class PrefixesUtil { | ||
public static String createPrefix(String prefix, String 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 name of the function doesn't explain what the function does
Field field = null; | ||
while (clazz != null && field == null) { | ||
try { | ||
field = clazz.getDeclaredField(name); |
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.
should it be "getDeclaredField" or "getField"?
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.
getField returns only public fields (but for entire hirearchy), but we need private ones as well. So this method runs over the entire hirearchy and searches for private methods with this name.
fix #174