Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda