dynamodb-toolbox icon indicating copy to clipboard operation
dynamodb-toolbox copied to clipboard

Cannot read property 'type' of undefined

Open jmadan opened this issue 2 years ago • 1 comments

Hello,

When querying table with partitionKey and sortKey, I keep getting the following error

TypeError: Cannot read property 'type' of undefined
    at /node_modules/dynamodb-toolbox/dist/lib/validateTypes.js:17:21
    at Table.queryParams (/node_modules/dynamodb-toolbox/dist/classes/Table.js:418:52)
    at Table.<anonymous> (/node_modules/dynamodb-toolbox/dist/classes/Table.js:254:75)
    at Generator.next (<anonymous>)
    at /node_modules/dynamodb-toolbox/dist/classes/Table.js:13:71
    at new Promise (<anonymous>)
    at __awaiter (/node_modules/dynamodb-toolbox/dist/classes/Table.js:9:12)
    at Table.query (/node_modules/dynamodb-toolbox/dist/classes/Table.js:252:16)
    at DynamoDbService.getIdentity (/src/dynamodb/dynamodb.service.ts:50:54)
    at IdentityService.getIdentity (/src/identity/identity.service.ts:10:48)

My table definition is as follows

myTable = new Table({
        // Specify table name (used by DynamoDB)
        name: this.configService.get('DB_TABLE_NAME'),

        // Define partition and sort keys
        partitionKey: 'pk',
        sortKey: 'sk',

        // Add the DocumentClient
        DocumentClient: client,
      });
DynamoHelper.UserEntity = new Entity<TUser>({
        name: 'User',
        attributes: {
          pk: { partitionKey: true },
          sk: { sortKey: true },
          firstName: { alias: 'first_name' },
          lastName: { alias: 'last_name' },
          id: { type: 'string' },
        },
        table: myTable,
      });

and query

const { Items } = await myTable.query(
        pk,
        {
           eq: sk,
         },
      );

The above code throws TypeError but I am not able to figure out what is causing Type Error. Any help is appreciated.

jmadan avatar Mar 01 '22 13:03 jmadan

From a quick look, it seems the type of sk cannot be found (because sk is undefined). Without having other insights in your code, my assumption is that when passing sk to the query below, for some reason you are passing undefined and not a string.

salv0 avatar Mar 04 '22 11:03 salv0

Hey, thanks for opening this issue.

I'll be closing it for now because it doesn't seem like an issue in the library itself.

Let me know if you have any further questions.

naorpeled avatar Aug 17 '22 14:08 naorpeled