fix: enforce NonNegativeInt on GraphQL pagination arguments
Summary
Adds a NonNegativeInt GraphQL scalar and applies it to the pagination arguments (limit, offset, log_limit, log_offset) of the specialized top-level queries: branch, event, task, search, relationship, account-token, resource-manager and diff-tree. Negative or non-integer pagination values on these queries are now rejected at the schema level with an error that names the offending argument and its location.
The scalar lives in backend/infrahub/graphql/scalars.py (next to FixedGenericScalar).
This supersedes #7610 (originally opened from a personal fork before I joined OpsMill), rebased onto current develop and reworked per the review there.
Context / scope
#7474 (late errors for negative offset/limit) was already fixed and released in v1.9.5 by #9203, which added a resolver-level validate_offset_and_limit() guard in default_paginated_list_resolver — the resolver used by the generic node list queries. That guard covers generic node pagination but not the specialized query resolvers.
This PR closes that gap by validating declaratively at the schema level on exactly those specialized queries. The generic node filters are intentionally left as Int — they are already validated by #9203, and switching them to NonNegativeInt would be a breaking change for every client (frontend, SDK, internal node-id fetch queries) that paginates a node with an Int variable.
Review feedback addressed (from #7610)
- @ogenstad: raise
ValidationErrorrather thanGraphQLErrorso the response keeps the argument type name and source location. The scalar raisesinfrahub.exceptions.ValidationError, which graphql-core wraps asExpected value of type 'NonNegativeInt', found -1; Value must be a non-negative integerwithlocationspopulated. - Docstrings + type hints on the scalar;
ValueError/TypeErrorhandled.
Notable fixes beyond the original PR
parse_literalaccepts thevariablesargument the executor passes, so a paginated query that also declares query variables is coerced correctly instead of failing argument validation (the original raised a spuriousinvalid value).parse_valuevalidates strictly: booleans, strings and fractional floats are rejected (whole-number floats accepted, matching the built-inInt), so variable inputs enforce the same integer contract as inline literals.
Changes
- New
NonNegativeIntinbackend/infrahub/graphql/scalars.py, with unit tests inbackend/tests/unit/graphql/types/test_scalars.py. Int()→NonNegativeInt()on the pagination args of the eight specialized query modules.- Regenerated
schema/schema.graphql(scalar + the eight fields) and the frontend generated GraphQL files; updated the frontend query documents for the specialized queries and mappedNonNegativeInt→numberin gql.tada / graphql-codegen. - Component tests for the specialized queries; the branch resolver's now-redundant negative-offset check was removed (the scalar guarantees it).
Test plan
uv run invoke format/lint,mypy— clean.- Backend unit + affected component tests pass locally against a Neo4j testcontainer; CI green.
- Frontend
codegen+betterer/biome/knipall pass.
Closes #7610.