Repository navigation
Expand file tree
/
Copy pathNonNullableFieldWasNullException.java
More file actions
60 lines (49 loc) · 2.12 KB
/
Copy pathNonNullableFieldWasNullException.java
File metadata and controls
60 lines (49 loc) · 2.12 KB
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
package graphql.execution;
import static graphql.Assert.assertNotNull;
/**
* See (http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability), but if a non nullable field
* actually resolves to a null value and the parent type is nullable then the parent must in fact become null
* so we use exceptions to indicate this special case
*/
public class NonNullableFieldWasNullException extends RuntimeException {
private final ExecutionInfo executionInfo;
private final ExecutionPath path;
public NonNullableFieldWasNullException(ExecutionInfo executionInfo, ExecutionPath path) {
super(
mkMessage(assertNotNull(executionInfo),
assertNotNull(path))
);
this.executionInfo = executionInfo;
this.path = path;
}
public NonNullableFieldWasNullException(NonNullableFieldWasNullException previousException) {
super(
mkMessage(
assertNotNull(previousException.executionInfo.getParent()),
assertNotNull(previousException.executionInfo.getParent().getPath())
),
previousException
);
this.executionInfo = previousException.executionInfo.getParent();
this.path = previousException.executionInfo.getParent().getPath();
}
private static String mkMessage(ExecutionInfo executionInfo, ExecutionPath path) {
if (executionInfo.hasParent()) {
return String.format("Cannot return null for non-nullable type: '%s' within parent '%s' (%s)", executionInfo.getType().getName(), executionInfo.getParent().getType().getName(), path);
}
return String.format("Cannot return null for non-nullable type: '%s' (%s)", executionInfo.getType().getName(), path);
}
public ExecutionInfo getExecutionInfo() {
return executionInfo;
}
public ExecutionPath getPath() {
return path;
}
@Override
public String toString() {
return "NonNullableFieldWasNullException{" +
" path=" + path +
" executionInfo=" + executionInfo +
'}';
}
}