Skip to content

Add a way to unset an input property #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions codegen/lib/graphql_java_gen/templates/APISchema.java.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>
Expand All @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions support/src/test/java/com/shopify/graphql/support/Generated.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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('{');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}