8000 Fix builder return type and expose generic toSpecification by gnawf · Pull Request #3642 · 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
8000
19 changes: 9 additions & 10 deletions src/main/java/graphql/incremental/IncrementalPayload.java
Original file line number D 10BC0 iff line number Diff line change
@@ -1,6 +1,5 @@
package graphql.incremental;

import graphql.ExecutionResult;
import graphql.ExperimentalApi;
import graphql.GraphQLError;
import graphql.execution.ResultPath;
Expand Down Expand Up @@ -61,7 +60,7 @@ public Map<Object, Object> getExtensions() {
return this.extensions;
}

protected Map<String, Object> toSpecification() {
public Map<String, Object> toSpecification() {
Map<String, Object> result = new LinkedHashMap<>();

result.put("path", path);
Expand Down Expand Up @@ -122,25 +121,25 @@ public T errors(List<GraphQLError> errors) {
return (T) this;
}

public Builder<T> addErrors(List<GraphQLError> errors) {
public T addErrors(List<GraphQLError> errors) {
this.errors.addAll(errors);
return this;
return (T) this;
}

public Builder<T> addError(GraphQLError error) {
public T addError(GraphQLError error) {
this.errors.add(error);
return this;
return (T) this;
}

public Builder<T> extensions(Map<Object, Object> extensions) {
public T extensions(Map<Object, Object> extensions) {
this.extensions = extensions;
return this;
return (T) this;
}

public Builder<T> addExtension(String key, Object value) {
public T addExtension(String key, Object value) {
this.extensions = (this.extensions == null ? new LinkedHashMap<>() : this.extensions);
this.extensions.put(key, value);
return this;
return (T) this;
}
}
}
84 changes: 81 additions & 3 deletions src/test/groovy/graphql/incremental/DeferPayloadTest.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graphql.incremental


import graphql.GraphqlErrorBuilder
import graphql.execution.ResultPath
import spock.lang.Specification

class DeferPayloadTest extends Specification {
Expand All @@ -14,8 +15,85 @@ class DeferPayloadTest extends Specification {

then:
spec == [
data : null,
path : null,
data: null,
path: null,
]
}

def "can construct an instance using builder"() {
def payload = DeferPayload.newDeferredItem()
.data("twow is that a bee")
.path(["hello"])
.errors([])
.addError(GraphqlErrorBuilder.newError()
.message("wow")
.build())
.addErrors([
GraphqlErrorBuilder.newError()
.message("yep")
.build(),
])
.extensions([echo: "Hello world"])
.build()

when:
def serialized = payload.toSpecification()

then:
serialized == [
data : "twow is that a bee",
path : ["hello"],
errors : [
[
message : "wow",
locations : [],
extensions: [classification: "DataFetchingException"],
],
[
message : "yep",
locations : [],
extensions: [classification: "DataFetchingException"],
],
],
extensions: [
echo: "Hello world",
],
]
}

def "errors replaces existing errors"() {
def payload = DeferPayload.newDeferredItem()
.data("twow is that a bee")
.path(ResultPath.fromList(["test", "echo"]))
.addError(GraphqlErrorBuilder.newError()
.message("wow")
.build())
.addErrors([])
.errors([
GraphqlErrorBuilder.newError()
.message("yep")
.build(),
])
.extensions([echo: "Hello world"])
.build()

when:
def serialized = payload.toSpecification()

then:
serialized == [
data : "twow is that a bee",
errors : [
[
message : "yep",
locations : [],
extensions: [classification: "DataFetchingException"],
],
],
extensions: [
echo: "Hello world",
],
path : ["test", "echo"],
]
}
}
79 changes: 79 additions & 0 deletions src/test/groovy/graphql/incremental/StreamPayloadTest.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package graphql.incremental

import graphql.GraphqlErrorBuilder
import graphql.execution.ResultPath
import spock.lang.Specification

class StreamPayloadTest extends Specification {
Expand All @@ -17,4 +19,81 @@ class StreamPayloadTest extends Specification {
path : null,
]
}

def "can construct an instance using builder"() {
def payload = StreamPayload.newStreamedItem()
.items(["twow is that a bee"])
.path(["hello"])
.errors([])
.addError(GraphqlErrorBuilder.newError()
.message("wow")
.build())
.addErrors([
GraphqlErrorBuilder.newError()
.message("yep")
.build(),
])
.extensions([echo: "Hello world"])
.build()

when:
def serialized = payload.toSpecification()

then:
serialized == [
items : ["twow is that a bee"],
path : ["hello"],
errors : [
[
message : "wow",
locations : [],
extensions: [classification: "DataFetchingException"],
],
[
message : "yep",
locations : [],
extensions: [classification: "DataFetchingException"],
],
],
extensions: [
echo: "Hello world",
],
]
}

def "errors replaces existing errors"() {
def payload = StreamPayload.newStreamedItem()
.items(["twow is that a bee"])
.path(ResultPath.fromList(["test", "echo"]))
.addError(GraphqlErrorBuilder.newError()
.message("wow")
.build())
.addErrors([])
.errors([
GraphqlErrorBuilder.newError()
.message("yep")
.build(),
])
.extensions([echo: "Hello world"])
.build()

when:
def serialized = payload.toSpecification()

then:
serialized == [
items : ["twow is that a bee"],
errors : [
[
message : "yep",
locations : [],
extensions: [classification: "DataFetchingException"],
],
],
extensions: [
echo: "Hello world",
],
path : ["test", "echo"],
]
}
}
0