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
Fix for #130 - Adds support for Boolean property accessors with 'get' prefix in PropertyDataFetcher #164
Conversation
} | ||
} | ||
|
||
private Object getPropertyViaGetterUsingPrefix(Object object, GraphQLOutputType outputType, String prefix) throws NoSuchMethodException { | ||
String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); | ||
try { | ||
Method method = object.getClass().getMethod(getterName); | ||
return method.invoke(object); | ||
|
||
} catch (NoSuchMethodException e) { |
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.
Can you just not have a catch block for NoSuchMethodException
?
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.
Right, just removed the unnecessary catch block for NoSuchMethodException
Thanks for the PR! Let me know if the comments make sense. |
It could also have an additional clause with a search for any property that contains (BTW Many new codes do not use |
Yes, thank you for this PR! Let's fix this, given the demand. What do you think about this: https://github.com/dminkovsky/graphql-java/blob/8efb230b58224488c335cc8409c17a73f0657b51/src/main/java/graphql/schema/PropertyDataFetcher.java I think it might be clearer? |
Thanks for review @markphilpot The current flow to find property data is as follows
|
@dminkovsky Looks simpler and more explanatory indeed. |
Whoops didn't mean to overload |
@ayhanap cool. If you like that more, feel free to update your PR with that variant and we can see what other people think. Will be glad to close this one. |
Updated the PR with @dminkovsky's cleaner suggestion. |
@ayhanap cool, thanks. I think there's also @markphilpot's question regarding that caught-and-then-immediately-thrown |
Sorry missed that. Fixed that. |
How do you think about earlier suggestion to allow any kind of prefix or postfix #164 (comment) ? I know classes with conventions like |
Yet another option, and easily added is a public overload that takes the prefix. |
I think searching for method names containing fielddefinition names could lead to some unexpected results.
And a POJO like this
What do you think @aschrijver. |
Yes, I agree, you are right with the search. It would be too much of a burden on the developer to get it right, and don't forget when adding a similarly-named member in future. Passing a prefix parameter could be solution. On a different note, related but not the same, I have a need to be able to define field aliases. I am discussing that on the metadata-related issues I created earlier. |
I kind of like the idea of keeping the surface of this class small, like it currently is. Property fetchers, after all, are a core public API. If people need some specific functionality they can write their own property fetcher and with lambda notation this is trivial for a simple property reference. To me, this PR is about responding to a specific repeated request from multiple users. So, let's revisit adding more functionality to this property fetcher when there is repeated, specific demand? I like how it looks right now as of this PR, especially with the removed unused fields. |
Yeah, that's no problem. Let's close this one. Given how busy I am it will be some time before I revisit this, maybe then I'll come up with a more elegant PR for other prefixes. We'll see.. |
Agree, those other requirements need more discussion and evaluation. Keeping in mind that this class is responsible of most of the data fetching, it should be fast and simple. |
Thanks Mark суббота, 20 августа 2016 г. пользователь Mark Philpot написал:
|
@dminkovsky Hailing from Russia or Ukrain? Then you are making even more late-nighters than me 😉 |
пожалуйста |
Oh no thankfully on the east coast of the US. Have my phone in Russian суббота, 20 августа 2016 г. пользователь Mark Philpot написал:
|
Lucky you, ha ha. I should be horizontal now at 04:00PM on the clock, not in S shape over laptop 😁 |
As mentioned in #130 some languages and frameworks uses "get" prefix for
Boolean
types. This was also the case for me. I use Lombok for generating accessors which also uses this convention. Even IDE's generate getters forBoolean
with "get"The prefix 'is' generally used for primitive
boolean
, Lombok has a option to disable this but not forBoolean
. So I think this functionality should be a part ofPropertyDataFetcher
. Otherwise it will be error prone or some unnecessary configuration/code for these fields.