@@ -7,15 +7,15 @@ import static graphql.schema.GraphQLNonNull.nonNull
7
7
8
8
class NonNullableFieldValidatorTest extends Specification {
9
9
10
- ExecutionContext context = Mock (ExecutionContext ) {
11
- propagateErrors() >> true
12
- }
13
-
14
10
def parameters = Mock (ExecutionStrategyParameters ) {
15
11
getPath() >> ResultPath . rootPath()
16
12
}
17
13
18
14
def " non nullable field throws exception" () {
15
+ ExecutionContext context = Mock (ExecutionContext ) {
16
+ propagateErrors() >> true
17
+ }
18
+
19
19
ExecutionStepInfo typeInfo = ExecutionStepInfo . newExecutionStepInfo(). type(nonNull(GraphQLString )). build()
20
20
21
21
NonNullableFieldValidator validator = new NonNullableFieldValidator (context, typeInfo)
@@ -29,6 +29,10 @@ class NonNullableFieldValidatorTest extends Specification {
29
29
}
30
30
31
31
def " nullable field does not throw exception" () {
32
+ ExecutionContext context = Mock (ExecutionContext ) {
33
+ propagateErrors() >> true
34
+ }
35
+
32
36
ExecutionStepInfo typeInfo = ExecutionStepInfo . newExecutionStepInfo(). type(GraphQLString ). build()
33
37
34
38
NonNullableFieldValidator validator = new NonNullableFieldValidator (context, typeInfo)
@@ -39,4 +43,20 @@ class NonNullableFieldValidatorTest extends Specification {
39
43
then :
40
44
result == null
41
45
}
46
+
47
+ def " non nullable field returns null if errors are not propagated" () {
48
+ ExecutionContext context = Mock (ExecutionContext ) {
49
+ propagateErrors() >> false
50
+ }
51
+
52
+ ExecutionStepInfo typeInfo = ExecutionStepInfo . newExecutionStepInfo(). type(nonNull(GraphQLString )). build()
53
+
54
+ NonNullableFieldValidator validator = new NonNullableFieldValidator (context, typeInfo)
55
+
56
+ when :
57
+ def result = validator. validate(parameters, null )
58
+
59
+ then :
60
+ result == null
61
+ }
42
62
}
0 commit comments