From 8cbb4e5db10b84286f2dce419b74db3ff1b5dc0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20zu=20Dohna?= Date: Fri, 19 Jun 2020 14:51:16 +0200 Subject: [PATCH] #282: PR feedback --- client/generator-test/pom.xml | 5 +++-- .../graphql/api/{GraphQlErrorCode.java => ErrorCode.java} | 2 +- .../graphql/execution/error/ExecutionErrorsService.java | 5 +++-- .../graphql/execution/error/ExecutionErrorsServiceTest.java | 4 ++-- .../io/smallrye/graphql/test/apps/error/api/ErrorApi.java | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) rename server/api/src/main/java/io/smallrye/graphql/api/{GraphQlErrorCode.java => ErrorCode.java} (90%) diff --git a/client/generator-test/pom.xml b/client/generator-test/pom.xml index fcd07086f..09d0c275c 100644 --- a/client/generator-test/pom.xml +++ b/client/generator-test/pom.xml @@ -45,8 +45,9 @@ ${project.version} - org.eclipse.microprofile.graphql - microprofile-graphql-api + io.smallrye + smallrye-graphql-api + ${project.version} diff --git a/server/api/src/main/java/io/smallrye/graphql/api/GraphQlErrorCode.java b/server/api/src/main/java/io/smallrye/graphql/api/ErrorCode.java similarity index 90% rename from server/api/src/main/java/io/smallrye/graphql/api/GraphQlErrorCode.java rename to server/api/src/main/java/io/smallrye/graphql/api/ErrorCode.java index 4cef52bf1..faa28543d 100644 --- a/server/api/src/main/java/io/smallrye/graphql/api/GraphQlErrorCode.java +++ b/server/api/src/main/java/io/smallrye/graphql/api/ErrorCode.java @@ -9,6 +9,6 @@ @Retention(RUNTIME) @Target({ TYPE, ANNOTATION_TYPE }) -public @interface GraphQlErrorCode { +public @interface ErrorCode { String value(); } diff --git a/server/implementation/src/main/java/io/smallrye/graphql/execution/error/ExecutionErrorsService.java b/server/implementation/src/main/java/io/smallrye/graphql/execution/error/ExecutionErrorsService.java index aa2ef7e43..5193a3b9b 100644 --- a/server/implementation/src/main/java/io/smallrye/graphql/execution/error/ExecutionErrorsService.java +++ b/server/implementation/src/main/java/io/smallrye/graphql/execution/error/ExecutionErrorsService.java @@ -22,7 +22,7 @@ import graphql.ExceptionWhileDataFetching; import graphql.GraphQLError; import graphql.validation.ValidationError; -import io.smallrye.graphql.api.GraphQlErrorCode; +import io.smallrye.graphql.api.ErrorCode; /** * Help to create the exceptions @@ -94,7 +94,8 @@ private Optional getDataFetchingExtensions(ExceptionWhileDataFetchin } private String toErrorCode(Throwable exception) { - GraphQlErrorCode annotation = exception.getClass().getAnnotation(GraphQlErrorCode.class); + // TODO change to use the Model and the model needs to get this using Jandex + ErrorCode annotation = exception.getClass().getAnnotation(ErrorCode.class); return (annotation == null) ? camelToKebab(exception.getClass().getSimpleName().replaceAll("Exception$", "")) : annotation.value(); diff --git a/server/implementation/src/test/java/io/smallrye/graphql/execution/error/ExecutionErrorsServiceTest.java b/server/implementation/src/test/java/io/smallrye/graphql/execution/error/ExecutionErrorsServiceTest.java index 9aa7d40c5..83f3417e5 100644 --- a/server/implementation/src/test/java/io/smallrye/graphql/execution/error/ExecutionErrorsServiceTest.java +++ b/server/implementation/src/test/java/io/smallrye/graphql/execution/error/ExecutionErrorsServiceTest.java @@ -18,7 +18,7 @@ import graphql.language.SourceLocation; import graphql.validation.ValidationError; import graphql.validation.ValidationErrorType; -import io.smallrye.graphql.api.GraphQlErrorCode; +import io.smallrye.graphql.api.ErrorCode; /** * Test for {@link ExecutionErrorsService} @@ -91,7 +91,7 @@ public DummyBusinessException(String message) { @Test void shouldMapClassAnnotationErrorCode() { - @GraphQlErrorCode("dummy-code") + @ErrorCode("dummy-code") class DummyBusinessException extends RuntimeException { public DummyBusinessException(String message) { super(message); diff --git a/server/tck/src/test/java/io/smallrye/graphql/test/apps/error/api/ErrorApi.java b/server/tck/src/test/java/io/smallrye/graphql/test/apps/error/api/ErrorApi.java index 52f6042a6..c82d4b3c7 100644 --- a/server/tck/src/test/java/io/smallrye/graphql/test/apps/error/api/ErrorApi.java +++ b/server/tck/src/test/java/io/smallrye/graphql/test/apps/error/api/ErrorApi.java @@ -3,7 +3,7 @@ import org.eclipse.microprofile.graphql.GraphQLApi; import org.eclipse.microprofile.graphql.Query; -import io.smallrye.graphql.api.GraphQlErrorCode; +import io.smallrye.graphql.api.ErrorCode; @GraphQLApi public class ErrorApi { @@ -20,7 +20,7 @@ public String customBusinessException() { throw new CustomBusinessException(); } - @GraphQlErrorCode("some-business-error-code") + @ErrorCode("some-business-error-code") public static class AnnotatedCustomBusinessException extends RuntimeException { }