From 9397de4fc049edd113ed1a3282c96aa9e13e35f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Marti=C5=A1ka?= Date: Tue, 9 Mar 2021 12:05:34 +0100 Subject: [PATCH] Fix GraphQL queries returning Collection.class in native mode --- .../graphql/deployment/SmallRyeGraphQLProcessor.java | 1 + .../io/quarkus/it/smallrye/graphql/GreetingResource.java | 8 ++++++++ .../quarkus/it/smallrye/graphql/GreetingResourceTest.java | 3 +++ 3 files changed, 12 insertions(+) diff --git a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java index 50a616dc55d9b..177613933e365 100644 --- a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java +++ b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java @@ -268,6 +268,7 @@ private Class[] getGraphQLJavaClasses() { classes.add(graphql.schema.GraphQLSchema.class); classes.add(graphql.schema.GraphQLTypeReference.class); classes.add(List.class); + classes.add(Collection.class); return classes.toArray(new Class[] {}); } diff --git a/integration-tests/smallrye-graphql/src/main/java/io/quarkus/it/smallrye/graphql/GreetingResource.java b/integration-tests/smallrye-graphql/src/main/java/io/quarkus/it/smallrye/graphql/GreetingResource.java index d5dcd75dab4bd..e3708cb98a71f 100644 --- a/integration-tests/smallrye-graphql/src/main/java/io/quarkus/it/smallrye/graphql/GreetingResource.java +++ b/integration-tests/smallrye-graphql/src/main/java/io/quarkus/it/smallrye/graphql/GreetingResource.java @@ -2,6 +2,7 @@ import java.time.LocalTime; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.eclipse.microprofile.config.inject.ConfigProperty; @@ -36,6 +37,13 @@ public Greetings load(Greetings greetings) { public List buildInOptions(@Source Greeting greeting) { List options = new ArrayList<>(); options.add(new Hello()); + return options; + } + + @Name("options2") + // make sure that returning Collection.class does not break native mode + public Collection buildInOptionsCollection(@Source Greeting greeting) { + List options = new ArrayList<>(); options.add(new Morning()); return options; } diff --git a/integration-tests/smallrye-graphql/src/test/java/io/quarkus/it/smallrye/graphql/GreetingResourceTest.java b/integration-tests/smallrye-graphql/src/test/java/io/quarkus/it/smallrye/graphql/GreetingResourceTest.java index fb313728f51c5..9ff8af8a1d9e4 100644 --- a/integration-tests/smallrye-graphql/src/test/java/io/quarkus/it/smallrye/graphql/GreetingResourceTest.java +++ b/integration-tests/smallrye-graphql/src/test/java/io/quarkus/it/smallrye/graphql/GreetingResourceTest.java @@ -22,6 +22,9 @@ void testEndpoint() { " options{\n" + " message\n" + " }\n" + + " options2{\n" + + " message\n" + + " }\n" + " }\n" + " farewell:farewell{\n" + " type\n" +