Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
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?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

await can be used only with in an async context, so ideally what you would have to do is the following

const allTodos = async () => {
   const todos = await API.graphql({ query: queries.listTodos }); 
   return todos
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda