Skip to content

Commit 36ebb40

Browse files
committed
keep in sync with graphql-js
graphql/graphql-js#4348
1 parent a5f0fac commit 36ebb40

File tree

5 files changed

+23
-62
lines changed

5 files changed

+23
-62
lines changed

src/main/java/graphql/Directives.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class Directives {
4040
private static final String SPECIFIED_BY = "specifiedBy";
4141
private static final String ONE_OF = "oneOf";
4242
private static final String DEFER = "defer";
43-
private static final String NULL_ON_ERROR = "nullOnError";
43+
private static final String DISABLE_ERROR_PROPAGATION = "experimental_disableErrorPropagation";
4444

4545
public static final DirectiveDefinition DEPRECATED_DIRECTIVE_DEFINITION;
4646
public static final DirectiveDefinition INCLUDE_DIRECTIVE_DEFINITION;
@@ -51,7 +51,7 @@ public class Directives {
5151
@ExperimentalApi
5252
public static final DirectiveDefinition DEFER_DIRECTIVE_DEFINITION;
5353
@ExperimentalApi
54-
public static final DirectiveDefinition NULL_ON_ERROR_DIRECTIVE_DEFINITION;
54+
public static final DirectiveDefinition DISABLE_ERROR_PROPAGATION_DIRECTIVE_DEFINITION;
5555

5656
public static final String BOOLEAN = "Boolean";
5757
public static final String STRING = "String";
@@ -139,8 +139,8 @@ public class Directives {
139139
.type(newTypeName().name(STRING).build())
140140
.build())
141141
.build();
142-
NULL_ON_ERROR_DIRECTIVE_DEFINITION = DirectiveDefinition.newDirectiveDefinition()
143-
.name(NULL_ON_ERROR)
142+
DISABLE_ERROR_PROPAGATION_DIRECTIVE_DEFINITION = DirectiveDefinition.newDirectiveDefinition()
143+
.name(DISABLE_ERROR_PROPAGATION)
144144
.directiveLocation(newDirectiveLocation().name(QUERY.name()).build())
145145
.directiveLocation(newDirectiveLocation().name(MUTATION.name()).build())
146146
.directiveLocation(newDirectiveLocation().name(SUBSCRIPTION.name()).build())
@@ -240,11 +240,11 @@ public class Directives {
240240
.build();
241241

242242
@ExperimentalApi
243-
public static final GraphQLDirective NullOnErrorDirective = GraphQLDirective.newDirective()
244-
.name(NULL_ON_ERROR)
245-
.description("This directive allows returning null in non-null positions that have an associated error.")
243+
public static final GraphQLDirective DisableErrorPropagationDirective = GraphQLDirective.newDirective()
244+
.name(DISABLE_ERROR_PROPAGATION)
245+
.description("This directive disables error propagation for the given operation.")
246246
.validLocations(QUERY, MUTATION, SUBSCRIPTION)
247-
.definition(NULL_ON_ERROR_DIRECTIVE_DEFINITION)
247+
.definition(DISABLE_ERROR_PROPAGATION_DIRECTIVE_DEFINITION)
248248
.build();
249249

250250
private static Description createDescription(String s) {

src/main/java/graphql/ExperimentalApi.java

-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,4 @@
2424
* The key that should be associated with a boolean value which indicates whether @defer and @stream behaviour is enabled for this execution.
2525
*/
2626
String ENABLE_INCREMENTAL_SUPPORT = "ENABLE_INCREMENTAL_SUPPORT";
27-
/**
28-
* The key that should be associated with a boolean value which indicates whether @nullOnError behaviour is enabled for this execution.
29-
*/
30-
String ENABLE_NULL_ON_ERROR = "ENABLE_NULL_ON_ERROR";
3127
}

src/main/java/graphql/execution/Execution.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import java.util.Optional;
3838
import java.util.concurrent.CompletableFuture;
3939

40-
import static graphql.Directives.NULL_ON_ERROR_DIRECTIVE_DEFINITION;
40+
import static graphql.Directives.DISABLE_ERROR_PROPAGATION_DIRECTIVE_DEFINITION;
4141
import static graphql.execution.ExecutionContextBuilder.newExecutionContextBuilder;
4242
import static graphql.execution.ExecutionStepInfo.newExecutionStepInfo;
4343
import static graphql.execution.ExecutionStrategyParameters.newParameters;
@@ -88,10 +88,7 @@ public CompletableFuture<ExecutionResult> execute(Document document, GraphQLSche
8888
throw rte;
8989
}
9090

91-
boolean customErrorPropagationEnabled = Optional.ofNullable(executionInput.getGraphQLContext())
92-
.map(graphqlContext -> graphqlContext.getBoolean(ExperimentalApi.ENABLE_NULL_ON_ERROR))
93-
.orElse(false);
94-
boolean propagateErrors = !customErrorPropagationEnabled || propagateErrors(operationDefinition.getDirectives(), true);
91+
boolean propagateErrors = propagateErrors(operationDefinition.getDirectives(), true);
9592

9693
ExecutionContext executionContext = newExecutionContextBuilder()
9794
.instrumentation(instrumentation)
@@ -272,7 +269,7 @@ private ExecutionResult mergeExtensionsBuilderIfPresent(ExecutionResult executio
272269
}
273270

274271
private boolean propagateErrors(List<Directive> directives, boolean defaultValue) {
275-
Directive foundDirective = NodeUtil.findNodeByName(directives, NULL_ON_ERROR_DIRECTIVE_DEFINITION.getName());
272+
Directive foundDirective = NodeUtil.findNodeByName(directives, DISABLE_ERROR_PROPAGATION_DIRECTIVE_DEFINITION.getName());
276273
if (foundDirective != null) {
277274
return false;
278275
}

src/main/java/graphql/execution/ExecutionContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public ValueUnboxer getValueUnboxer() {
176176
/**
177177
* @return true if the current operation should propagate errors in non-null positions
178178
* Propagating errors is the default. Error aware clients may opt in returning null in non-null positions
179-
* by using the `@nullOnError` directive.
179+
* by using the `@experimental_disableErrorPropagation` directive.
180180
*/
181181
@ExperimentalApi
182182
public boolean propagateErrors() { return propagateErrors; }
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
package graphql.execution
22

33
import graphql.ExecutionInput
4-
import graphql.ExperimentalApi
54
import graphql.TestUtil
65
import spock.lang.Specification
76

87
class NoErrorPropagationTest extends Specification {
98

10-
def "with nullOnError, null is returned"() {
9+
def "with experimental_disableErrorPropagation, null is returned"() {
1110

1211
def sdl = '''
1312
type Query {
1413
foo : Int!
1514
}
16-
directive @nullOnError on QUERY | MUTATION | SUBSCRIPTION
15+
directive @experimental_disableErrorPropagation on QUERY | MUTATION | SUBSCRIPTION
1716
'''
1817

1918
def graphql = TestUtil.graphQL(sdl).build()
2019

2120
def query = '''
22-
query GetFoo @nullOnError { foo }
21+
query GetFoo @experimental_disableErrorPropagation { foo }
2322
'''
2423
when:
2524

2625
ExecutionInput ei = ExecutionInput.newExecutionInput(query).root(
2726
[foo: null]
28-
).graphQLContext([(ExperimentalApi.ENABLE_NULL_ON_ERROR): true])
29-
.build()
27+
).build()
3028

3129
def er = graphql.execute(ei)
3230

@@ -36,13 +34,13 @@ class NoErrorPropagationTest extends Specification {
3634
er.errors[0].path.toList() == ["foo"]
3735
}
3836

39-
def "without nullOnError, error is propagated"() {
37+
def "without experimental_disableErrorPropagation, error is propagated"() {
4038

4139
def sdl = '''
4240
type Query {
4341
foo : Int!
4442
}
45-
directive @nullOnError on QUERY | MUTATION | SUBSCRIPTION
43+
directive @experimental_disableErrorPropagation on QUERY | MUTATION | SUBSCRIPTION
4644
'''
4745

4846
def graphql = TestUtil.graphQL(sdl).build()
@@ -54,8 +52,7 @@ class NoErrorPropagationTest extends Specification {
5452

5553
ExecutionInput ei = ExecutionInput.newExecutionInput(query).root(
5654
[foo: null]
57-
).graphQLContext([(ExperimentalApi.ENABLE_NULL_ON_ERROR): true])
58-
.build()
55+
).build()
5956

6057
def er = graphql.execute(ei)
6158

@@ -64,21 +61,19 @@ class NoErrorPropagationTest extends Specification {
6461
er.errors[0].message == "The field at path '/foo' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value. The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is 'Int' within parent type 'Query'"
6562
er.errors[0].path.toList() == ["foo"]
6663
}
67-
68-
69-
def "when ENABLE_NULL_ON_ERROR is false, error is propagated"() {
64+
65+
def "when @experimental_disableErrorPropagation is not added to the schema operation does not validate"() {
7066

7167
def sdl = '''
7268
type Query {
7369
foo : Int!
7470
}
75-
directive @nullOnError on QUERY | MUTATION | SUBSCRIPTION
7671
'''
7772

7873
def graphql = TestUtil.graphQL(sdl).build()
7974

8075
def query = '''
81-
query GetFoo @nullOnError { foo }
76+
query GetFoo @experimental_disableErrorPropagation { foo }
8277
'''
8378
when:
8479

@@ -90,34 +85,7 @@ class NoErrorPropagationTest extends Specification {
9085

9186
then:
9287
er.data == null
93-
er.errors[0].path.toList() == ["foo"]
94-
}
95-
96-
def "when @nullOnError is not added to the schema operation does not validate"() {
97-
98-
def sdl = '''
99-
type Query {
100-
foo : Int!
101-
}
102-
'''
103-
104-
def graphql = TestUtil.graphQL(sdl).build()
105-
106-
def query = '''
107-
query GetFoo @nullOnError { foo }
108-
'''
109-
when:
110-
111-
ExecutionInput ei = ExecutionInput.newExecutionInput(query).root(
112-
[foo: null]
113-
).graphQLContext([(ExperimentalApi.ENABLE_NULL_ON_ERROR): true])
114-
.build()
115-
116-
def er = graphql.execute(ei)
117-
118-
then:
119-
er.data == null
120-
er.errors[0].message.equals("Validation error (UnknownDirective) : Unknown directive 'nullOnError'")
88+
er.errors[0].message.equals("Validation error (UnknownDirective) : Unknown directive 'experimental_disableErrorPropagation'")
12189
}
12290

12391
}

0 commit comments

Comments
 (0)