From 433c776ada8623487438983c94ae00e5767d58c5 Mon Sep 17 00:00:00 2001 From: Marek Skacelik Date: Mon, 9 Dec 2024 14:37:09 +0100 Subject: [PATCH 1/2] fix: Record implementing interface field --- .../schema/creator/type/InterfaceCreator.java | 6 +- .../RecordImplementingInterfaceTest.java | 89 +++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 server/integration-tests/src/test/java/io/smallrye/graphql/tests/records/RecordImplementingInterfaceTest.java diff --git a/common/schema-builder/src/main/java/io/smallrye/graphql/schema/creator/type/InterfaceCreator.java b/common/schema-builder/src/main/java/io/smallrye/graphql/schema/creator/type/InterfaceCreator.java index 8a21bca0b..41010d6d1 100644 --- a/common/schema-builder/src/main/java/io/smallrye/graphql/schema/creator/type/InterfaceCreator.java +++ b/common/schema-builder/src/main/java/io/smallrye/graphql/schema/creator/type/InterfaceCreator.java @@ -1,5 +1,8 @@ package io.smallrye.graphql.schema.creator.type; +import static io.smallrye.graphql.schema.Annotations.NAME; +import static io.smallrye.graphql.schema.Annotations.getAnnotationsForMethod; + import java.util.List; import org.jboss.jandex.ClassInfo; @@ -38,7 +41,8 @@ protected void addFields(Type interfaceType, ClassInfo classInfo, Reference refe // Add all fields from interface itself for (MethodInfo methodInfo : classInfo.methods()) { - if (MethodHelper.isPropertyMethod(Direction.OUT, methodInfo)) { + if (MethodHelper.isPropertyMethod(Direction.OUT, methodInfo) + || getAnnotationsForMethod(methodInfo).containsKeyAndValidValue(NAME)) { fieldCreator.createFieldForInterface(methodInfo, reference) .ifPresent(interfaceType::addField); } diff --git a/server/integration-tests/src/test/java/io/smallrye/graphql/tests/records/RecordImplementingInterfaceTest.java b/server/integration-tests/src/test/java/io/smallrye/graphql/tests/records/RecordImplementingInterfaceTest.java new file mode 100644 index 000000000..96ea3632e --- /dev/null +++ b/server/integration-tests/src/test/java/io/smallrye/graphql/tests/records/RecordImplementingInterfaceTest.java @@ -0,0 +1,89 @@ +package io.smallrye.graphql.tests.records; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.URL; +import java.util.List; + +import org.eclipse.microprofile.graphql.GraphQLApi; +import org.eclipse.microprofile.graphql.Name; +import org.eclipse.microprofile.graphql.Query; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import io.smallrye.graphql.tests.GraphQLAssured; + +@RunWith(Arquillian.class) +public class RecordImplementingInterfaceTest { + @Deployment + public static WebArchive deployment() { + return ShrinkWrap.create(WebArchive.class, "default.war") + .addClasses(CustomerProductResource.class, InternetLine.class, MobileLine.class, CustomerProduct.class); + } + + @ArquillianResource + URL testingURL; + + @Test + public void testRecordImplementingInterface() { + GraphQLAssured graphQLAssured = new GraphQLAssured(testingURL); + final String query = """ + query { + products { + name + } + } + """; + final String expected = """ + { + "data": { + "products": [ + { + "name": "Fiber 100" + }, + { + "name": "Mobile 1" + }, + { + "name": "Fiber 200" + }, + { + "name": "Mobile 2" + } + ] + } + } + """; + assertThat(graphQLAssured.post(query)).isEqualToIgnoringWhitespace(expected); + + } + + @GraphQLApi + public static class CustomerProductResource { + + @Query + public List getProducts() { + return List.of( + new InternetLine("Fiber 100", 100), + new MobileLine("Mobile 1", "123456789"), + new InternetLine("Fiber 200", 200), + new MobileLine("Mobile 2", "987654321")); + } + } + + public sealed interface CustomerProduct permits InternetLine, MobileLine { + @Name("name") // @Name("") is also valid, since it automatically uses the field name + String name(); + } + + public record InternetLine(String name, int speed) implements CustomerProduct { + } + + public record MobileLine(String name, String phoneNumber) implements CustomerProduct { + } +} From 15dd3edd996cb978cee5882f5884de3e3ce37e85 Mon Sep 17 00:00:00 2001 From: Marek Skacelik Date: Mon, 9 Dec 2024 14:37:45 +0100 Subject: [PATCH 2/2] updated impsort pluginu --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2642b2dba..9a890308a 100644 --- a/pom.xml +++ b/pom.xml @@ -62,8 +62,8 @@ 17 17 17 - 1.8.0 2.1.0 + 1.12.0 2.1.0