File tree 4 files changed +11
-6
lines changed
spring-graphql/src/main/java/org/springframework/graphql/server
4 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ public abstract class AbstractGraphQlHttpHandler {
52
52
53
53
protected final Log logger = LogFactory .getLog (getClass ());
54
54
55
+ private static final MediaType APPLICATION_GRAPHQL = MediaType .parseMediaType ("application/graphql" );
55
56
56
57
private final WebGraphQlHandler graphQlHandler ;
57
58
@@ -118,10 +119,9 @@ private static Mono<SerializableGraphQlRequest> applyApplicationGraphQlFallback(
118
119
String contentTypeHeader = request .headers ().firstHeader (HttpHeaders .CONTENT_TYPE );
119
120
if (StringUtils .hasText (contentTypeHeader )) {
120
121
MediaType contentType = MediaType .parseMediaType (contentTypeHeader );
121
- MediaType applicationGraphQl = MediaType .parseMediaType ("application/graphql" );
122
122
123
123
// Spec requires application/json but some clients still use application/graphql
124
- return applicationGraphQl .includes (contentType ) ? ServerRequest .from (request )
124
+ return APPLICATION_GRAPHQL .includes (contentType ) ? ServerRequest .from (request )
125
125
.headers ((headers ) -> headers .setContentType (MediaType .APPLICATION_JSON ))
126
126
.body (request .bodyToFlux (DataBuffer .class ))
127
127
.build ()
Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ public static RequestPredicate graphQlSse(String path) {
73
73
74
74
private static class GraphQlHttpRequestPredicate implements RequestPredicate {
75
75
76
+ private static final MediaType APPLICATION_GRAPHQL = MediaType .parseMediaType ("application/graphql" );
77
+
76
78
private final PathPattern pattern ;
77
79
78
80
private final List <MediaType > contentTypes ;
@@ -86,7 +88,7 @@ private static class GraphQlHttpRequestPredicate implements RequestPredicate {
86
88
PathPatternParser parser = PathPatternParser .defaultInstance ;
87
89
path = parser .initFullPathPattern (path );
88
90
this .pattern = parser .parse (path );
89
- this .contentTypes = List .of (MediaType .APPLICATION_JSON , MediaType . parseMediaType ( "application/graphql" ) );
91
+ this .contentTypes = List .of (MediaType .APPLICATION_JSON , APPLICATION_GRAPHQL );
90
92
this .acceptedMediaTypes = accepted ;
91
93
}
92
94
Original file line number Diff line number Diff line change @@ -67,6 +67,8 @@ public abstract class AbstractGraphQlHttpHandler {
67
67
68
68
protected final Log logger = LogFactory .getLog (getClass ());
69
69
70
+ private static final MediaType APPLICATION_GRAPHQL = MediaType .parseMediaType ("application/graphql" );
71
+
70
72
private final IdGenerator idGenerator = new AlternativeJdkIdGenerator ();
71
73
72
74
private final WebGraphQlHandler graphQlHandler ;
@@ -174,9 +176,8 @@ private static SerializableGraphQlRequest applyApplicationGraphQlFallback(
174
176
String contentTypeHeader = request .headers ().firstHeader (HttpHeaders .CONTENT_TYPE );
175
177
if (StringUtils .hasText (contentTypeHeader )) {
176
178
MediaType contentType = MediaType .parseMediaType (contentTypeHeader );
177
- MediaType applicationGraphQl = MediaType .parseMediaType ("application/graphql" );
178
179
// Spec requires application/json but some clients still use application/graphql
179
- if (applicationGraphQl .includes (contentType )) {
180
+ if (APPLICATION_GRAPHQL .includes (contentType )) {
180
181
try {
181
182
request = ServerRequest .from (request )
182
183
.headers ((headers ) -> headers .setContentType (MediaType .APPLICATION_JSON ))
Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ public static RequestPredicate graphQlSse(String path) {
73
73
74
74
private static class GraphQlHttpRequestPredicate implements RequestPredicate {
75
75
76
+ private static final MediaType APPLICATION_GRAPHQL = MediaType .parseMediaType ("application/graphql" );
77
+
76
78
private final PathPattern pattern ;
77
79
78
80
private final List <MediaType > contentTypes ;
@@ -86,7 +88,7 @@ private static class GraphQlHttpRequestPredicate implements RequestPredicate {
86
88
PathPatternParser parser = PathPatternParser .defaultInstance ;
87
89
path = parser .initFullPathPattern (path );
88
90
this .pattern = parser .parse (path );
89
- this .contentTypes = List .of (MediaType .APPLICATION_JSON , MediaType . parseMediaType ( "application/graphql" ) );
91
+ this .contentTypes = List .of (MediaType .APPLICATION_JSON , APPLICATION_GRAPHQL );
90
92
this .acceptedMediaTypes = accepted ;
91
93
}
92
94
You can’t perform that action at this time.
0 commit comments