diff --git a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb index 5357f70..4258c6b 100644 --- a/codegen/lib/graphql_java_gen/templates/APISchema.java.erb +++ b/codegen/lib/graphql_java_gen/templates/APISchema.java.erb @@ -286,6 +286,7 @@ public class <%= schema_name %> { this.<%= escape_reserved_word(field.camelize_name) %> = <%= escape_reserved_word(field.camelize_name) %>; return this; } + <% end %> <% type.optional_input_fields.each do |field| %> <%= java_annotations(field) %> @@ -298,6 +299,14 @@ public class <%= schema_name %> { this.<%= field.camelize_name %>Seen = true; return this; } + + // 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 %> 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..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,6 +1120,13 @@ public SetIntegerInput setTtl(@Nullable LocalDateTime ttl) { return this; } + // Unsets the ttl property so that it is not serialized. + public SetIntegerInput unsetTtl() { + this.ttl = null; + this.ttlSeen = false; + return this; + } + @Nullable public Boolean getNegate() { return negate; @@ -1131,6 +1138,13 @@ public SetIntegerInput setNegate(@Nullable Boolean negate) { return this; } + // Unsets the negate property so that it is not serialized. + public SetIntegerInput unsetNegate() { + this.negate = null; + this.negateSeen = false; + return this; + } + @Nullable public String getApiClient() { return apiClient; @@ -1142,6 +1156,13 @@ public SetIntegerInput setApiClient(@Nullable String apiClient) { return this; } + // 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) { 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..460b52f 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 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); + } }