Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/github/rate-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ function skipFragments(query: string): number {
*/
export function injectRateLimit(query: string): string {
const operationStart = skipFragments(query);
// `rateLimit` is a field on the Query root only. Injecting it into a mutation
// makes GitHub reject the whole document — "Field 'rateLimit' doesn't exist on
// type 'Mutation'" — which failed every approve, merge and label action.
if (/^\s*mutation\b/.test(query.slice(operationStart))) {
return query;
}
const braceIndex = query.indexOf("{", operationStart);
if (braceIndex === -1) return query;
return `${query.slice(0, braceIndex + 1)}\n rateLimit { cost remaining limit resetAt }${query.slice(braceIndex + 1)}`;
Expand Down