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

Client support Kotlin annotation for NotNull

Open robp94 opened this issue 2 years ago • 12 comments

The server supports the Kotlin annotation for NotNull, the client does not.

Maybe it is similar simple to the server side https://github.com/smallrye/smallrye-graphql/issues/1109

robp94 avatar Jan 10 '23 16:01 robp94

@robp94 : maybe you could provide a PR?

t1 avatar Jan 16 '23 20:01 t1

I think we would need to do something like this, I not too familiar with the client code.

io.smallrye.graphql.client.impl.typesafe.reflection.ParameterInfo
    private String optionalExclamationMark(TypeInfo itemType) {
        if (itemType == this.type) {
            // Work around a weird GraalVM native mode behavior in which the object returned by
            // parameter.getAnnotatedType() does not include annotation metadata. So if we're
            // determining whether this Parameter itself is nullable, introspect the Parameter
            // instance itself rather than its AnnotatedType (which is what the
            // `itemType.isNonNull` method would do).
            return this.type.isPrimitive() || parameter.isAnnotationPresent(NonNull.class) || parameter.isAnnotationPresent(NotNull.class) ? "!" : "";      <-------------------
        } else {
            return itemType.isNonNull() ? "!" : "";
        }
    }

Furthermore, we would need the jetbrains annotations as a new dependency. @jmartisk @t1 are there any more places where non-null is handled?

robp94 avatar Jan 18 '23 15:01 robp94

I did not follow this closely, but please use Jandex and do not include the Jetbrains dependency (if you use Jandex you can use String values to reference the class)

phillip-kruger avatar Jan 18 '23 22:01 phillip-kruger

On the server side we did it with jandex, but either I overlooked it or there is no jandex on the client side.

robp94 avatar Jan 19 '23 08:01 robp94

Yeah we don't have Jandex on the client side (at least not yet). But I assume you can still try to call Class.forName() to obtain a class reference, and swallow the exception it might throw if the annotation's class isn't there.

jmartisk avatar Jan 19 '23 09:01 jmartisk

Would be ok for me. If this is the only place, I would do a pr on the weekend, probably.

robp94 avatar Jan 19 '23 09:01 robp94

OK, I though we are using Jandex on the client. We really need to do that. Is there an issue for that ?

phillip-kruger avatar Jan 19 '23 10:01 phillip-kruger

We have https://github.com/smallrye/smallrye-graphql/issues/873 for build-time scanning in the client

jmartisk avatar Jan 19 '23 11:01 jmartisk

Would be nice if client and server could use the same implementation, always a bit ugly if they behave differently.

Should I still do a PR for this issue?

robp94 avatar Jan 19 '23 11:01 robp94

Should I still do a PR for this issue?

Of course!

Some parts of the schema-builder will be reusable by the client, but not that much. The client doesn't build a full GraphQL schema (it doesn't even depend on graphql-java), it just converts interfaces and classes directly into GraphQL queries. So "using the same implementation" is only possible to some extent. And the schema builder will have to be changed quite heavily if we want to reuse it, because right now it's really built for creating a server-side GraphQL schema, which is not what the client wants. I vaguely remember trying to implement this change in the past, but I gave up, it was harder than initially expected.

jmartisk avatar Jan 19 '23 11:01 jmartisk

Hm, I missed that the Jetbrains Annotations are RetentionPolicy.CLASS, this will have to wait until the client uses jandex.

robp94 avatar Jan 22 '23 16:01 robp94

I see, ok.

jmartisk avatar Jan 23 '23 07:01 jmartisk