smallrye / smallrye-graphql

Implementation for MicroProfile GraphQL
Apache License 2.0
155 stars 89 forks source link

Constraints for list not included in schema #2131

Open robp94 opened 1 month ago

robp94 commented 1 month ago

If I have a class like this:

public class TestObject {
    private List<@Pattern(regexp = "^1") String> list;

    @Pattern(regexp = "^1")
    private String nonList;
    ...

I get a schema like this:

input TestObjectInput {
  list: [String]
  nonList: String @constraint(pattern : "^1")
}

For the type of the list, the constraint is not in the schema. Constraints for the list like max/min length do work.

jmartisk commented 1 month ago

I guess this is just another variation on https://github.com/smallrye/smallrye-graphql/issues/1366 We've made some progress in scanning generic types, but apparently there are still some gaps.

mskacelik commented 1 month ago

Most importantly, I think we do not yet support wrapper directives (and constraints directives via bean validation). I have started to work on the feature, but it will take some time to implement.

For #1366, the problem was that if the type argument contained @NonNull, every wrapper was non-null. See: https://github.com/smallrye/smallrye-graphql/blob/ba3cf915b94b169112f599b011eaab3febb79974/common/schema-builder/src/main/java/io/smallrye/graphql/schema/creator/WrapperCreator.java#L80

https://github.com/smallrye/smallrye-graphql/blob/ba3cf915b94b169112f599b011eaab3febb79974/server/implementation/src/main/java/io/smallrye/graphql/bootstrap/Bootstrap.java#L917

List<Set<Collection<@NonNull Integer>>> => [[[Int!]!]!]! List<Set<@NonNull Collection<Integer>>> => [[[Int]]] I might have fixed the issue locally, but I still need to test it...