Skip to content

Commit eb00f57

Browse files
committed
Add integration test
1 parent 2c6fd1c commit eb00f57

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/main/java/graphql/execution/NonNullableFieldValidator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public NonNullableFieldValidator(ExecutionContext executionContext, ExecutionSte
3434
*/
3535
public <T> T validate(ExecutionStrategyParameters parameters, T result) throws NonNullableFieldWasNullException {
3636
if (result == null) {
37-
if (executionStepInfo.isNonNullType() && executionContext.propagateErrors()) {
37+
if (executionStepInfo.isNonNullType()) {
3838
// see https://spec.graphql.org/October2021/#sec-Errors-and-Non-Nullability
3939
//
4040
// > If the field returns null because of an error which has already been added to the "errors" list in the response,
@@ -56,7 +56,9 @@ public <T> T validate(ExecutionStrategyParameters parameters, T result) throws N
5656
} else {
5757
executionContext.addError(error, path);
5858
}
59-
throw nonNullException;
59+
if (executionContext.propagateErrors()) {
60+
throw nonNullException;
61+
}
6062
}
6163
}
6264
return result;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package graphql.execution
2+
3+
import graphql.ExecutionInput
4+
import graphql.TestUtil
5+
import graphql.schema.idl.RuntimeWiring
6+
import graphql.schema.idl.SchemaGenerator
7+
import graphql.GraphQL
8+
import spock.lang.Specification
9+
10+
class NoErrorPropagationTest extends Specification {
11+
12+
def "when error propagation is disabled null is returned"() {
13+
14+
def sdl = '''
15+
type Query {
16+
foo : Int!
17+
}
18+
'''
19+
20+
def options = SchemaGenerator.Options.defaultOptions().addOnErrorDirective(true)
21+
22+
def schema = TestUtil.schema(options, sdl, RuntimeWiring.MOCKED_WIRING)
23+
def graphql = GraphQL.newGraphQL(schema).build()
24+
25+
def query = '''
26+
query GetFoo @errorHandling(onError: NULL) { foo }
27+
'''
28+
when:
29+
30+
ExecutionInput ei = ExecutionInput.newExecutionInput(query).root(
31+
[foo: null]
32+
).build()
33+
34+
def er = graphql.execute(ei)
35+
36+
then:
37+
er.data != null
38+
er.data.foo == null
39+
er.errors[0].path.toList() == ["foo"]
40+
}
41+
}

0 commit comments

Comments
 (0)