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

169
Vistas
How to mutate the state of an array in graphql?

I am trying to add an array inside a GraphQl schema. Currently, it looks like this:

type Play {
  winRatio: [Float]
}

The purpose of the win ratio is to hold the history of all win ratios. For example, after 3 games, the winRatio array should look like this:

winRatio: [1, .5, .66]

Currently, when I mutate the winRatio array, no history is saved; the state updates to the latest value. This is how that looks:

await API.graphql({
  query: updatePlay,
  variables: {
    input: {
      winRatio: [winRatio, (await wins) / (await totalPlays)], // update the player's win ratio
    },
  },
})

However, when I query for the winRatio data in graphql, I get an array with ONLY the latest value:

winRatio:[.66]

I feel like I need the spread operator, but I am not sure why my current solution is not solving my problem.

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

0

Yes, you are correct in that you need the spread operator.

winRatio: [...winRatio, (await wins) / (await totalPlays)]
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