Skip to content

Commit 76c8e69

Browse files
authored
Merge pull request #768 from code0-tech/760-make-queryuserusername-case-insensitive
Make users query by username case insensitive
2 parents 4c70194 + f7ca1fa commit 76c8e69

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

app/graphql/types/query_type.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class QueryType < Types::BaseObject
4343
field :user, Types::UserType, null: true, description: 'Find a user' do
4444
argument :id, Types::GlobalIdType[::User], required: false, description: 'GlobalID of the target user'
4545

46-
argument :username, GraphQL::Types::String, required: false, description: 'Username of the target user'
46+
argument :username, GraphQL::Types::String, required: false,
47+
description: 'Username of the target user (case insensitive)'
4748

4849
require_one_of %i[id username]
4950
end
@@ -88,7 +89,7 @@ def user(id: nil, username: nil)
8889
if id.present?
8990
SagittariusSchema.object_from_id(id)
9091
elsif username.present?
91-
User.find_by(username: username)
92+
User.find_by('LOWER(username) = ?', username.downcase)
9293
end
9394
end
9495

docs/graphql/object/query.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ Returns [`User`](../object/user.md).
7777
| Name | Type | Description |
7878
|------|------|-------------|
7979
| `id` | [`UserID`](../scalar/userid.md) | GlobalID of the target user |
80-
| `username` | [`String`](../scalar/string.md) | Username of the target user |
80+
| `username` | [`String`](../scalar/string.md) | Username of the target user (case insensitive) |

0 commit comments

Comments
 (0)