Skip to content

perf(client): pass pagination offset and limit as GraphQL variables#1207

Merged
fatih-acar merged 1 commit into
infrahub-developfrom
fac/check-sdk-variables-2h509
Jul 23, 2026
Merged

perf(client): pass pagination offset and limit as GraphQL variables#1207
fatih-acar merged 1 commit into
infrahub-developfrom
fac/check-sdk-variables-2h509

Conversation

@fatih-acar

@fatih-acar fatih-acar commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Paginated queries generated by the SDK (all(), filters(), get(), and resource pool allocation lookups) now pass offset and limit as GraphQL variables instead of inlining them into the query text. The query document stays byte-identical across pages, so repeated pages of the same fetch can hit Infrahub's server-side GraphQL query cache (opsmill/infrahub#8102) — the same optimization the frontend adopted in opsmill/infrahub#8245.

Key Changes

  • client.filters() (async and sync) renders the query once per call with $offset/$limit placeholders and sends the per-page values in the GraphQL variables payload — previously the query was re-generated and re-rendered for every page with literal values baked in.
  • get_pool_allocated_resources() (async and sync) does the same for its pagination loop, extending the $pool_id/$resource_id variables it already used.
  • generate_query_data() / generate_query_data_init() accept variable placeholder strings (e.g. "$offset") for offset and limit; passing literal ints keeps working unchanged.
  • count() needed no change: it takes no pagination arguments, so its query text was already stable per filter set.

Related Context

Documentation Updates

  • Regenerated SDK reference (docs/docs/python-sdk/sdk_ref/infrahub_sdk/node/node.mdx) for the widened signatures.
  • Changelog fragment changelog/+graphql-pagination-variables.changed.md.

Test Plan

  • uv run pytest tests/unit/ — updated the six operation-name assertions to expect the ($offset: Int!, $limit: Int!) signature; added test_method_all_pagination_uses_graphql_variables, which fetches two pages and asserts the query text is identical across pages while only the variables differ ({"offset": 0, "limit": 3}{"offset": 3, "limit": 3}).
  • uv run invoke lint-code (ruff, ty, mypy) passes; uv run invoke docs-generate output is committed.

🤖 Generated with Claude Code


Summary by cubic

SDK paginated queries now send offset and limit as GraphQL variables, keeping the query text identical across pages and enabling server-side cache hits. Queries are rendered once per call, and generate_query_data* now accept variable placeholders.

  • Refactors
    • Use GraphQL variables for offset/limit in all(), filters(), get(), and pool allocation lookups. One rendered document per call; per-page values go in variables.
    • generate_query_data() and generate_query_data_init() accept int or variable placeholders (e.g. "$offset", "$limit"). Backward compatible.
    • count() unchanged.

Written for commit ac9e0f7. Summary will update on new commits.

Review in cubic

@fatih-acar fatih-acar added the type/task Body of work related to an epic label Jul 23, 2026
@github-actions github-actions Bot added the type/documentation Improvements or additions to documentation label Jul 23, 2026
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                 Coverage Diff                  @@
##           infrahub-develop    #1207      +/-   ##
====================================================
- Coverage             83.98%   83.17%   -0.81%     
====================================================
  Files                   139      139              
  Lines                 14390    12441    -1949     
  Branches               2381     1852     -529     
====================================================
- Hits                  12085    10348    -1737     
+ Misses                 1654     1528     -126     
+ Partials                651      565      -86     
Flag Coverage Δ
integration-tests 40.30% <60.00%> (-2.38%) ⬇️
python-3.10 56.94% <100.00%> (-1.71%) ⬇️
python-3.11 56.93% <100.00%> (-1.72%) ⬇️
python-3.12 56.94% <100.00%> (-1.69%) ⬇️
python-3.13 56.94% <100.00%> (-1.71%) ⬇️
python-3.14 56.94% <100.00%> (-1.71%) ⬇️
python-filler-3.12 22.50% <0.00%> (-0.22%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/client.py 79.62% <100.00%> (-1.28%) ⬇️
infrahub_sdk/node/node.py 87.40% <100.00%> (-1.27%) ⬇️

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Re-trigger cubic

@dgarros dgarros left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, ideally I think we should target infrahub-develop directly because there are a lot of changes in this branch right now compared to develop

Queries generated by all()/filters()/get() and the resource pool
allocation lookup previously inlined offset and limit into the query
text, so every page of a paginated fetch produced a different GraphQL
document and could never hit the server-side query cache. Pagination now
travels as $offset/$limit variables: the document stays identical across
pages, and the query is rendered once per call instead of once per page.

generate_query_data() and generate_query_data_init() accept variable
placeholder strings (e.g. "$offset") for offset and limit, matching the
existing $pool_id convention.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@fatih-acar
fatih-acar force-pushed the fac/check-sdk-variables-2h509 branch from d9f39fd to ac9e0f7 Compare July 23, 2026 10:31
@fatih-acar
fatih-acar changed the base branch from develop to infrahub-develop July 23, 2026 10:31
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 23, 2026

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: ac9e0f7
Status: ✅  Deploy successful!
Preview URL: https://86441eb7.infrahub-sdk-python.pages.dev
Branch Preview URL: https://fac-check-sdk-variables-2h50.infrahub-sdk-python.pages.dev

View logs

@fatih-acar
fatih-acar marked this pull request as ready for review July 23, 2026 11:11
@fatih-acar
fatih-acar requested a review from a team as a code owner July 23, 2026 11:11
@fatih-acar
fatih-acar merged commit 6722e43 into infrahub-develop Jul 23, 2026
22 of 34 checks passed
@fatih-acar
fatih-acar deleted the fac/check-sdk-variables-2h509 branch July 23, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/documentation Improvements or additions to documentation type/task Body of work related to an epic

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants