'Using the Amplify Graphql Client in Javascript to Query Data
On the API(GraphQL) - Getting Started documentation here, it says to query your data using the following:
import { API } from 'aws-amplify';
import * as queries from './graphql/queries';
// Simple query
const allTodos = await API.graphql({ query: queries.listTodos });
console.log(allTodos); // result: { "data": { "listTodos": { "items": [/* ..... */] } } }
However, when I try to apply their code to my javascript code it says that it does not recognize the word await. Online it says I can only use the await keyword inside of a async function. When I take the await keyword out, the promise from the query function does not get settled so it returns the promise first before the data.
I tried setting up an async function before, and posted a stackoverflow post about it. The solution got a little messy, and did not quite work for me. So, I am wondering what is the best way to go about querying data using Graphql? And how do I implement that?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
