{"record":{"id":"a6edbce5eaf016ac","repo":"666ghj/MiroFish","slug":"github-graphql-rejected-the-stargazer-request","errorCode":null,"errorMessage":"GitHub GraphQL rejected the stargazer request","messagePattern":"GitHub GraphQL rejected the stargazer request","errorType":"exception","errorClass":"StarHistoryError","httpStatus":null,"severity":"error","filePath":"scripts/star_history.py","lineNumber":245,"sourceCode":"            f\"name={REPOSITORY_NAME}\",\n        ]\n        if after is not None:\n            if not after or \"\\n\" in after or \"\\r\" in after:\n                raise StarHistoryError(\"GitHub returned an invalid pagination cursor\")\n            arguments.extend((\"-f\", f\"after={after}\"))\n\n        completed = self._runner.run(arguments)\n        if completed.returncode != 0:\n            raise StarHistoryError(\n                f\"GitHub GraphQL request failed (exit {completed.returncode})\"\n            )\n        try:\n            payload = json.loads(completed.stdout)\n        except json.JSONDecodeError as exc:\n            raise StarHistoryError(\"GitHub GraphQL returned malformed JSON\") from exc\n\n        if not isinstance(payload, dict) or payload.get(\"errors\"):\n            raise StarHistoryError(\"GitHub GraphQL rejected the stargazer request\")\n        try:\n            data = payload[\"data\"]\n            repository = data[\"repository\"]\n            stargazers = repository[\"stargazers\"]\n            rate_limit = data[\"rateLimit\"]\n            raw_edges = stargazers[\"edges\"]\n            page_info = stargazers[\"pageInfo\"]\n        except (KeyError, TypeError) as exc:\n            raise StarHistoryError(\"GitHub GraphQL response had an unexpected shape\") from exc\n\n        if not all(\n            isinstance(value, dict)\n            for value in (data, repository, stargazers, rate_limit, page_info)\n        ):\n            raise StarHistoryError(\"GitHub GraphQL response had an unexpected shape\")\n\n        total_count = _strict_non_negative_int(\n            stargazers.get(\"totalCount\"), \"GraphQL totalCount\"","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/666ghj/MiroFish/blob/b5b53acc57189a4a42e44a23e149dc655c98fe82/scripts/star_history.py#L227-L263","documentation":"GraphQL-level rejection: the parsed JSON body is not an object, or it contains a top-level \"errors\" array. With gh exit 0 this still happens — GraphQL returns 200 with an errors array for query problems, type errors, bad cursor values (BAD_CURSOR / pagination cost), or insufficient scopes.","triggerScenarios":"Passing an invalid or stale after cursor (GitHub returns '... is not a valid cursor'); GraphQL variables owner/name of a wrong type; missing rateLimit or stargazers field in a pinned query against a changed schema; token lacking public repo read; query cost exceeding GraphQL rate limits.","commonSituations":"Resuming backfill with a cursor from a different GraphQL endpoint or an old schema; gh token scopes trimmed; GitHub GraphQL API schema evolution breaking the pinned GRAPHQL_QUERY.","solutions":["Print payload['errors'] (it contains messages like 'wasn't a valid cursor') to identify the exact GraphQL complaint.","If the cursor is stale/corrupt, drop back to the last known-good cursor in history.json and re-fetch that page.","Verify the token's scopes with gh auth status; public stargazer reads need public access.","If the schema changed, update GRAPHQL_QUERY in scripts/star_history.py to the current stargazers/rateLimit shape and re-run."],"exampleFix":"# before: generic rejection message\nif not isinstance(payload, dict) or payload.get(\"errors\"):\n    raise StarHistoryError(\"GitHub GraphQL rejected the stargazer request\")\n\n# after: include the GraphQL error messages (bounded)\nif not isinstance(payload, dict) or payload.get(\"errors\"):\n    msgs = [\n        e.get(\"message\", \"\")[:120]\n        for e in (payload.get(\"errors\") or [])[:3]\n        if isinstance(e, dict)\n    ]\n    raise StarHistoryError(\n        \"GitHub GraphQL rejected the stargazer request\"\n        + (f\": {'; '.join(msgs)}\" if msgs else \"\")\n    )","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"from typing import Any\n\ndef is_graphql_success(payload: Any) -> bool:\n    \"\"\"200 + no top-level errors + object body before field access.\"\"\"\n    return isinstance(payload, dict) and not payload.get(\"errors\")","tryCatchPattern":"try:\n    page = gateway.fetch_stargazer_page(after)\nexcept StarHistoryError as exc:\n    if \"rejected the stargazer request\" in str(exc):\n        # GraphQL errors array holds the reason (e.g. invalid cursor);\n        # fetch the raw payload once via `gh api graphql` to read it\n        raise SystemExit(\"GraphQL-level failure; re-run gh manually and read \"\n                         \"the errors[] messages\")\n    raise","preventionTips":["Always inspect payload['errors'] messages — they name the exact field/cursor problem.","Discard stale cursors after schema changes; GraphQL errors on cursors are the first symptom.","Keep the pinned GRAPHQL_QUERY in sync when GitHub's schema evolves; smoke-test it with gh after gh upgrades."],"tags":["graphql","api-contract","pagination","star-history"],"backgroundTag":null,"analyzedSha":"b5b53acc57189a4a42e44a23e149dc655c98fe82","analyzedAt":"2026-08-14T22:29:33.146Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}