@@ -182,16 +182,20 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
182182 path = req .getServletPath ();
183183 }
184184 if (path .contentEquals ("/schema.json" )) {
185- query (CharStreams .toString (new InputStreamReader (GraphQLServlet .class .getResourceAsStream ("introspectionQuery" ))), new HashMap <>(), schema , req , resp , context );
185+ query (CharStreams .toString (new InputStreamReader (GraphQLServlet .class .getResourceAsStream ("introspectionQuery" ))), null , new HashMap <>(), schema , req , resp , context );
186186 } else {
187187 if (req .getParameter ("q" ) != null ) {
188- query (req .getParameter ("q" ), new HashMap <>(), readOnlySchema , req , resp , context );
188+ query (req .getParameter ("q" ), null , new HashMap <>(), readOnlySchema , req , resp , context );
189189 } else if (req .getParameter ("query" ) != null ) {
190190 Map <String ,Object > variables = new HashMap <>();
191191 if (req .getParameter ("variables" ) != null ) {
192192 variables .putAll (new ObjectMapper ().readValue (req .getParameter ("variables" ), new TypeReference <Map <String ,Object >>() {}));
193193 }
194- query (req .getParameter ("query" ), variables , readOnlySchema , req , resp , context );
194+ String operationName = null ;
195+ if (req .getParameter ("operationName" ) != null ) {
196+ operationName = req .getParameter ("operationName" );
197+ }
198+ query (req .getParameter ("query" ), operationName , variables , readOnlySchema , req , resp , context );
195199 }
196200 }
197201 }
@@ -226,20 +230,20 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
226230 if (variables == null ) {
227231 variables = new HashMap <>();
228232 }
229- query (request .query , variables , schema , req , resp , context );
233+ query (request .query , request . operationName , variables , schema , req , resp , context );
230234 }
231235
232- private void query (String query , Map <String , Object > variables , GraphQLSchema schema , HttpServletRequest req , HttpServletResponse resp , GraphQLContext context ) throws IOException {
236+ private void query (String query , String operationName , Map <String , Object > variables , GraphQLSchema schema , HttpServletRequest req , HttpServletResponse resp , GraphQLContext context ) throws IOException {
233237 if (Subject .getSubject (AccessController .getContext ()) == null && context .getSubject ().isPresent ()) {
234238 Subject .doAs (context .getSubject ().get (), new PrivilegedAction <Void >() {
235239 @ Override @ SneakyThrows
236240 public Void run () {
237- query (query , variables , schema , req , resp , context );
241+ query (query , operationName , variables , schema , req , resp , context );
238242 return null ;
239243 }
240244 });
241245 } else {
242- ExecutionResult result = new GraphQL (schema , executionStrategyProvider .getExecutionStrategy ()).execute (query , context , variables );
246+ ExecutionResult result = new GraphQL (schema , executionStrategyProvider .getExecutionStrategy ()).execute (query , operationName , context , variables );
243247 resp .setContentType ("application/json" );
244248 if (result .getErrors ().isEmpty ()) {
245249 Map <String , Object > dict = new HashMap <>();
0 commit comments