Skip to content

Commit 63cfbbf

Browse files
authored
Remove operation name from the regex and default to query (#1004)
1 parent e439bf3 commit 63cfbbf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

graphene_django/static/graphene_django/graphiql.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,18 @@
135135
// Run a regex against the query to determine the operation type (query, mutation, subscription).
136136
var operationRegex = new RegExp(
137137
// Look for lines that start with an operation keyword, ignoring whitespace.
138-
"^\\s*(query|mutation|subscription)\\s+" +
139-
// The operation keyword should be followed by the operationName in the GraphQL parameters.
140-
graphQLParams.operationName +
138+
"^\\s*(query|mutation|subscription)\\s*" +
139+
// The operation keyword should be followed by whitespace and the operationName in the GraphQL parameters (if available).
140+
(graphQLParams.operationName ? ("\\s+" + graphQLParams.operationName) : "") +
141141
// The line should eventually encounter an opening curly brace.
142142
"[^\\{]*\\{",
143143
// Enable multiline matching.
144144
"m",
145145
);
146146
var match = operationRegex.exec(graphQLParams.query);
147+
if (!match) {
148+
return "query";
149+
}
147150

148151
return match[1];
149152
}

0 commit comments

Comments
 (0)