Skip to content

Commit 32c8c04

Browse files
authored
Merge pull request #744 from code0-tech/741-add-support-for-username-in-queryuser
Add username to users query
2 parents 4822ebd + d45556b commit 32c8c04

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

app/graphql/types/query_type.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ class QueryType < Types::BaseObject
4141
end
4242

4343
field :user, Types::UserType, null: true, description: 'Find a user' do
44-
argument :id, Types::GlobalIdType[::User], required: true, description: 'GlobalID of the target user'
44+
argument :id, Types::GlobalIdType[::User], required: false, description: 'GlobalID of the target user'
45+
46+
argument :username, GraphQL::Types::String, required: false, description: 'Username of the target user'
47+
48+
require_one_of %i[id username]
4549
end
4650

4751
field :users, Types::UserType.connection_type, null: false, description: 'Find users'
@@ -89,8 +93,12 @@ def namespace(id:)
8993
SagittariusSchema.object_from_id(id)
9094
end
9195

92-
def user(id:)
93-
SagittariusSchema.object_from_id(id)
96+
def user(id: nil, username: nil)
97+
if id.present?
98+
SagittariusSchema.object_from_id(id)
99+
elsif username.present?
100+
User.find_by(username: username)
101+
end
94102
end
95103

96104
def users

docs/graphql/object/query.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,5 @@ Returns [`User`](../object/user.md).
7777

7878
| Name | Type | Description |
7979
|------|------|-------------|
80-
| `id` | [`UserID!`](../scalar/userid.md) | GlobalID of the target user |
80+
| `id` | [`UserID`](../scalar/userid.md) | GlobalID of the target user |
81+
| `username` | [`String`](../scalar/string.md) | Username of the target user |

0 commit comments

Comments
 (0)