MCPcopy
hub / github.com/vinta/awesome-python / parse_graphql_response

Function parse_graphql_response

website/fetch_github_stars.py:61–78  ·  view source on GitHub ↗

Parse GraphQL response into {owner/repo: {stars, owner}} dict.

(
    data: dict,
    repos: Sequence[str],
)

Source from the content-addressed store, hash-verified

59
60
61def parse_graphql_response(
62 data: dict,
63 repos: Sequence[str],
64) -> dict[str, dict]:
65 """Parse GraphQL response into {owner/repo: {stars, owner}} dict."""
66 result = {}
67 for i, repo in enumerate(repos):
68 node = data.get(f"repo_{i}")
69 if node is None:
70 continue
71 default_branch = node.get("defaultBranchRef") or {}
72 target = default_branch.get("target") or {}
73 result[repo] = {
74 "stars": node.get("stargazerCount", 0),
75 "owner": node.get("owner", {}).get("login", ""),
76 "last_commit_at": target.get("committedDate", ""),
77 }
78 return result
79
80
81def fetch_batch(repos: Sequence[str], client: httpx.Client) -> dict[str, dict]:

Calls

no outgoing calls