smallrye-graphql
smallrye-graphql copied to clipboard
Make optional parameters nullable
It would be great to have an annotation for nullable/optional parameters. Here an example:
@Query("getYieldByPostcode") public Uni<YieldStats> getYield(@Name("fullPostcode") @NonNull String postcode, @Name("bedrooms") int bedrooms, @Name("houseType") String houseType){ return yieldService.getByFullPostCode(postcode,bedrooms,houseType); }
bedrooms and houseType are optional, as per today, I got to default them to a dummy value, check inside the method and pass null when required.
Thanks @dicolasi .
This case is when you have an Integer (Object) rather than a primitive, and it can be null. So it would be good to allow @Nullable on Object primitives.
Maybe I misunderstand this, but what would be passed as null for a primitive type? 0? -1? And it's irritating to have an Optional to be null, isn't it?
OTOH maybe it makes sense add a config option to invert the default, i.e. everything is NonNull by default. Then we'd need a Nullable for those fields that actually should be nullable. Only Optionals should remain always nullable.
Yes Optional<Integer> or OptionalInt should also work. @dicolasi that might be a clean solution than checking the -1 on the int value.