@@ -44,7 +44,7 @@ public class GraphQlHttpHandler extends AbstractGraphQlHttpHandler {
44
44
private static final List <MediaType > SUPPORTED_MEDIA_TYPES = List .of (
45
45
MediaTypes .APPLICATION_GRAPHQL_RESPONSE , MediaType .APPLICATION_JSON , APPLICATION_GRAPHQL );
46
46
47
- private boolean isStandardMode = false ;
47
+ private boolean httpOkOnValidationErrors = false ;
48
48
49
49
50
50
/**
@@ -65,29 +65,31 @@ public GraphQlHttpHandler(WebGraphQlHandler graphQlHandler, CodecConfigurer code
65
65
}
66
66
67
67
/**
68
- * Return whether this HTTP handler should conform to the "GraphQL over HTTP specification"
69
- * when the {@link MediaTypes#APPLICATION_GRAPHQL_RESPONSE} is selected.
70
- * <p>When enabled, this mode will use 4xx/5xx HTTP response status if an error occurs before
68
+ * Return whether this HTTP handler should use HTTP 200 OK responses if an error occurs before
71
69
* the GraphQL request execution phase starts; for example, if JSON parsing, GraphQL document parsing,
72
- * or GraphQL document validation fails. When disabled, behavior will remain consistent with the
73
- * "application/json" response content type.
70
+ * or GraphQL document validation fail.
71
+ * <p>This option only applies to {@link MediaTypes#APPLICATION_GRAPHQL_RESPONSE} responses,
72
+ * as legacy {@link MediaType#APPLICATION_JSON} responses always use HTTP 200 OK in such cases.
73
+ * Enabling this option means the server will not conform to the "GraphQL over HTTP specification".
74
74
* <p>By default, this is set to {@code false}.
75
75
* @since 1.4.0
76
76
* @see <a href="https://graphql.github.io/graphql-over-http/draft/#sec-application-graphql-response-json">GraphQL over HTTP specification</a>
77
77
*/
78
- public boolean isStandardMode () {
79
- return this .isStandardMode ;
78
+ public boolean isHttpOkOnValidationErrors () {
79
+ return this .httpOkOnValidationErrors ;
80
80
}
81
81
82
82
/**
83
- * Set whether this HTTP handler should conform to the "GraphQL over HTTP specification"
84
- * when the {@link MediaTypes#APPLICATION_GRAPHQL_RESPONSE} is selected .
85
- * @param standardMode whether the "standard mode" should be enabled
83
+ * Set whether this HTTP handler should use HTTP 200 OK responses if an error occurs before
84
+ * the GraphQL request execution phase starts .
85
+ * @param httpOkOnValidationErrors whether "HTTP 200 OK" responses should always be used
86
86
* @since 1.4.0
87
- * @see #isStandardMode
87
+ * @deprecated since 1.4, will be made {@code false} permanently in a future release
88
+ * @see #isHttpOkOnValidationErrors
88
89
*/
89
- public void setStandardMode (boolean standardMode ) {
90
- this .isStandardMode = standardMode ;
90
+ @ Deprecated (since = "1.4.0" , forRemoval = true )
91
+ public void setHttpOkOnValidationErrors (boolean httpOkOnValidationErrors ) {
92
+ this .httpOkOnValidationErrors = httpOkOnValidationErrors ;
91
93
}
92
94
93
95
protected Mono <ServerResponse > prepareResponse (ServerRequest request , WebGraphQlResponse response ) {
@@ -100,7 +102,7 @@ protected Mono<ServerResponse> prepareResponse(ServerRequest request, WebGraphQl
100
102
}
101
103
102
104
protected HttpStatus selectResponseStatus (WebGraphQlResponse response , MediaType responseMediaType ) {
103
- if (this . isStandardMode
105
+ if (! isHttpOkOnValidationErrors ()
104
106
&& !response .getExecutionResult ().isDataPresent ()
105
107
&& MediaTypes .APPLICATION_GRAPHQL_RESPONSE .equals (responseMediaType )) {
106
108
return HttpStatus .BAD_REQUEST ;
0 commit comments