@@ -84,8 +84,7 @@ public WebGraphQlRequest(
84
84
URI uri , HttpHeaders headers , @ Nullable MultiValueMap <String , HttpCookie > cookies ,
85
85
Map <String , Object > attributes , Map <String , Object > body , String id , @ Nullable Locale locale ) {
86
86
87
- super (getKey ("query" , body ), getKey ("operationName" , body ), getKey ("variables" , body ),
88
- getKey ("extensions" , body ), id , locale );
87
+ super (getQuery (body ), getOperation (body ), getMap ("variables" , body ), getMap ("extensions" , body ), id , locale );
89
88
90
89
Assert .notNull (uri , "URI is required'" );
91
90
Assert .notNull (headers , "HttpHeaders is required'" );
@@ -96,12 +95,31 @@ public WebGraphQlRequest(
96
95
this .attributes = Collections .unmodifiableMap (attributes );
97
96
}
98
97
98
+ private static String getQuery (Map <String , Object > body ) {
99
+ Object value = body .get ("query" );
100
+ if (!(value instanceof String query ) || !StringUtils .hasText (query )) {
101
+ throw new ServerWebInputException ("Invalid value for 'query'" );
102
+ }
103
+ return (String ) value ;
104
+ }
105
+
106
+ @ Nullable
107
+ private static String getOperation (Map <String , Object > body ) {
108
+ Object value = body .get ("operation" );
109
+ if (value != null && !(value instanceof String )) {
110
+ throw new ServerWebInputException ("Invalid value for 'operation'" );
111
+ }
112
+ return (String ) value ;
113
+ }
114
+
99
115
@ SuppressWarnings ("unchecked" )
100
- private static <T > T getKey (String key , Map <String , Object > body ) {
101
- if (key .equals ("query" ) && !StringUtils .hasText ((String ) body .get (key ))) {
102
- throw new ServerWebInputException ("No \" query\" in the request document" );
116
+ @ Nullable
117
+ private static Map <String , Object > getMap (String key , Map <String , Object > body ) {
118
+ Object value = body .get (key );
119
+ if (value != null && !(value instanceof Map )) {
120
+ throw new ServerWebInputException ("Invalid value for '" + key + "'" );
103
121
}
104
- return (T ) body . get ( key ) ;
122
+ return (Map < String , Object >) value ;
105
123
}
106
124
107
125
0 commit comments