From 21b355cd6b878865092d39ca662106226bacffe9 Mon Sep 17 00:00:00 2001 From: Nick Siderakis Date: Thu, 29 Nov 2018 17:50:33 -0500 Subject: [PATCH] support json_name proto annotation for renaming field names in GraphQL schema. also bumping version to release 0.2.1. --- rejoiner/pom.xml | 2 +- .../java/com/google/api/graphql/rejoiner/ProtoToGql.java | 6 ++---- .../com/google/api/graphql/rejoiner/ProtoToGqlTest.java | 5 +++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/rejoiner/pom.xml b/rejoiner/pom.xml index 0ff6c83..5d15b24 100644 --- a/rejoiner/pom.xml +++ b/rejoiner/pom.xml @@ -41,7 +41,7 @@ com.google.api.graphql rejoiner Rejoiner - 0.2.0 + 0.2.1 Generating GraphQL schemas from Protobufs. https://github.com/google/rejoiner jar diff --git a/rejoiner/src/main/java/com/google/api/graphql/rejoiner/ProtoToGql.java b/rejoiner/src/main/java/com/google/api/graphql/rejoiner/ProtoToGql.java index 3337483..5a43983 100644 --- a/rejoiner/src/main/java/com/google/api/graphql/rejoiner/ProtoToGql.java +++ b/rejoiner/src/main/java/com/google/api/graphql/rejoiner/ProtoToGql.java @@ -137,9 +137,7 @@ private static Object call(Object object, String methodName) { return method.invoke(object); } catch (NoSuchMethodException e) { return null; - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } @@ -154,7 +152,7 @@ public GraphQLFieldDefinition apply(FieldDescriptor fieldDescriptor) { .type(convertType(fieldDescriptor)) .dataFetcher( new ProtoDataFetcher(convertedFieldName)) - .name(convertedFieldName); + .name(fieldDescriptor.getJsonName()); builder.description(DescriptorSet.COMMENTS.get(fieldDescriptor.getFullName())); if (fieldDescriptor.getOptions().hasDeprecated() && fieldDescriptor.getOptions().getDeprecated()) { diff --git a/rejoiner/src/test/java/com/google/api/graphql/rejoiner/ProtoToGqlTest.java b/rejoiner/src/test/java/com/google/api/graphql/rejoiner/ProtoToGqlTest.java index 9e19ab9..b30d598 100644 --- a/rejoiner/src/test/java/com/google/api/graphql/rejoiner/ProtoToGqlTest.java +++ b/rejoiner/src/test/java/com/google/api/graphql/rejoiner/ProtoToGqlTest.java @@ -57,7 +57,7 @@ public void convertShouldWorkForMessage() { GraphQLObjectType result = ProtoToGql.convert(Proto1.getDescriptor(), null); assertThat(result.getName()) .isEqualTo("javatests_com_google_api_graphql_rejoiner_proto_Proto1"); - assertThat(result.getFieldDefinitions()).hasSize(5); + assertThat(result.getFieldDefinitions()).hasSize(6); } @Test @@ -74,9 +74,10 @@ public void convertShouldWorkForEnums() { @Test public void checkFieldNameCamelCase() { GraphQLObjectType result = ProtoToGql.convert(Proto1.getDescriptor(), null); - assertThat(result.getFieldDefinitions()).hasSize(5); + assertThat(result.getFieldDefinitions()).hasSize(6); assertThat(result.getFieldDefinition("intField")).isNotNull(); assertThat(result.getFieldDefinition("camelCaseName")).isNotNull(); + assertThat(result.getFieldDefinition("RenamedField")).isNotNull(); } @Test