Skip to content

Commit d9449fa

Browse files
fix(schema): Check for undefined value in resolveQueryObjectId resolver (#2914)
1 parent d606ac6 commit d9449fa

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/mongodb/src/resolvers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export async function resolveQueryObjectId(
1919
): Promise<IdQueryObject<ObjectId>>
2020
export async function resolveQueryObjectId(value: ObjectIdParam): Promise<ObjectId>
2121
export async function resolveQueryObjectId(value: ObjectIdParam | IdQueryObject<ObjectIdParam>) {
22+
if (!value) {
23+
return undefined
24+
}
25+
2226
if (typeof value === 'string' || typeof value === 'number' || value instanceof ObjectId) {
2327
return toObjectId(value)
2428
}

packages/mongodb/test/resolvers.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ describe('ObjectId resolvers', () => {
2424
assert.ok(oids.$in && oids.$in[0] instanceof ObjectId)
2525
assert.ok(oids.$ne instanceof ObjectId)
2626
})
27+
28+
it('resolveQueryObjectId with falsey value', async () => {
29+
await resolveQueryObjectId(undefined)
30+
await resolveQueryObjectId(null)
31+
await resolveQueryObjectId(0)
32+
33+
assert.ok('Falsey value does not throw exception')
34+
})
2735
})

0 commit comments

Comments
 (0)