Skip to content

Commit 2c6fd1c

Browse files
committed
add test for NonNullableFieldValidator
1 parent 63dcac3 commit 2c6fd1c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/test/groovy/graphql/execution/NonNullableFieldValidatorTest.groovy

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import static graphql.schema.GraphQLNonNull.nonNull
77

88
class NonNullableFieldValidatorTest extends Specification {
99

10-
ExecutionContext context = Mock(ExecutionContext) {
11-
propagateErrors() >> true
12-
}
13-
1410
def parameters = Mock(ExecutionStrategyParameters) {
1511
getPath() >> ResultPath.rootPath()
1612
}
1713

1814
def "non nullable field throws exception"() {
15+
ExecutionContext context = Mock(ExecutionContext) {
16+
propagateErrors() >> true
17+
}
18+
1919
ExecutionStepInfo typeInfo = ExecutionStepInfo.newExecutionStepInfo().type(nonNull(GraphQLString)).build()
2020

2121
NonNullableFieldValidator validator = new NonNullableFieldValidator(context, typeInfo)
@@ -29,6 +29,10 @@ class NonNullableFieldValidatorTest extends Specification {
2929
}
3030

3131
def "nullable field does not throw exception"() {
32+
ExecutionContext context = Mock(ExecutionContext) {
33+
propagateErrors() >> true
34+
}
35+
3236
ExecutionStepInfo typeInfo = ExecutionStepInfo.newExecutionStepInfo().type(GraphQLString).build()
3337

3438
NonNullableFieldValidator validator = new NonNullableFieldValidator(context, typeInfo)
@@ -39,4 +43,20 @@ class NonNullableFieldValidatorTest extends Specification {
3943
then:
4044
result == null
4145
}
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+
}
4262
}

0 commit comments

Comments
 (0)