'Graphql is returning the promise and not my DynamoDB data
I am using a Graphql API to access my DynamoDB database. I am then trying to render the list of users in my app. According to the docs I should use:
import * as queries from './graphql/queries';
const users = await API.graphql({ query: queries.listUsers });
console.log(users);
However, I get an error regarding the await. So I removed the await key word, but const users = API.graphql({ query: queries.listUsers });
returns the promise. This is the response:
Promise {
"_U": 0,
"_V": 0,
"_W": null,
"_X": null,
}
I put my code into an async function and used the await keyword and still only got the promise. Is there a way to simply call the query and without the await and get the correct data instead of the promise? I have also been trying to use the GraphQLResult to get the actual result, but that isn't working, I am either getting errors or I am still getting the promise.
Solution 1:[1]
using try catch
block to handle error of the await
await return the promise result but after remove the await, it just return the promise, you should use then catch
to get the result
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bulog |