Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
bb7392b4
Commit
bb7392b4
authored
Oct 30, 2020
by
Mario de la Ossa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GraphQL: Add search param to Users resolver
Allows users to pass `search` to search by username and name.
parent
f17d1cc4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
5 deletions
+38
-5
app/graphql/resolvers/users_resolver.rb
app/graphql/resolvers/users_resolver.rb
+8
-3
changelogs/unreleased/273801-graphql-fuzzy-search-users.yml
changelogs/unreleased/273801-graphql-fuzzy-search-users.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+5
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+10
-0
spec/graphql/resolvers/users_resolver_spec.rb
spec/graphql/resolvers/users_resolver_spec.rb
+10
-2
No files found.
app/graphql/resolvers/users_resolver.rb
View file @
bb7392b4
...
...
@@ -18,10 +18,14 @@ module Resolvers
required:
false
,
default_value:
'created_desc'
def
resolve
(
ids:
nil
,
usernames:
nil
,
sort:
nil
)
argument
:search
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
"Query to search users by name, username, or primary email."
def
resolve
(
ids:
nil
,
usernames:
nil
,
sort:
nil
,
search:
nil
)
authorize!
::
UsersFinder
.
new
(
context
[
:current_user
],
finder_params
(
ids
,
usernames
,
sort
)).
execute
::
UsersFinder
.
new
(
context
[
:current_user
],
finder_params
(
ids
,
usernames
,
sort
,
search
)).
execute
end
def
ready?
(
**
args
)
...
...
@@ -42,11 +46,12 @@ module Resolvers
private
def
finder_params
(
ids
,
usernames
,
sort
)
def
finder_params
(
ids
,
usernames
,
sort
,
search
)
params
=
{}
params
[
:sort
]
=
sort
if
sort
params
[
:username
]
=
usernames
if
usernames
params
[
:id
]
=
parse_gids
(
ids
)
if
ids
params
[
:search
]
=
search
if
search
params
end
...
...
changelogs/unreleased/273801-graphql-fuzzy-search-users.yml
0 → 100644
View file @
bb7392b4
---
title
:
Add search param to Users GraphQL type
merge_request
:
46609
author
:
type
:
added
doc/api/graphql/reference/gitlab_schema.graphql
View file @
bb7392b4
...
...
@@ -16708,6 +16708,11 @@ type Query {
"""
last
:
Int
"""
Query
to
search
users
by
name
,
username
,
or
primary
email
.
"""
search
:
String
"""
Sort
users
by
this
criteria
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
bb7392b4
...
...
@@ -48368,6 +48368,16 @@
},
"defaultValue": "created_desc"
},
{
"name": "search",
"description": "Query to search users by name, username, or primary email.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
spec/graphql/resolvers/users_resolver_spec.rb
View file @
bb7392b4
...
...
@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec
.
describe
Resolvers
::
UsersResolver
do
include
GraphqlHelpers
let_it_be
(
:user1
)
{
create
(
:user
)
}
let_it_be
(
:user2
)
{
create
(
:user
)
}
let_it_be
(
:user1
)
{
create
(
:user
,
name:
"SomePerson"
)
}
let_it_be
(
:user2
)
{
create
(
:user
,
username:
"someone123784"
)
}
describe
'#resolve'
do
it
'raises an error when read_users_list is not authorized'
do
...
...
@@ -43,6 +43,14 @@ RSpec.describe Resolvers::UsersResolver do
).
to
contain_exactly
(
user1
,
user2
)
end
end
context
'when a search term is passed'
do
it
'returns all users who match'
,
:aggregate_failures
do
expect
(
resolve_users
(
search:
"some"
)).
to
contain_exactly
(
user1
,
user2
)
expect
(
resolve_users
(
search:
"123784"
)).
to
contain_exactly
(
user2
)
expect
(
resolve_users
(
search:
"someperson"
)).
to
contain_exactly
(
user1
)
end
end
end
def
resolve_users
(
args
=
{})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment