forked from graphql-java/graphql-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeferPayload.java
72 lines (59 loc) · 1.84 KB
/
DeferPayload.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package graphql.incremental;
import graphql.ExperimentalApi;
import graphql.GraphQLError;
import javax.annotation.Nullable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Represents a defer payload
*/
@ExperimentalApi
public class DeferPayload extends IncrementalPayload {
private final Object data;
private DeferPayload(Object data, List<Object> path, String label, List<GraphQLError> errors, Map<Object, Object> extensions) {
super(path, label, errors, extensions);
this.data = data;
}
/**
* @return the resolved data
* @param <T> the type to cast the result to
*/
@Nullable
public <T> T getData() {
//noinspection unchecked
return (T) this.data;
}
/**
* @return a map of this payload that strictly follows the spec
*/
@Override
public Map<String, Object> toSpecification() {
Map<String, Object> map = new LinkedHashMap<>(super.toSpecification());
if (data != null) {
map.put("data", data);
}
return map;
}
/**
* @return a {@link DeferPayload.Builder} that can be used to create an instance of {@link DeferPayload}
*/
public static DeferPayload.Builder newDeferredItem() {
return new DeferPayload.Builder();
}
public static class Builder extends IncrementalPayload.Builder<Builder> {
private Object data = null;
public Builder data(Object data) {
this.data = data;
return this;
}
public Builder from(DeferPayload deferredItem) {
super.from(deferredItem);
this.data = deferredItem.data;
return this;
}
public DeferPayload build() {
return new DeferPayload(data, this.path, this.label, this.errors, this.extensions);
}
}
}