smallrye-graphql icon indicating copy to clipboard operation
smallrye-graphql copied to clipboard

`@NonNull` at class/package level

Open ybroeker opened this issue 4 years ago • 1 comments

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?

ybroeker avatar Jul 20 '21 13:07 ybroeker

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.

t1 avatar Jul 20 '21 14:07 t1