smallrye / smallrye-graphql

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

`List<@NonNull String>` should be `[String!]` not `[String!]!` #753

Open t1 opened 3 years ago

t1 commented 3 years ago

When I add a @NonNull to the element type of a list, the resulting list still should be nullable.

@GraphQLApi
public class Boundary {
    public @Query String foo(List<@NonNull String> strings) {
        return "bar";
    }
}

But it actually becomes:

type Query {
  foo(strings: [String!]!): String
}
computerlove commented 3 years ago

When building the model the information about annotations on the argument and its parameters are merged. ArgumentCreator:

    public Optional<Argument> createArgument(Operation operation, MethodInfo methodInfo, short position) {
     //methodInfo = java.util.List<java.lang.String> foo(java.util.List<@NonNull java.lang.String> list) 
     Annotations annotationsForThisArgument = Annotations.getAnnotationsForArgument(methodInfo, position);
    // annotationsForThisArgument = {org.eclipse.microprofile.graphql.NonNull=@NonNull}
   }

So the book keeping needs to be changed to not merge all annotations on the argument and its parameters. I make an attempt at fixing it.

velias commented 3 years ago

This relates to bug #740 also, as that bug is about Lists nested deeper in the generics structure, and it is related to how is model for GraphQL schema built for collections. At least we have to make sure we do not bring big conflicts when patching this and that bugs.

computerlove commented 3 years ago

Ok, I will wait for your work on #740.