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 src/main/java/graphql/execution/ExecutionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ protected CompletableFuture<ExecutionResult> completeValue(ExecutionContext exec
*
* @return an un-boxed result
*/
private Object unboxPossibleOptional(Object result) {
protected Object unboxPossibleOptional(Object result) {
if (result instanceof Optional) {
Optional optional = (Optional) result;
if (optional.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ private List<ExecutionNode> handleList(ExecutionContext executionContext, Map<St

MapOrList listResult = mapOrList.createAndPutList(fieldName);
for (Object rawValue : (List<Object>) value.getValue()) {
rawValue = unboxPossibleOptional(rawValue);
flattenedValues.add(new FetchedValue(listResult, rawValue));
}
}
Expand Down Expand Up @@ -408,7 +409,8 @@ private BiFunction<List<Object>, Throwable, List<FetchedValue>> handleResult(Exe
List<Object> values = result;
List<FetchedValue> retVal = new ArrayList<>();
for (int i = 0; i < parentResults.size(); i++) {
retVal.add(new FetchedValue(parentResults.get(i), values.get(i)));
Object value = unboxPossibleOptional(values.get(i));
retVal.add(new FetchedValue(parentResults.get(i), value));
}
return retVal;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,16 @@ class BatchedExecutionStrategyTest extends Specification {
runTestBatching(query, expected)
runTestBatchingExpectErrors(query, new BatchAssertionFailed(), false)
}

def "#673 optional support"() {
given:
String query = "{ string(value: \"673-optional-support\"){emptyOptional, optional} }"

def expected = [string: [emptyOptional:null, optional:"673-optional-support"]]
println expected

expect:
runTest(query, expected)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

public class FunWithStringsSchemaFactory {
Expand Down Expand Up @@ -203,6 +204,10 @@ public Object get(DataFetchingEnvironment environment) {

public DataFetcher appendFetcher = e -> ((String)e.getSource()) + e.getArgument("text");

public DataFetcher emptyOptionalFetcher = e -> Optional.empty();

public DataFetcher optionalFetcher = e -> Optional.of("673-optional-support");

public void setWordsAndLettersFetcher(DataFetcher fetcher) {
this.wordsAndLettersFetcher = fetcher;
}
Expand Down Expand Up @@ -292,6 +297,22 @@ GraphQLSchema createSchema() {
.type(Scalars.GraphQLString))
.dataFetcher(appendFetcher))

.field(GraphQLFieldDefinition.newFieldDefinition()
.name("emptyOptional")
.type(Scalars.GraphQLString)
.argument(GraphQLArgument.newArgument()
.name("text")
.type(Scalars.GraphQLString))
.dataFetcher(emptyOptionalFetcher))

.field(GraphQLFieldDefinition.newFieldDefinition()
.name("optional")
.type(Scalars.GraphQLString)
.argument(GraphQLArgument.newArgument()
.name("text")
.type(Scalars.GraphQLString))
.dataFetcher(optionalFetcher))

.build();


Expand Down