Skip to content

Commit f7ca1fa

Browse files
committed
Make users query by username case insensitive
1 parent 16d8abe commit f7ca1fa

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
@@ -97,7 +98,7 @@ def user(id: nil, username: nil)
9798
if id.present?
9899
SagittariusSchema.object_from_id(id)
99100
elsif username.present?
100-
User.find_by(username: username)
101+
User.find_by('LOWER(username) = ?', username.downcase)
101102
end
102103
end
103104

docs/graphql/object/query.md

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

0 commit comments

Comments
 (0)