Commit be636a20 authored by Maxime Orefice's avatar Maxime Orefice Committed by Robert Speicher

Query projects by ids

This commit allows our GraphQL API to query projects by ids.
parent d81fd9e9
...@@ -12,9 +12,13 @@ module Resolvers ...@@ -12,9 +12,13 @@ module Resolvers
required: false, required: false,
description: 'Search query for project name, path, or description' description: 'Search query for project name, path, or description'
argument :ids, [GraphQL::ID_TYPE],
required: false,
description: 'Filter projects by IDs'
def resolve(**args) def resolve(**args)
ProjectsFinder ProjectsFinder
.new(current_user: current_user, params: project_finder_params(args)) .new(current_user: current_user, params: project_finder_params(args), project_ids_relation: parse_gids(args[:ids]))
.execute .execute
end end
...@@ -27,5 +31,9 @@ module Resolvers ...@@ -27,5 +31,9 @@ module Resolvers
search: params[:search] search: params[:search]
}.compact }.compact
end end
def parse_gids(gids)
gids&.map { |gid| GitlabSchema.parse_gid(gid, expected_type: ::Project).model_id }
end
end end
end end
---
title: Query projects by ids with GraphQL
merge_request: 42372
author:
type: added
...@@ -13981,6 +13981,11 @@ type Query { ...@@ -13981,6 +13981,11 @@ type Query {
""" """
first: Int first: Int
"""
Filter projects by IDs
"""
ids: [ID!]
""" """
Returns the last _n_ elements from the list. Returns the last _n_ elements from the list.
""" """
......
...@@ -40936,6 +40936,24 @@ ...@@ -40936,6 +40936,24 @@
}, },
"defaultValue": null "defaultValue": null
}, },
{
"name": "ids",
"description": "Filter projects by IDs",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
}
},
"defaultValue": null
},
{ {
"name": "after", "name": "after",
"description": "Returns the elements in the list that come after the specified cursor.", "description": "Returns the elements in the list that come after the specified cursor.",
...@@ -71,6 +71,14 @@ RSpec.describe Resolvers::ProjectsResolver do ...@@ -71,6 +71,14 @@ RSpec.describe Resolvers::ProjectsResolver do
is_expected.to contain_exactly(project, private_project) is_expected.to contain_exactly(project, private_project)
end end
end end
context 'when ids filter is provided' do
let(:filters) { { ids: [project.to_global_id.to_s] } }
it 'returns matching project' do
is_expected.to contain_exactly(project)
end
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment