When querying DynamoDB using Table.getItem() or Table.queryItems(), params.fields are ignored and full objects are returned. When querying using Model.get() or Model.find(), everything works as expected and only the requested fields are returned.
To Reproduce
Full details can be found the test/debug.ts file here. I'll copy/paste an outline of the issue below.
const User = table.getModel('User')
const userProperties = {
name: "Daenerys I Targaryen",
nickName: "Breaker of chains",
email: "iHeartDragons@example.com",
}
const user = await User.create(userProperties)
const userId = user.id!
test('model.get() respects the fields.', async () => {
// Works as expected, only returns id and name.
const user = await User.get({pk: userId}, {fields: ["id", "name"], parse: true})
expect(user).toMatchObject({
name: "Daenerys I Targaryen",
});
expect(user!.id).toMatch(Match.ulid);
expect(user!.nickName).toBeUndefined();
expect(user!.email).toBeUndefined();
})
test('table.getItem() does not respect the fields.', async () => {
// Should break but doesn't because the entire record is returned.
let tableGetItem = await table.getItem({pk: userId}, {fields: ["id", "name"], parse: true})
expect(tableGetItem).toMatchObject(userProperties);
})
Expected behaviorTable.getItem() and Table.queryItems() should respect the params.fields and return only the requested fields.
Environment (please complete the following information):
Describe the bug
When querying DynamoDB using
Table.getItem()
orTable.queryItems()
,params.fields
are ignored and full objects are returned. When querying usingModel.get()
orModel.find()
, everything works as expected and only the requested fields are returned.To Reproduce
Full details can be found the
test/debug.ts
file here. I'll copy/paste an outline of the issue below.Cut/Paste
Schema
Test
Expected behavior
Table.getItem()
andTable.queryItems()
should respect theparams.fields
and return only the requested fields.Environment (please complete the following information):