FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add generic DataFetcherResult.newBuilder(T data) method by jord1e · Pull Request #4254 · graphql-java/graphql-java · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .groovy  (1) .java  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 13 additions & 0 deletions src/main/java/graphql/execution/DataFetcherResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ public static <T> Builder<T> newResult() {
return new Builder<>();
}

/**
* Creates a new data fetcher result builder with associated data.
* <p>Data may later be overwritten using {@link Builder#data(Object)}.
*
* @param data the data
* @param <T> the type of the result
*
* @return a new builder
*/
public static <T> Builder<@Nullable T> newResult(@Nullable T data) {
return new Builder<>(data);
}

public static class Builder<T extends @Nullable Object> {
private @Nullable T data;
private @Nullable Object localContext;
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ class DataFetcherResultTest extends Specification {
result.getErrors() == [error1, error2]
}

def "building with generics"() {
when:
DataFetcherResult<String> result = DataFetcherResult.newResult("hello")
.error(error1).errors([error2]).localContext("world").build()
then:
result.getData() == "hello"
result.getLocalContext() == "world"
result.getErrors() == [error1, error2]
}

def "building with generics data can be overwritten in builder"() {
when:
DataFetcherResult<String> result = DataFetcherResult.newResult("someText")
.data("hello")
.error(error1).errors([error2]).localContext("world").build()
then:
result.getData() == "hello"
result.getLocalContext() == "world"
result.getErrors() == [error1, error2]
}

def "hasErrors can be called"() {
when:
def builder = DataFetcherResult.newResult()
Expand Down
Loading

Back | FazBrowse Home | New Git URL