Skip to content

Commit 76f681d

Browse files
committed
Fix builder return type and expose generic toSpecification
1 parent 985e9c8 commit 76f681d

File tree

3 files changed

+168
-13
lines changed

3 files changed

+168
-13
lines changed

‎src/main/java/graphql/incremental/IncrementalPayload.java‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
packagegraphql.incremental;
22

3-
importgraphql.ExecutionResult;
43
importgraphql.ExperimentalApi;
54
importgraphql.GraphQLError;
65
importgraphql.execution.ResultPath;
@@ -61,7 +60,7 @@ public Map<Object, Object> getExtensions(){
6160
returnthis.extensions;
6261
}
6362

64-
protectedMap<String, Object> toSpecification(){
63+
publicMap<String, Object> toSpecification(){
6564
Map<String, Object> result = newLinkedHashMap<>();
6665

6766
result.put("path", path);
@@ -122,25 +121,25 @@ public T errors(List<GraphQLError> errors){
122121
return (T) this;
123122
}
124123

125-
publicBuilder<T>addErrors(List<GraphQLError> errors){
124+
publicTaddErrors(List<GraphQLError> errors){
126125
this.errors.addAll(errors);
127-
returnthis;
126+
return(T) this;
128127
}
129128

130-
publicBuilder<T>addError(GraphQLErrorerror){
129+
publicTaddError(GraphQLErrorerror){
131130
this.errors.add(error);
132-
returnthis;
131+
return(T) this;
133132
}
134133

135-
publicBuilder<T>extensions(Map<Object, Object> extensions){
134+
publicTextensions(Map<Object, Object> extensions){
136135
this.extensions = extensions;
137-
returnthis;
136+
return(T) this;
138137
}
139138

140-
publicBuilder<T>addExtension(Stringkey, Objectvalue){
139+
publicTaddExtension(Stringkey, Objectvalue){
141140
this.extensions = (this.extensions == null ? newLinkedHashMap<>() : this.extensions);
142141
this.extensions.put(key, value);
143-
returnthis;
142+
return(T) this;
144143
}
145144
}
146145
}

‎src/test/groovy/graphql/incremental/DeferPayloadTest.groovy‎

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
packagegraphql.incremental
22

3-
3+
importgraphql.GraphqlErrorBuilder
4+
importgraphql.execution.ResultPath
45
importspock.lang.Specification
56

67
classDeferPayloadTestextendsSpecification{
@@ -14,8 +15,85 @@ class DeferPayloadTest extends Specification{
1415

1516
then:
1617
spec == [
17-
data : null,
18-
path : null,
18+
data: null,
19+
path: null,
20+
]
21+
}
22+
23+
def"can construct an instance using builder"(){
24+
def payload =DeferPayload.newDeferredItem()
25+
.data("twow is that a bee")
26+
.path(["hello"])
27+
.errors([])
28+
.addError(GraphqlErrorBuilder.newError()
29+
.message("wow")
30+
.build())
31+
.addErrors([
32+
GraphqlErrorBuilder.newError()
33+
.message("yep")
34+
.build(),
35+
])
36+
.extensions([echo: "Hello world"])
37+
.build()
38+
39+
when:
40+
def serialized = payload.toSpecification()
41+
42+
then:
43+
serialized == [
44+
data : "twow is that a bee",
45+
path : ["hello"],
46+
errors : [
47+
[
48+
message : "wow",
49+
locations : [],
50+
extensions: [classification: "DataFetchingException"],
51+
],
52+
[
53+
message : "yep",
54+
locations : [],
55+
extensions: [classification: "DataFetchingException"],
56+
],
57+
],
58+
extensions: [
59+
echo: "Hello world",
60+
],
61+
]
62+
}
63+
64+
def"errors replaces existing errors"(){
65+
def payload =DeferPayload.newDeferredItem()
66+
.data("twow is that a bee")
67+
.path(ResultPath.fromList(["test", "echo"]))
68+
.addError(GraphqlErrorBuilder.newError()
69+
.message("wow")
70+
.build())
71+
.addErrors([])
72+
.errors([
73+
GraphqlErrorBuilder.newError()
74+
.message("yep")
75+
.build(),
76+
])
77+
.extensions([echo: "Hello world"])
78+
.build()
79+
80+
when:
81+
def serialized = payload.toSpecification()
82+
83+
then:
84+
serialized == [
85+
data : "twow is that a bee",
86+
errors : [
87+
[
88+
message : "yep",
89+
locations : [],
90+
extensions: [classification: "DataFetchingException"],
91+
],
92+
],
93+
extensions: [
94+
echo: "Hello world",
95+
],
96+
path : ["test", "echo"],
1997
]
2098
}
2199
}

‎src/test/groovy/graphql/incremental/StreamPayloadTest.groovy‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
packagegraphql.incremental
22

3+
importgraphql.GraphqlErrorBuilder
4+
importgraphql.execution.ResultPath
35
importspock.lang.Specification
46

57
classStreamPayloadTestextendsSpecification{
@@ -15,6 +17,82 @@ class StreamPayloadTest extends Specification{
1517
spec == [
1618
items: null,
1719
path : null,
20+
]
21+
}
22+
def"can construct an instance using builder"(){
23+
def payload =StreamPayload.newStreamedItem()
24+
.items(["twow is that a bee"])
25+
.path(["hello"])
26+
.errors([])
27+
.addError(GraphqlErrorBuilder.newError()
28+
.message("wow")
29+
.build())
30+
.addErrors([
31+
GraphqlErrorBuilder.newError()
32+
.message("yep")
33+
.build(),
34+
])
35+
.extensions([echo: "Hello world"])
36+
.build()
37+
38+
when:
39+
def serialized = payload.toSpecification()
40+
41+
then:
42+
serialized == [
43+
items : ["twow is that a bee"],
44+
path : ["hello"],
45+
errors : [
46+
[
47+
message : "wow",
48+
locations : [],
49+
extensions: [classification: "DataFetchingException"],
50+
],
51+
[
52+
message : "yep",
53+
locations : [],
54+
extensions: [classification: "DataFetchingException"],
55+
],
56+
],
57+
extensions: [
58+
echo: "Hello world",
59+
],
60+
]
61+
}
62+
63+
def"errors replaces existing errors"(){
64+
def payload =StreamPayload.newStreamedItem()
65+
.items(["twow is that a bee"])
66+
.path(ResultPath.fromList(["test", "echo"]))
67+
.addError(GraphqlErrorBuilder.newError()
68+
.message("wow")
69+
.build())
70+
.addErrors([])
71+
.errors([
72+
GraphqlErrorBuilder.newError()
73+
.message("yep")
74+
.build(),
75+
])
76+
.extensions([echo: "Hello world"])
77+
.build()
78+
79+
when:
80+
def serialized = payload.toSpecification()
81+
82+
then:
83+
serialized == [
84+
items : ["twow is that a bee"],
85+
errors : [
86+
[
87+
message : "yep",
88+
locations : [],
89+
extensions: [classification: "DataFetchingException"],
90+
],
91+
],
92+
extensions: [
93+
echo: "Hello world",
94+
],
95+
path : ["test", "echo"],
1896
]
1997
}
2098
}

0 commit comments

Comments
(0)