smallrye-graphql
smallrye-graphql copied to clipboard
`@NonNull` at class/package level
It would be nice, if @NonNull (or an alternative annotation) could be used at class or package-level to mark all fields as non null.
Most of our classes look like this:
class API {
@Query @NonNull String someField() {...}
@Query Optional<String> someOptionalField() {...}
@Query @NonNull List<@NonNull String> someFields() {...}
@Mutation @NonNull SomePayload someFields(@NonNull SomeInput input) {...}
}
which could look like this if @NonNull on classes would be possible, where anything except someOptionalField would be non-null:
@NonNull
class API {
@Query String someField() {...}
@Query Optional<String> someOptionalField() {...}
@Query List<String> someFields() {...}
@Mutation SomePayload someFields(SomeInput input) {...}
}
I don't know if @NonNull is the best approach for this, maybe a new annotation to specify default nullability for fields, inputs, parameters would be better.
Maybe someone has an idea?
I like your suggestion, as we also prefer to make everything non-nullable. But when we configure it at a wider scope, we need to be able to define exceptions to the rule, i.e. a @Nullable annotation (or so). Maybe we could define the global setting in the config properties.