Skip to content

Commit

Permalink
fix(schema): Check for undefined value in resolveQueryObjectId resolv…
Browse files Browse the repository at this point in the history
…er (#2914)
  • Loading branch information
philipimperato authored Dec 11, 2022
1 parent d606ac6 commit d9449fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/mongodb/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export async function resolveQueryObjectId(
): Promise<IdQueryObject<ObjectId>>
export async function resolveQueryObjectId(value: ObjectIdParam): Promise<ObjectId>
export async function resolveQueryObjectId(value: ObjectIdParam | IdQueryObject<ObjectIdParam>) {
if (!value) {
return undefined
}

if (typeof value === 'string' || typeof value === 'number' || value instanceof ObjectId) {
return toObjectId(value)
}
Expand Down
8 changes: 8 additions & 0 deletions packages/mongodb/test/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ describe('ObjectId resolvers', () => {
assert.ok(oids.$in && oids.$in[0] instanceof ObjectId)
assert.ok(oids.$ne instanceof ObjectId)
})

it('resolveQueryObjectId with falsey value', async () => {
await resolveQueryObjectId(undefined)
await resolveQueryObjectId(null)
await resolveQueryObjectId(0)

assert.ok('Falsey value does not throw exception')
})
})

0 comments on commit d9449fa

Please sign in to comment.