From 63cfbbf59aaf9a20015194999e95b3fa5f82b6e7 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Mon, 13 Jul 2020 22:09:52 +0100 Subject: [PATCH] Remove operation name from the regex and default to query (#1004) --- graphene_django/static/graphene_django/graphiql.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/graphene_django/static/graphene_django/graphiql.js b/graphene_django/static/graphene_django/graphiql.js index 17836ef..45f8ad7 100644 --- a/graphene_django/static/graphene_django/graphiql.js +++ b/graphene_django/static/graphene_django/graphiql.js @@ -135,15 +135,18 @@ // Run a regex against the query to determine the operation type (query, mutation, subscription). var operationRegex = new RegExp( // Look for lines that start with an operation keyword, ignoring whitespace. - "^\\s*(query|mutation|subscription)\\s+" + - // The operation keyword should be followed by the operationName in the GraphQL parameters. - graphQLParams.operationName + + "^\\s*(query|mutation|subscription)\\s*" + + // The operation keyword should be followed by whitespace and the operationName in the GraphQL parameters (if available). + (graphQLParams.operationName ? ("\\s+" + graphQLParams.operationName) : "") + // The line should eventually encounter an opening curly brace. "[^\\{]*\\{", // Enable multiline matching. "m", ); var match = operationRegex.exec(graphQLParams.query); + if (!match) { + return "query"; + } return match[1]; }