From 3dd2a9f554780699228f06a36a47427c08e97af0 Mon Sep 17 00:00:00 2001 From: BenEmdon Date: Wed, 6 Sep 2017 15:03:30 -0400 Subject: [PATCH 1/5] Add 'clear{property name}' void function on input types for all nullable properties --- .../graphql_java_gen/templates/APISchema.java.erb | 5 +++++ .../com/shopify/graphql/support/Generated.java | 15 +++++++++++++++ .../shopify/graphql/support/IntegrationTest.java | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb index 5357f70..bc20865 100644 --- a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb +++ b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb @@ -298,6 +298,11 @@ public class <%= schema_name %> { this.<%= field.camelize_name %>Seen = true; return this; } + + public void clear<%= field.classify_name %>() { + this.<%= escape_reserved_word(field.camelize_name) %> = null; + this.<%= field.camelize_name %>Seen = false; + } <% end %> public void appendTo(StringBuilder _queryBuilder) { diff --git a/support/src/test/java/com/shopify/graphql/support/Generated.java b/support/src/test/java/com/shopify/graphql/support/Generated.java index 3ae9cf7..26b96fc 100644 --- a/support/src/test/java/com/shopify/graphql/support/Generated.java +++ b/support/src/test/java/com/shopify/graphql/support/Generated.java @@ -1120,6 +1120,11 @@ public SetIntegerInput setTtl(@Nullable LocalDateTime ttl) { return this; } + public void clearTtl() { + this.ttl = null; + this.ttlSeen = false; + } + @Nullable public Boolean getNegate() { return negate; @@ -1131,6 +1136,11 @@ public SetIntegerInput setNegate(@Nullable Boolean negate) { return this; } + public void clearNegate() { + this.negate = null; + this.negateSeen = false; + } + @Nullable public String getApiClient() { return apiClient; @@ -1142,6 +1152,11 @@ public SetIntegerInput setApiClient(@Nullable String apiClient) { return this; } + public void clearApiClient() { + this.apiClient = null; + this.apiClientSeen = false; + } + public void appendTo(StringBuilder _queryBuilder) { String separator = ""; _queryBuilder.append('{'); diff --git a/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java b/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java index 0ea10d7..6711902 100644 --- a/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java +++ b/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java @@ -164,4 +164,12 @@ public void testOptionalFieldOnInput() throws Exception { ).toString(); assertEquals("mutation{set_integer(input:{key:\"answer\",value:42,ttl:null})}", queryString); } + + @Test + public void testClearOptionalFieldOnInput() throws Exception { + String queryString = Generated.mutation(mutation -> mutation + .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(null).clearTtl()) + ).toString(); + assertEquals("mutation{set_integer(input:{key:\"answer\",value:42})}", queryString); + } } From a2b4b306b7b6afa9c540d8fd5c86fd6c67d8fd81 Mon Sep 17 00:00:00 2001 From: BenEmdon Date: Wed, 6 Sep 2017 15:25:08 -0400 Subject: [PATCH 2/5] Chnaged 'clear' => 'unSet' and added a testUnSetRequiredlFieldOnInput --- .../graphql_java_gen/templates/APISchema.java.erb | 6 +++++- .../com/shopify/graphql/support/Generated.java | 14 +++++++++++--- .../shopify/graphql/support/IntegrationTest.java | 12 ++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb index bc20865..b00485f 100644 --- a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb +++ b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb @@ -286,6 +286,10 @@ public class <%= schema_name %> { this.<%= escape_reserved_word(field.camelize_name) %> = <%= escape_reserved_word(field.camelize_name) %>; return this; } + + public void unSet<%= field.classify_name %>() { + this.<%= escape_reserved_word(field.camelize_name) %> = null; + } <% end %> <% type.optional_input_fields.each do |field| %> <%= java_annotations(field) %> @@ -299,7 +303,7 @@ public class <%= schema_name %> { return this; } - public void clear<%= field.classify_name %>() { + public void unSet<%= field.classify_name %>() { this.<%= escape_reserved_word(field.camelize_name) %> = null; this.<%= field.camelize_name %>Seen = false; } diff --git a/support/src/test/java/com/shopify/graphql/support/Generated.java b/support/src/test/java/com/shopify/graphql/support/Generated.java index 26b96fc..f79f1ea 100644 --- a/support/src/test/java/com/shopify/graphql/support/Generated.java +++ b/support/src/test/java/com/shopify/graphql/support/Generated.java @@ -1100,6 +1100,10 @@ public SetIntegerInput setKey(String key) { return this; } + public void unSetKey() { + this.key = null; + } + public int getValue() { return value; } @@ -1109,6 +1113,10 @@ public SetIntegerInput setValue(int value) { return this; } + public void unSetValue() { + this.value = null; + } + @Nullable public LocalDateTime getTtl() { return ttl; @@ -1120,7 +1128,7 @@ public SetIntegerInput setTtl(@Nullable LocalDateTime ttl) { return this; } - public void clearTtl() { + public void unSetTtl() { this.ttl = null; this.ttlSeen = false; } @@ -1136,7 +1144,7 @@ public SetIntegerInput setNegate(@Nullable Boolean negate) { return this; } - public void clearNegate() { + public void unSetNegate() { this.negate = null; this.negateSeen = false; } @@ -1152,7 +1160,7 @@ public SetIntegerInput setApiClient(@Nullable String apiClient) { return this; } - public void clearApiClient() { + public void unSetApiClient() { this.apiClient = null; this.apiClientSeen = false; } diff --git a/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java b/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java index 6711902..94bb626 100644 --- a/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java +++ b/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java @@ -166,9 +166,17 @@ public void testOptionalFieldOnInput() throws Exception { } @Test - public void testClearOptionalFieldOnInput() throws Exception { + public void testUnSetRequiredlFieldOnInput() throws Exception { String queryString = Generated.mutation(mutation -> mutation - .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(null).clearTtl()) + .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(null).unSetValue()) + ).toString(); + assertEquals("mutation{set_integer(input:{key:\"answer\",ttl:null})}", queryString); + } + + @Test + public void testUnSetOptionalFieldOnInput() throws Exception { + String queryString = Generated.mutation(mutation -> mutation + .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(null).unSetTtl()) ).toString(); assertEquals("mutation{set_integer(input:{key:\"answer\",value:42})}", queryString); } From f02f8e0ad63629bd9d4cc6c59380072b5ca2c462 Mon Sep 17 00:00:00 2001 From: BenEmdon Date: Wed, 6 Sep 2017 15:34:45 -0400 Subject: [PATCH 3/5] Added comments to codegen and made 'unSet' => 'unset' --- .../graphql_java_gen/templates/APISchema.java.erb | 8 ++++++-- .../com/shopify/graphql/support/Generated.java | 15 ++++++++++----- .../shopify/graphql/support/IntegrationTest.java | 8 ++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb index b00485f..bff1c8e 100644 --- a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb +++ b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb @@ -287,9 +287,11 @@ public class <%= schema_name %> { return this; } - public void unSet<%= field.classify_name %>() { + // Unsets the <%= escape_reserved_word(field.camelize_name) %> property so that it is not serialized + public void unset<%= field.classify_name %>() { this.<%= escape_reserved_word(field.camelize_name) %> = null; } + <% end %> <% type.optional_input_fields.each do |field| %> <%= java_annotations(field) %> @@ -303,10 +305,12 @@ public class <%= schema_name %> { return this; } - public void unSet<%= field.classify_name %>() { + // Unsets the <%= escape_reserved_word(field.camelize_name) %> property so that it is not serialized + public void unset<%= field.classify_name %>() { this.<%= escape_reserved_word(field.camelize_name) %> = null; this.<%= field.camelize_name %>Seen = false; } + <% end %> public void appendTo(StringBuilder _queryBuilder) { diff --git a/support/src/test/java/com/shopify/graphql/support/Generated.java b/support/src/test/java/com/shopify/graphql/support/Generated.java index f79f1ea..deb1d23 100644 --- a/support/src/test/java/com/shopify/graphql/support/Generated.java +++ b/support/src/test/java/com/shopify/graphql/support/Generated.java @@ -1100,7 +1100,8 @@ public SetIntegerInput setKey(String key) { return this; } - public void unSetKey() { + // Unsets the key property so that it is not serialized + public void unsetKey() { this.key = null; } @@ -1113,7 +1114,8 @@ public SetIntegerInput setValue(int value) { return this; } - public void unSetValue() { + // Unsets the value property so that it is not serialized + public void unsetValue() { this.value = null; } @@ -1128,7 +1130,8 @@ public SetIntegerInput setTtl(@Nullable LocalDateTime ttl) { return this; } - public void unSetTtl() { + // Unsets the ttl property so that it is not serialized + public void unsetTtl() { this.ttl = null; this.ttlSeen = false; } @@ -1144,7 +1147,8 @@ public SetIntegerInput setNegate(@Nullable Boolean negate) { return this; } - public void unSetNegate() { + // Unsets the negate property so that it is not serialized + public void unsetNegate() { this.negate = null; this.negateSeen = false; } @@ -1160,7 +1164,8 @@ public SetIntegerInput setApiClient(@Nullable String apiClient) { return this; } - public void unSetApiClient() { + // Unsets the apiClient property so that it is not serialized + public void unsetApiClient() { this.apiClient = null; this.apiClientSeen = false; } diff --git a/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java b/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java index 94bb626..e215a42 100644 --- a/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java +++ b/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java @@ -166,17 +166,17 @@ public void testOptionalFieldOnInput() throws Exception { } @Test - public void testUnSetRequiredlFieldOnInput() throws Exception { + public void testUnsetRequiredlFieldOnInput() throws Exception { String queryString = Generated.mutation(mutation -> mutation - .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(null).unSetValue()) + .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(null).unsetValue()) ).toString(); assertEquals("mutation{set_integer(input:{key:\"answer\",ttl:null})}", queryString); } @Test - public void testUnSetOptionalFieldOnInput() throws Exception { + public void testUnsetOptionalFieldOnInput() throws Exception { String queryString = Generated.mutation(mutation -> mutation - .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(null).unSetTtl()) + .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(null).unsetTtl()) ).toString(); assertEquals("mutation{set_integer(input:{key:\"answer\",value:42})}", queryString); } From fe937296934b338d28063c0e2bc1090cbf8fca82 Mon Sep 17 00:00:00 2001 From: BenEmdon Date: Wed, 6 Sep 2017 16:02:00 -0400 Subject: [PATCH 4/5] Removed unset for required fields --- .../lib/graphql_java_gen/templates/APISchema.java.erb | 5 ----- .../java/com/shopify/graphql/support/Generated.java | 10 ---------- .../com/shopify/graphql/support/IntegrationTest.java | 8 -------- 3 files changed, 23 deletions(-) diff --git a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb index bff1c8e..a14517a 100644 --- a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb +++ b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb @@ -287,11 +287,6 @@ public class <%= schema_name %> { return this; } - // Unsets the <%= escape_reserved_word(field.camelize_name) %> property so that it is not serialized - public void unset<%= field.classify_name %>() { - this.<%= escape_reserved_word(field.camelize_name) %> = null; - } - <% end %> <% type.optional_input_fields.each do |field| %> <%= java_annotations(field) %> diff --git a/support/src/test/java/com/shopify/graphql/support/Generated.java b/support/src/test/java/com/shopify/graphql/support/Generated.java index deb1d23..4723d04 100644 --- a/support/src/test/java/com/shopify/graphql/support/Generated.java +++ b/support/src/test/java/com/shopify/graphql/support/Generated.java @@ -1100,11 +1100,6 @@ public SetIntegerInput setKey(String key) { return this; } - // Unsets the key property so that it is not serialized - public void unsetKey() { - this.key = null; - } - public int getValue() { return value; } @@ -1114,11 +1109,6 @@ public SetIntegerInput setValue(int value) { return this; } - // Unsets the value property so that it is not serialized - public void unsetValue() { - this.value = null; - } - @Nullable public LocalDateTime getTtl() { return ttl; diff --git a/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java b/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java index e215a42..460b52f 100644 --- a/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java +++ b/support/src/test/java/com/shopify/graphql/support/IntegrationTest.java @@ -165,14 +165,6 @@ public void testOptionalFieldOnInput() throws Exception { assertEquals("mutation{set_integer(input:{key:\"answer\",value:42,ttl:null})}", queryString); } - @Test - public void testUnsetRequiredlFieldOnInput() throws Exception { - String queryString = Generated.mutation(mutation -> mutation - .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(null).unsetValue()) - ).toString(); - assertEquals("mutation{set_integer(input:{key:\"answer\",ttl:null})}", queryString); - } - @Test public void testUnsetOptionalFieldOnInput() throws Exception { String queryString = Generated.mutation(mutation -> mutation From 016fb3202e675929cba46363f4ef5043b72bc3ee Mon Sep 17 00:00:00 2001 From: BenEmdon Date: Wed, 6 Sep 2017 20:06:50 -0400 Subject: [PATCH 5/5] Made unsetter return 'this' to match setter expected behavior --- .../graphql_java_gen/templates/APISchema.java.erb | 5 +++-- .../com/shopify/graphql/support/Generated.java | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb index a14517a..4258c6b 100644 --- a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb +++ b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb @@ -300,10 +300,11 @@ public class <%= schema_name %> { return this; } - // Unsets the <%= escape_reserved_word(field.camelize_name) %> property so that it is not serialized - public void unset<%= field.classify_name %>() { + // Unsets the <%= escape_reserved_word(field.camelize_name) %> property so that it is not serialized. + public <%= type.name %> unset<%= field.classify_name %>() { this.<%= escape_reserved_word(field.camelize_name) %> = null; this.<%= field.camelize_name %>Seen = false; + return this; } <% end %> diff --git a/support/src/test/java/com/shopify/graphql/support/Generated.java b/support/src/test/java/com/shopify/graphql/support/Generated.java index 4723d04..6ce5bf0 100644 --- a/support/src/test/java/com/shopify/graphql/support/Generated.java +++ b/support/src/test/java/com/shopify/graphql/support/Generated.java @@ -1120,10 +1120,11 @@ public SetIntegerInput setTtl(@Nullable LocalDateTime ttl) { return this; } - // Unsets the ttl property so that it is not serialized - public void unsetTtl() { + // Unsets the ttl property so that it is not serialized. + public SetIntegerInput unsetTtl() { this.ttl = null; this.ttlSeen = false; + return this; } @Nullable @@ -1137,10 +1138,11 @@ public SetIntegerInput setNegate(@Nullable Boolean negate) { return this; } - // Unsets the negate property so that it is not serialized - public void unsetNegate() { + // Unsets the negate property so that it is not serialized. + public SetIntegerInput unsetNegate() { this.negate = null; this.negateSeen = false; + return this; } @Nullable @@ -1154,10 +1156,11 @@ public SetIntegerInput setApiClient(@Nullable String apiClient) { return this; } - // Unsets the apiClient property so that it is not serialized - public void unsetApiClient() { + // Unsets the apiClient property so that it is not serialized. + public SetIntegerInput unsetApiClient() { this.apiClient = null; this.apiClientSeen = false; + return this; } public void appendTo(StringBuilder _queryBuilder) {