Skip to content

fix(server): do not inject rateLimit into mutations - #22

Open
mjarlund wants to merge 1 commit into
alysnnix:mainfrom
mjarlund:fix/rate-limit-on-mutations
Open

mjarlund wants to merge 1 commit into
alysnnix:mainfrom
mjarlund:fix/rate-limit-on-mutations

Conversation

@mjarlund

Copy link
Copy Markdown

injectRateLimit adds rateLimit { cost remaining limit resetAt } immediately after the operation's opening brace, which is correct for a query and invalid for a mutation: rateLimit is a field on the Query root only.

Result: every mutation the plugin sends fails before it reaches the API.

Request failed: gh: Field 'rateLimit' doesn't exist on type 'Mutation'

Reproduced directly, without the plugin:

gh api graphql -f 'query=mutation { __typename rateLimit { cost } }'
# {"errors":[{"path":["mutation","rateLimit"],"extensions":{"code":"undefinedField",
#   "typeName":"Mutation","fieldName":"rateLimit"},
#   "message":"Field 'rateLimit' doesn't exist on type 'Mutation'"}]}
gh api graphql -f 'query=mutation { __typename }'
# {"data":{"__typename":"Mutation"}}

So Approve, Merge, and label add/remove are all dead in the installed build (d6f7184a); the merge button in the detail panel surfaces it as the popup seen above.

This skips injection when the operation after any leading fragments starts with mutation. Queries — shorthand { … }, named query X(…), and queries preceded by fragment definitions — are untouched and still report their cost.

Checked against the three shapes the plugin actually sends:

document before after
mutation($id: ID!, $method: PullRequestMergeMethod!) { … } rejected sent unchanged
query { viewer { login } } injected injected
query Board($login: String!) { … } injected injected
fragment F on PullRequest { id }\nquery { … } injected injected

Happy to add a unit test for the mutation case if you want one in the repo — there is no existing test file for rate-limit.ts.

rateLimit is a field on the Query root. injectRateLimit added it as a sibling of
every operation's root fields, so every mutation document failed with
"Field 'rateLimit' doesn't exist on type 'Mutation'" — approve, merge, label edit
and label remove were all dead.

Skip injection for mutation operations. Queries (shorthand, named, with leading
fragments) still get the reading.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant