Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit 21b355c

Browse files
committed
support json_name proto annotation for renaming field names in GraphQL schema.
also bumping version to release 0.2.1.
1 parent 5bc479d commit 21b355c

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

rejoiner/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<groupId>com.google.api.graphql</groupId>
4242
<artifactId>rejoiner</artifactId>
4343
<name>Rejoiner</name>
44-
<version>0.2.0</version>
44+
<version>0.2.1</version>
4545
<description>Generating GraphQL schemas from Protobufs.</description>
4646
<url>https://github.com/google/rejoiner</url>
4747
<packaging>jar</packaging>

rejoiner/src/main/java/com/google/api/graphql/rejoiner/ProtoToGql.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ private static Object call(Object object, String methodName) {
137137
return method.invoke(object);
138138
} catch (NoSuchMethodException e) {
139139
return null;
140-
} catch (IllegalAccessException e) {
141-
throw new RuntimeException(e);
142-
} catch (InvocationTargetException e) {
140+
} catch (IllegalAccessException | InvocationTargetException e) {
143141
throw new RuntimeException(e);
144142
}
145143
}
@@ -154,7 +152,7 @@ public GraphQLFieldDefinition apply(FieldDescriptor fieldDescriptor) {
154152
.type(convertType(fieldDescriptor))
155153
.dataFetcher(
156154
new ProtoDataFetcher(convertedFieldName))
157-
.name(convertedFieldName);
155+
.name(fieldDescriptor.getJsonName());
158156
builder.description(DescriptorSet.COMMENTS.get(fieldDescriptor.getFullName()));
159157
if (fieldDescriptor.getOptions().hasDeprecated()
160158
&& fieldDescriptor.getOptions().getDeprecated()) {

rejoiner/src/test/java/com/google/api/graphql/rejoiner/ProtoToGqlTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void convertShouldWorkForMessage() {
5757
GraphQLObjectType result = ProtoToGql.convert(Proto1.getDescriptor(), null);
5858
assertThat(result.getName())
5959
.isEqualTo("javatests_com_google_api_graphql_rejoiner_proto_Proto1");
60-
assertThat(result.getFieldDefinitions()).hasSize(5);
60+
assertThat(result.getFieldDefinitions()).hasSize(6);
6161
}
6262

6363
@Test
@@ -74,9 +74,10 @@ public void convertShouldWorkForEnums() {
7474
@Test
7575
public void checkFieldNameCamelCase() {
7676
GraphQLObjectType result = ProtoToGql.convert(Proto1.getDescriptor(), null);
77-
assertThat(result.getFieldDefinitions()).hasSize(5);
77+
assertThat(result.getFieldDefinitions()).hasSize(6);
7878
assertThat(result.getFieldDefinition("intField")).isNotNull();
7979
assertThat(result.getFieldDefinition("camelCaseName")).isNotNull();
80+
assertThat(result.getFieldDefinition("RenamedField")).isNotNull();
8081
}
8182

8283
@Test

0 commit comments

Comments
 (0)