这是indexloc提供的服务,不要输入任何密码
Skip to content
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
2 changes: 1 addition & 1 deletion codegen/lib/graphql_java_gen/templates/APISchema.java.erb
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public class <%= schema_name %> {
}

public <%= type.name %> set<%= field.classify_name %>(<%= java_annotations(field, in_argument: true) %><%= java_input_type(field.type) %> <%= escape_reserved_word(field.camelize_name) %>) {
this.<%= escape_reserved_word(field.camelize_name) %> = Input.value(<%= escape_reserved_word(field.camelize_name) %>);
this.<%= escape_reserved_word(field.camelize_name) %> = Input.optional(<%= escape_reserved_word(field.camelize_name) %>);
return this;
}

Expand Down
4 changes: 4 additions & 0 deletions support/src/main/java/com/shopify/graphql/support/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public static <T> Input<T> value(@Nullable T value) {
return new Input<>(value, true);
}

public static <T> Input<T> optional(@Nullable T value) {
return value != null ? value(value) : Input.<T>undefined();
}

public static <T> Input<T> undefined() {
return new Input<>(null, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ public Input<LocalDateTime> getTtlInput() {
}

public SetIntegerInput setTtl(@Nullable LocalDateTime ttl) {
this.ttl = Input.value(ttl);
this.ttl = Input.optional(ttl);
return this;
}

Expand All @@ -1139,7 +1139,7 @@ public Input<Boolean> getNegateInput() {
}

public SetIntegerInput setNegate(@Nullable Boolean negate) {
this.negate = Input.value(negate);
this.negate = Input.optional(negate);
return this;
}

Expand All @@ -1161,7 +1161,7 @@ public Input<String> getApiClientInput() {
}

public SetIntegerInput setApiClient(@Nullable String apiClient) {
this.apiClient = Input.value(apiClient);
this.apiClient = Input.optional(apiClient);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void testOptionalFieldOnInput() throws Exception {
String queryString = Generated.mutation(mutation -> mutation
.setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(null))
).toString();
assertEquals("mutation{set_integer(input:{key:\"answer\",value:42,ttl:null})}", queryString);
assertEquals("mutation{set_integer(input:{key:\"answer\",value:42})}", queryString);
}

@Test
Expand Down