Remove operation name from the regex and default to query (#1004)

This commit is contained in:
Jonathan Kim 2020-07-13 22:09:52 +01:00 committed by GitHub
parent e439bf3727
commit 63cfbbf59a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -135,15 +135,18 @@
// Run a regex against the query to determine the operation type (query, mutation, subscription). // Run a regex against the query to determine the operation type (query, mutation, subscription).
var operationRegex = new RegExp( var operationRegex = new RegExp(
// Look for lines that start with an operation keyword, ignoring whitespace. // Look for lines that start with an operation keyword, ignoring whitespace.
"^\\s*(query|mutation|subscription)\\s+" + "^\\s*(query|mutation|subscription)\\s*" +
// The operation keyword should be followed by the operationName in the GraphQL parameters. // The operation keyword should be followed by whitespace and the operationName in the GraphQL parameters (if available).
graphQLParams.operationName + (graphQLParams.operationName ? ("\\s+" + graphQLParams.operationName) : "") +
// The line should eventually encounter an opening curly brace. // The line should eventually encounter an opening curly brace.
"[^\\{]*\\{", "[^\\{]*\\{",
// Enable multiline matching. // Enable multiline matching.
"m", "m",
); );
var match = operationRegex.exec(graphQLParams.query); var match = operationRegex.exec(graphQLParams.query);
if (!match) {
return "query";
}
return match[1]; return match[1];
} }