Limit AI Catalog item versions to one item per request
What does this MR do and why?
The versions field on AI Catalog items had no call limit and no page size cap. One signed-out request could select versions on every item in a list, or nest it through a version's item, and load the same version rows thousands of times. The query cost 18 against a complexity limit of 200, so nothing stopped it.
This MR:
- Resolves
versionsfor one item per request (FieldCallCount, limit 1). A second call in the same request returnsnullfor that field and an error. - Caps a
versionspage at 20 (max_page_size: 20). The largest request now returns 20 versions. - Removes the
versionspreloads fromItemsResolverandCustomAndFoundationalItemsResolver. They loaded every version of every item. With the call limit, a list resolvesversionsfor one item at most.
Lists can use latestVersion instead of versions.
This is a breaking change
The GraphQL style guide lists a smaller page size, and a new limit that rejects a query that used to work, as breaking changes. This MR makes both without a deprecation period. I'd like a GraphQL reviewer to confirm that is acceptable, on these grounds:
- Every query field I checked that returns a catalog item is an experiment:
aiCatalogItem,aiCatalogItems,aiCatalogCustomAndFoundationalItems,aiCatalogItemVersions,aiCatalogConfiguredItems, and the project and groupaiCatalogItemsfields. Theversionsfield and theAiCatalogIteminterface are not marked as experiments themselves. - The API docs allow an immediate breaking change for a critical performance concern. Signed-out users can run this query.
What callers will see:
- A query that selects
versionson more than one item, or more than once in a request (aliases included), getsversions: nullafter the first call, plus an error. - A caller that reads one item's versions without paginating gets 20 instead of up to 100. In production 25 public items have more than 20 versions.
- No frontend query or backend GraphQL call in this repository selects
versionson a catalog item. Callers outside this repository were not checked. - In 7 days of production logs, the only caller selecting
versionson a list was one Node.js script paging through the catalog. It has not been identified, and it will start getting errors.
Not in this MR
- Giving
versionsits own resolver, so its complexity grows with page size. That is a follow-up. - Both resolvers still include
LooksAhead, which now preloads nothing. I left it to keep the fix small, and can remove it here if reviewers prefer.
References
- https://gitlab.com/gitlab-org/gitlab/-/work_items/635152
- Project Bulkhead: https://gitlab.com/groups/gitlab-org/-/epics/24147
Screenshots or screen recordings
Not applicable. This is an API-only change.
How to set up and validate locally
-
Make sure the AI Catalog is enabled and you have at least two public catalog items.
-
Sign out, open
http://gdk.test:3000/-/graphql-explorer, and run the query from the issue:{ aiCatalogItemVersions { nodes { item { versions { nodes { id } } } } } }One item returns its versions. The others return
versions: null, with the error"versions" field can be requested only for 1 AiCatalogItem(s) at a time. -
Run the same check on a list:
{ aiCatalogItems { nodes { id versions { nodes { id } } } } } -
Check that a single item still works, and that a page stops at 20. Replace the ID with one of your items:
{ aiCatalogItem(id: "gid://gitlab/Ai::Catalog::Item/1") { versions(first: 100) { nodes { id } pageInfo { hasNextPage endCursor } } } }
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.