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 versions for one item per request (FieldCallCount, limit 1). A second call in the same request returns null for that field and an error.
  • Caps a versions page at 20 (max_page_size: 20). The largest request now returns 20 versions.
  • Removes the versions preloads from ItemsResolver and CustomAndFoundationalItemsResolver. They loaded every version of every item. With the call limit, a list resolves versions for 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 group aiCatalogItems fields. The versions field and the AiCatalogItem interface 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 versions on more than one item, or more than once in a request (aliases included), gets versions: null after 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 versions on a catalog item. Callers outside this repository were not checked.
  • In 7 days of production logs, the only caller selecting versions on 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 versions its 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

Screenshots or screen recordings

Not applicable. This is an API-only change.

How to set up and validate locally

  1. Make sure the AI Catalog is enabled and you have at least two public catalog items.

  2. 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.

  3. Run the same check on a list:

    { aiCatalogItems { nodes { id versions { nodes { id } } } } }
  4. 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.

Edited by Jafar Soltani

Merge request reports

Loading
Loading