简体   繁体   中英

How do i get my table's row information without an 'id'?

I've successfully been able to add new entries and update information using AppSync. However, I'm totally stumped when it comes to 'Get' information.

So for example if i try:

await API.graphql(graphqlOperation(getVideo, { id: ???? }))

I have no idea what my 'id' is. Obviously once the entry is created a unique id is created, but I have no way of knowing that unless going to my AWS console.

Or how can I get this id as a response when I create the entry?

I have created my own (as it were in dynamodb, SortKey) called 'myId' in creating the entry which I know. I need to use this 'myId' to retrieve the information in my table. How do I go about using this to get my table entry information?

I believe you should still use the real id rather than the myId to get info about a newly created item.

You can easily get real id without needing to visit aws console by using createVideo graphql operation.

const createdVideo = await API.graphql(graphqlOperation(mutations.createVideo));
const videoId = createdVideo.data.createVideo.id;

Also, listVideos graphql operation can list all ids.

const allVideos = await API.graphql(graphqlOperation(queries.listVideos));
const videoIds = allVideos.data.listVideos.items.map(video => video.id);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM