-1

I should get the DynamoDb id for Justin. The call doesn't seem to fail. If i console.log(returned) i get an [object Object]. When i try to get to the returned.data.getIdFromUserName.id or returned.data.getIdFromUserName.email (anything else in the table) i get undefined. What am i missing?

Returned data:

{
  "data": {
    "getIdFromUserName": {
      "items": [
        {
          "id": "3a5a2ks4-f137-41e2-a604-594e0c52a298",
          "userName": "Justin",
          "firstname": "null",
          "weblink": "@JustinTimberlake",
          "email": "iuiubiwewe@hotmail.com",
          "mobileNum": "+0123456789",
          "profilePicURI": "null",
          "listOfVideosSeen": null,
          "userDescription": "I wanna rock your body, please stay",
          "isBlocked": false,
          "GridPairs": null
        }
      ],
      "nextToken": null
    }
  }
}
chai86
  • 425
  • 2
  • 14
  • 34

2 Answers2

0

I'd suggest getting a better idea of what console.log(returned) is printing.

Try console.log(JSON.stringify(returned, null, 2)) to inspect what is being returned.

EDIT: The data you're working with looks like this:

{
  "data": {
    "getIdFromUserName": {
      "items": [
        {
          "id": "3a5a2ks4-f137-41e2-a604-594e0c52a298",
          "userName": "Justin",
          "firstname": "null",
          "weblink": "@JustinTimberlake",
          "email": "iuiubiwewe@hotmail.com",
          "mobileNum": "+0123456789",
          "profilePicURI": "null",
          "listOfVideosSeen": null,
          "userDescription": "I wanna rock your body, please stay",
          "isBlocked": false,
          "GridPairs": null
        }
      ],
      "nextToken": null
    }
  }
}

Pay close attention to the structure of that response. Both data and getIdFromUserName are maps. The content of data.getIdFromUserName is an array named items. Therefore, data.getIdFromUserName.items is an array containing the results of your query. You'll need to iterate over that array to get the data you are looking for.

For example, data.getIdFromUserName.items[0].id would be 3a5a2ks4-f137-41e2-a604-594e0c52a298

Seth Geoghegan
  • 5,372
  • 2
  • 8
  • 23
  • You're right. I AM getting the data packet returned which is a positive. However i don't know how to access the id from it. I've updated the post with what i get back. Please let me know how to access just the id. No combination i'm trying works. – chai86 Aug 18 '20 at 21:32
0

To access the email it would be data.getIdFromUserName.items[0].email.

Robert Kossendey
  • 6,733
  • 2
  • 12
  • 42