File tree Expand file tree Collapse file tree 4 files changed +11
-6
lines changed
spring-graphql/src/main/java/org/springframework/graphql/server Expand file tree Collapse file tree 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 {
5252
5353 protected final Log logger = LogFactory .getLog (getClass ());
5454
55+ private static final MediaType APPLICATION_GRAPHQL = MediaType .parseMediaType ("application/graphql" );
5556
5657 private final WebGraphQlHandler graphQlHandler ;
5758
@@ -118,10 +119,9 @@ private static Mono<SerializableGraphQlRequest> applyApplicationGraphQlFallback(
118119 String contentTypeHeader = request .headers ().firstHeader (HttpHeaders .CONTENT_TYPE );
119120 if (StringUtils .hasText (contentTypeHeader )) {
120121 MediaType contentType = MediaType .parseMediaType (contentTypeHeader );
121- MediaType applicationGraphQl = MediaType .parseMediaType ("application/graphql" );
122122
123123 // 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 )
125125 .headers ((headers ) -> headers .setContentType (MediaType .APPLICATION_JSON ))
126126 .body (request .bodyToFlux (DataBuffer .class ))
127127 .build ()
Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ public static RequestPredicate graphQlSse(String path) {
7373
7474 private static class GraphQlHttpRequestPredicate implements RequestPredicate {
7575
76+ private static final MediaType APPLICATION_GRAPHQL = MediaType .parseMediaType ("application/graphql" );
77+
7678 private final PathPattern pattern ;
7779
7880 private final List <MediaType > contentTypes ;
@@ -86,7 +88,7 @@ private static class GraphQlHttpRequestPredicate implements RequestPredicate {
8688 PathPatternParser parser = PathPatternParser .defaultInstance ;
8789 path = parser .initFullPathPattern (path );
8890 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 );
9092 this .acceptedMediaTypes = accepted ;
9193 }
9294
Original file line number Diff line number Diff line change @@ -67,6 +67,8 @@ public abstract class AbstractGraphQlHttpHandler {
6767
6868 protected final Log logger = LogFactory .getLog (getClass ());
6969
70+ private static final MediaType APPLICATION_GRAPHQL = MediaType .parseMediaType ("application/graphql" );
71+
7072 private final IdGenerator idGenerator = new AlternativeJdkIdGenerator ();
7173
7274 private final WebGraphQlHandler graphQlHandler ;
@@ -174,9 +176,8 @@ private static SerializableGraphQlRequest applyApplicationGraphQlFallback(
174176 String contentTypeHeader = request .headers ().firstHeader (HttpHeaders .CONTENT_TYPE );
175177 if (StringUtils .hasText (contentTypeHeader )) {
176178 MediaType contentType = MediaType .parseMediaType (contentTypeHeader );
177- MediaType applicationGraphQl = MediaType .parseMediaType ("application/graphql" );
178179 // Spec requires application/json but some clients still use application/graphql
179- if (applicationGraphQl .includes (contentType )) {
180+ if (APPLICATION_GRAPHQL .includes (contentType )) {
180181 try {
181182 request = ServerRequest .from (request )
182183 .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) {
7373
7474 private static class GraphQlHttpRequestPredicate implements RequestPredicate {
7575
76+ private static final MediaType APPLICATION_GRAPHQL = MediaType .parseMediaType ("application/graphql" );
77+
7678 private final PathPattern pattern ;
7779
7880 private final List <MediaType > contentTypes ;
@@ -86,7 +88,7 @@ private static class GraphQlHttpRequestPredicate implements RequestPredicate {
8688 PathPatternParser parser = PathPatternParser .defaultInstance ;
8789 path = parser .initFullPathPattern (path );
8890 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 );
9092 this .acceptedMediaTypes = accepted ;
9193 }
9294
You can’t perform that action at this time.
0 commit comments