Skip to content

Commit fc719f9

Browse files
committed
fix: Detect array syntax for orderBy
While this does not actually fix the problem in #65, it allows the query to fail as `orderBy` is not supported, and to log an error message before the failure. Closes #65.
1 parent 89f8651 commit fc719f9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/encryption.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ function rewriteWritePath(path: string, field: string, hashField: string) {
240240
function isOrderBy(path: string, field: string, value: string) {
241241
const items = path.split('.').reverse()
242242
return (
243-
items[1] === 'orderBy' &&
243+
items.includes('orderBy') &&
244244
items[0] === field &&
245245
['asc', 'desc'].includes(value.toLowerCase())
246246
)

src/tests/integration.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,18 @@ describe('integration', () => {
289289
expect(console.error).toHaveBeenLastCalledWith(
290290
errors.orderByUnsupported('User', 'name')
291291
)
292+
// @ts-ignore
293+
console.error.mockClear()
294+
const testArraySyntax = () =>
295+
client.user.findMany({
296+
orderBy: [{ name: 'asc' }]
297+
})
298+
// Removing the name: asc properties leaves behind an empty
299+
// array with an empty object, which is not supported by Prisma.
300+
expect(testArraySyntax).rejects.toThrow()
301+
expect(console.error).toHaveBeenLastCalledWith(
302+
errors.orderByUnsupported('User', 'name')
303+
)
292304
console.error = cer
293305
})
294306

0 commit comments

Comments
 (0)