Skip to content
Snippets Groups Projects
Commit be636a20 authored by Maxime Orefice's avatar Maxime Orefice Committed by Robert Speicher
Browse files

Query projects by ids

This commit allows our GraphQL API to query projects by ids.
parent d81fd9e9
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -12,9 +12,13 @@ module Resolvers
required: false,
description: 'Search query for project name, path, or description'
 
argument :ids, [GraphQL::ID_TYPE],
required: false,
description: 'Filter projects by IDs'
def resolve(**args)
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
end
 
Loading
Loading
@@ -27,5 +31,9 @@ module Resolvers
search: params[:search]
}.compact
end
def parse_gids(gids)
gids&.map { |gid| GitlabSchema.parse_gid(gid, expected_type: ::Project).model_id }
end
end
end
---
title: Query projects by ids with GraphQL
merge_request: 42372
author:
type: added
Loading
Loading
@@ -13981,6 +13981,11 @@ type Query {
"""
first: Int
 
"""
Filter projects by IDs
"""
ids: [ID!]
"""
Returns the last _n_ elements from the list.
"""
Loading
Loading
Loading
Loading
@@ -40936,6 +40936,24 @@
},
"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",
"description": "Returns the elements in the list that come after the specified cursor.",
Loading
Loading
@@ -71,6 +71,14 @@ RSpec.describe Resolvers::ProjectsResolver do
is_expected.to contain_exactly(project, private_project)
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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment