Skip to content

Commit

Permalink
Merge pull request #3570 from gnawf/always-include-incremental-props
Browse files Browse the repository at this point in the history
Always include incremental props even if null
  • Loading branch information
dondonz committed May 14, 2024
2 parents c8f08df + dbcf871 commit 17783d6
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 35 deletions.
10 changes: 3 additions & 7 deletions src/main/java/graphql/incremental/DeferPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ private DeferPayload(Object data, List<Object> path, String label, List<GraphQLE
}

/**
* @return the resolved data
* @param <T> the type to cast the result to
* @return the resolved data
*/
@Nullable
public <T> T getData() {
//noinspection unchecked
// noinspection unchecked
return (T) this.data;
}

Expand All @@ -37,11 +37,7 @@ public <T> T getData() {
@Override
public Map<String, Object> toSpecification() {
Map<String, Object> map = new LinkedHashMap<>(super.toSpecification());

if (data != null) {
map.put("data", data);
}

map.put("data", data);
return map;
}

Expand Down
10 changes: 3 additions & 7 deletions src/main/java/graphql/incremental/StreamPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ private StreamPayload(List<Object> items, List<Object> path, String label, List<
}

/**
* @return the resolved list of items
* @param <T> the type to cast the result to
* @return the resolved list of items
*/
@Nullable
public <T> List<T> getItems() {
//noinspection unchecked
// noinspection unchecked
return (List<T>) this.items;
}

Expand All @@ -36,11 +36,7 @@ public <T> List<T> getItems() {
@Override
public Map<String, Object> toSpecification() {
Map<String, Object> map = new LinkedHashMap<>(super.toSpecification());

if (items != null) {
map.put("items", items);
}

map.put("items", items);
return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ class DeferExecutionSupportIntegrationTest extends Specification {
private static DataFetcher resolve(Object value, Integer sleepMs, boolean allowMultipleCalls) {
return new DataFetcher() {
boolean executed = false

@Override
Object get(DataFetchingEnvironment environment) throws Exception {
if(executed && !allowMultipleCalls) {
if (executed && !allowMultipleCalls) {
throw new IllegalStateException("This data fetcher can run only once")
}
executed = true
Expand Down Expand Up @@ -298,7 +299,7 @@ class DeferExecutionSupportIntegrationTest extends Specification {
})

def indexOfId3 = Iterables.indexOf(incrementalResults, {
it.incremental[0] == [path: ["post3"], label:"defer-id3", data: [id3: "3"]]
it.incremental[0] == [path: ["post3"], label: "defer-id3", data: [id3: "3"]]
})

// Assert that both post3 and id3 are present
Expand Down Expand Up @@ -349,7 +350,7 @@ class DeferExecutionSupportIntegrationTest extends Specification {
def incrementalResults = getIncrementalResults(initialResult)

then:
if(type == "Post") {
if (type == "Post") {
assert incrementalResults == [
[
hasNext : false,
Expand Down Expand Up @@ -481,8 +482,8 @@ class DeferExecutionSupportIntegrationTest extends Specification {
hasNext : false,
incremental: [
[
path : ["post"],
data : [summary: "A summary"]
path: ["post"],
data: [summary: "A summary"]
]
]
]
Expand Down Expand Up @@ -519,8 +520,8 @@ class DeferExecutionSupportIntegrationTest extends Specification {
hasNext : false,
incremental: [
[
path : ["post"],
data : [resolvesToNull: null]
path: ["post"],
data: [resolvesToNull: null]
]
]
]
Expand Down Expand Up @@ -560,8 +561,8 @@ class DeferExecutionSupportIntegrationTest extends Specification {
hasNext : false,
incremental: [
[
path : ["post"],
data : [summary: "A summary", text: "The full text"]
path: ["post"],
data: [summary: "A summary", text: "The full text"]
]
]
]
Expand Down Expand Up @@ -739,8 +740,8 @@ class DeferExecutionSupportIntegrationTest extends Specification {
incremental: [
[
label: "summary-defer",
path: ["post"],
data: [summary: "A summary"]
path : ["post"],
data : [summary: "A summary"]
]
]
],
Expand All @@ -749,8 +750,8 @@ class DeferExecutionSupportIntegrationTest extends Specification {
incremental: [
[
label: "text-defer",
path: ["post"],
data: [text: "The full text"]
path : ["post"],
data : [text: "The full text"]
]
]
]
Expand Down Expand Up @@ -1211,8 +1212,8 @@ class DeferExecutionSupportIntegrationTest extends Specification {
hasNext : false,
incremental: [
[
path : ["post"],
data : [text: "The full text"],
path: ["post"],
data: [text: "The full text"],
]
]
]
Expand Down Expand Up @@ -1270,8 +1271,8 @@ class DeferExecutionSupportIntegrationTest extends Specification {
hasNext : false,
incremental: [
[
path : ["post"],
data : [text: "The full text"],
path: ["post"],
data: [text: "The full text"],
]
]
]
Expand Down Expand Up @@ -1329,8 +1330,8 @@ class DeferExecutionSupportIntegrationTest extends Specification {
hasNext : false,
incremental: [
[
path : ["post"],
data : [text: "The full text"],
path: ["post"],
data: [text: "The full text"],
]
]
]
Expand Down Expand Up @@ -1371,6 +1372,7 @@ class DeferExecutionSupportIntegrationTest extends Specification {
hasNext : true,
incremental: [
[
data : null,
path : ["post"],
errors: [
[
Expand All @@ -1388,8 +1390,8 @@ class DeferExecutionSupportIntegrationTest extends Specification {
hasNext : false,
incremental: [
[
path : ["post"],
data : [text: "The full text"],
path: ["post"],
data: [text: "The full text"],
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class DeferredCallTest extends Specification {

then:
deferPayload.toSpecification() == [
data : null,
path : ["path"],
label : "my-label",
errors: [
Expand Down
21 changes: 21 additions & 0 deletions src/test/groovy/graphql/incremental/DeferPayloadTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package graphql.incremental


import spock.lang.Specification

class DeferPayloadTest extends Specification {
def "null data is included"() {
def payload = DeferPayload.newDeferredItem()
.data(null)
.build()

when:
def spec = payload.toSpecification()

then:
spec == [
data : null,
path : null,
]
}
}
20 changes: 20 additions & 0 deletions src/test/groovy/graphql/incremental/StreamPayloadTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package graphql.incremental

import spock.lang.Specification

class StreamPayloadTest extends Specification {
def "null data is included"() {
def payload = StreamPayload.newStreamedItem()
.items(null)
.build()

when:
def spec = payload.toSpecification()

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

0 comments on commit 17783d6

Please sign in to comment.