Add latestVersion field to GraphQL AiCatalogItems
What does this MR do and why?
This MR returns the latest version of an AI item through the latestVersion field.
How to set up and validate locally
Enable the :global_ai_catalog feature flag:
First, create an agent if you don't have one already:
mutation {
aiCatalogAgentCreate(input: {
name: "Pirate"
description: "A pirate doing a sum"
projectId: "gid://gitlab/Project/1000000"
systemPrompt: "You are a pirate!"
userPrompt: "What is 2 + 2?"
}) {
errors
item {
id
}
}
}
Now, create 2 versions for that agent on the Rails console:
item = Ai::Catalog::Item.last
FactoryBot.create(:ai_catalog_item_version, version: '2.0.0', item: item)
FactoryBot.create(:ai_catalog_item_version, version: '2.1.0', item: item)
Now, query for the latestVersion of the agent that you created, the versionName property should be "2.1.0":
Replace <ID> in the query brlow with the id of the item.
{
aiCatalogItem(id: "gid://gitlab/Ai::Catalog::Item/<ID>") {
id
name
description
latestVersion {
id
versionName
createdAt
updatedAt
publishedAt
...on AiCatalogAgentVersion {
userPrompt
systemPrompt
}
}
}
}
Example response:
{
"data": {
"aiCatalogItem": {
"id": "gid://gitlab/Ai::Catalog::Item/6",
"name": "Pirate",
"description": "A pirate doing a sum",
"latestVersion": {
"id": "gid://gitlab/Ai::Catalog::ItemVersion/5",
"versionName": "2.1.0",
"createdAt": "2025-07-09T03:08:23Z",
"updatedAt": "2025-07-09T03:08:23Z",
"publishedAt": "2025-07-09T03:08:23Z",
"userPrompt": "What is 2 + 2?",
"systemPrompt": "You are a pirate!"
}
}
},
"correlationId": "01JZPN48PQRK2SCPSQXJBMXMQ6"
}
Verify latest_field loads without N+1, by
- Ensuring you have created multiple agents
- And that the agents have multiple versions
Tail the logs tail -f log/development.log, and executing a query to return many items:
{
aiCatalogItems {
nodes {
latestVersion {
id
}
}
}
}
The logs should show the version records are queried with one request.
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.