8000 transformable IncrementalExecutionResult by jbellenger · Pull Request #3693 · graphql-java/graphql-java · GitHub
[go: up one dir, main page]

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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;

@ExperimentalApi
Expand Down Expand Up @@ -52,6 +53,13 @@ public static Builder fromExecutionResult(ExecutionResult executionResult) {
return new Builder().from(executionResult);
}

@Override
public IncrementalExecutionResult transform(Consumer<ExecutionResult.Builder<?>> builderConsumer) {
Copy link
Contributor Author
@jbellenger jbellenger Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if this Consumer was actually for type IncrementalExecutionResult.Builder, but changing it would either break the override or require adding more generics to ExecutionResult.

As written, the builder given to the consumer is castable to IncrementalExecutionResult.Builder, which is better than nothing. I'm open to feedback/ideas on how to get better typing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.
That's a tricky problem though, and I can't think of a nice solution right now.
I'm happy to merge the PR as is if it unblocks you.

var builder = fromExecutionResult(this);
builderConsumer.accept(builder);
return builder.build();
}

@Override
public Map<String, Object> toSpecification() {
Map<String, Object> map = new LinkedHashMap<>(super.toSpecification());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package graphql.incremental

import graphql.execution.ResultPath
import groovy.json.JsonOutput
import io.reactivex.Flowable
import org.reactivestreams.Publisher
import spock.lang.Specification

import static graphql.incremental.DeferPayload.newDeferredItem
Expand Down Expand Up @@ -120,4 +118,18 @@ class IncrementalExecutionResultTest extends Specification {
newIncrementalExecutionResult.hasNext() == incrementalExecutionResult.hasNext()
newIncrementalExecutionResult.toSpecification() == incrementalExecutionResult.toSpecification()
}

def "transform returns IncrementalExecutionResult"() {
when:
def initial = newIncrementalExecutionResult().hasNext(true).build()

then:
def transformed = initial.transform { b ->
b.addExtension("ext-key", "ext-value")
b.hasNext(false)
}
transformed instanceof IncrementalExecutionResult
transformed.extensions == ["ext-key": "ext-value"]
transformed.hasNext == false
}
}
0