Skip to content

Commit 435bb89

Browse files
marcleblanc2Amp
andauthored
Release v0.1.6 (#20)
## Summary - expose SourcegraphClient.graphql pagination controls for callers that need to own cursor handling - add coverage for disabling automatic GraphQL pagination - bump src-py-lib package metadata to 0.1.6 ## Validation - uv lock --check - actionlint - npx --yes markdownlint-cli2@0.22.1 - uv run ruff check . - uv run ruff format --check . - uv run pyright - uv run python -m unittest discover -s tests - uv build --wheel --sdist --out-dir /tmp/src-py-lib-release-check --no-create-gitignore Co-authored-by: Amp <amp@ampcode.com>
1 parent ba6a20f commit 435bb89

5 files changed

Lines changed: 59 additions & 9 deletions

File tree

AGENTS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ uv run python -m unittest discover -s tests
6464
```sh
6565
set -euo pipefail
6666

67-
VERSION=0.1.4
67+
VERSION=0.1.6
6868
BRANCH="release-v${VERSION}"
6969

7070
git fetch origin --tags --prune
@@ -116,7 +116,7 @@ rm -rf /tmp/src-py-lib-release-check
116116
```sh
117117
set -euo pipefail
118118

119-
VERSION=0.1.4
119+
VERSION=0.1.6
120120
BRANCH="release-v${VERSION}"
121121
GH_REPO="sourcegraph/src-py-lib"
122122

@@ -140,7 +140,7 @@ gh pr merge "${BRANCH}" --repo "${GH_REPO}" --squash --delete-branch
140140
```sh
141141
set -euo pipefail
142142

143-
VERSION=0.1.4
143+
VERSION=0.1.6
144144

145145
git fetch origin --tags --prune
146146
git switch main
@@ -154,7 +154,7 @@ git push origin "v${VERSION}"
154154
```sh
155155
set -euo pipefail
156156

157-
VERSION=0.1.4
157+
VERSION=0.1.6
158158
GH_REPO="sourcegraph/src-py-lib"
159159

160160
RUN_ID="$(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dev = [
1010

1111
[project]
1212
name = "src-py-lib"
13-
version = "0.1.5"
13+
version = "0.1.6"
1414
description = "Reusable libraries for Sourcegraph projects"
1515
readme = "README.md"
1616
requires-python = ">=3.11"

src/src_py_lib/clients/sourcegraph.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,29 @@ def __post_init__(self) -> None:
206206
require_https=not self.allow_insecure_http,
207207
)
208208

209-
def graphql(self, query: str, variables: Mapping[str, JSONValue] | None = None) -> JSONDict:
210-
return self._client().execute(query, variables)
209+
def graphql(
210+
self,
211+
query: str,
212+
variables: Mapping[str, JSONValue] | None = None,
213+
*,
214+
follow_pages: bool = True,
215+
page_size: int | None = None,
216+
first_variable: str = "first",
217+
after_variable: str = "after",
218+
) -> JSONDict:
219+
"""Execute one Sourcegraph GraphQL operation.
220+
221+
Set `follow_pages=False` when the caller owns pagination, such as
222+
aliased queries with one cursor per alias.
223+
"""
224+
return self._client().execute(
225+
query,
226+
variables,
227+
follow_pages=follow_pages,
228+
page_size=page_size,
229+
first_variable=first_variable,
230+
after_variable=after_variable,
231+
)
211232

212233
def stream_connection_nodes(
213234
self,

tests/test_logging_http_clients.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,35 @@ def test_sourcegraph_client_builds_graphql_request(self) -> None:
14241424
self.assertEqual(http.calls[0]["url"], "https://sourcegraph.example.com/.api/graphql")
14251425
self.assertEqual(http.calls[0]["headers"], {"Authorization": "token token"})
14261426

1427+
def test_sourcegraph_client_graphql_can_disable_auto_pagination(self) -> None:
1428+
http = RecordingHTTP(
1429+
[
1430+
{
1431+
"data": {
1432+
"users": {
1433+
"nodes": [{"username": "alice"}],
1434+
"pageInfo": {"hasNextPage": True, "endCursor": "cursor-1"},
1435+
}
1436+
}
1437+
}
1438+
]
1439+
)
1440+
client = SourcegraphClient("https://sourcegraph.example.com", "token", http=http)
1441+
query = """
1442+
query Users($first: Int!, $after: String) {
1443+
users(first: $first, after: $after) {
1444+
nodes { username }
1445+
pageInfo { hasNextPage endCursor }
1446+
}
1447+
}
1448+
"""
1449+
1450+
data = client.graphql(query, page_size=1, follow_pages=False)
1451+
1452+
self.assertEqual(json_dict(data.get("users"))["nodes"], [{"username": "alice"}])
1453+
self.assertEqual(len(http.calls), 1)
1454+
self.assertEqual(http.calls[0]["json_body"]["variables"], {"first": 1})
1455+
14271456
def test_sourcegraph_client_rejects_http_endpoint_by_default(self) -> None:
14281457
with self.assertRaisesRegex(ValueError, "https:// URL"):
14291458
SourcegraphClient("http://sourcegraph.example.com", "token")
@@ -1536,7 +1565,7 @@ def handler(request: httpx.Request) -> httpx.Response:
15361565

15371566
with src.trace_context(root_context):
15381567
self.assertEqual(
1539-
client.graphql("query Viewer { currentUser { username } }"),
1568+
client.graphql("query Viewer { currentUser { username } }", follow_pages=False),
15401569
{"currentUser": {"username": "alice"}},
15411570
)
15421571
traces = client.drain_traces()

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)