diff --git a/src/gql/ArgumentManager.php b/src/gql/ArgumentManager.php index 7c5e1f7ae61..f4d231c18f6 100644 --- a/src/gql/ArgumentManager.php +++ b/src/gql/ArgumentManager.php @@ -123,12 +123,15 @@ public function prepareArguments(array $arguments): array { $orderBy = $arguments['orderBy'] ?? null; if ($orderBy) { - if (StringHelper::containsAny($orderBy, ['(', ')'])) { - throw new GqlException('Illegal value for `orderBy` argument: `' . $orderBy . '`'); - } - $chunks = StringHelper::split($orderBy); - foreach ($chunks as $chunk) { - if (!preg_match('/^\w+(\.\w+)?( (asc|desc))?$/i', $chunk)) { + foreach (StringHelper::split($orderBy) as $chunk) { + // Special case for `RAND()` + if (strtolower($chunk) === 'rand()') { + continue; + } + if ( + StringHelper::containsAny($orderBy, ['(', ')']) || + !preg_match('/^\w+(\.\w+)?( (asc|desc))?$/i', $chunk) + ) { throw new GqlException('Illegal value for `orderBy` argument: `' . $orderBy . '`'); } }