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

260
Visualizações
How do you apply an external GraphQL schema to a JavaScript response object?

Given this GraphQL schema, when I get the response using the GraphQL-Request client, how to I apply it so I can access so response data is cast to a selected object within the schema?

async function main() {

  const graphQLClient = new GraphQLClient(endpoint, {
    headers: {
      authorization: '',
    },
  })
  
  const query = gql`
    {
        pools(first:2, orderBy: txCount, orderDirection: desc) {
        token0{
          name,
          symbol,
          volumeUSD,
          totalSupply
        }
        token1{
          name,
          symbol,
          volumeUSD,
          totalSupply
        }
        token0Price,
        token1Price,
        txCount
      }
    }
  `

  const data = await request(endpoint, query)
  console.log(JSON.stringify(data, undefined, 2))

  // var json = JSON.parse(data);  // SyntaxError: Unexpected token o in JSON at position 1

  console.log(data.pools.length);
  
  
}

main().catch((error) => console.error(error))

enter image description here

Pool type is defined in the schema:

type Pool @entity {
  # pool address
  id: ID!
  # creation
  createdAtTimestamp: BigInt!
  # block pool was created at
  createdAtBlockNumber: BigInt!
  # token0
...

Response data contains an array of pools I would like to iterate through the array, filter for some value, i.e. poolList[x].token0.name.contains='xxxx'", cast as an object of type pool and store in a separate array.

I'm also open to using a different, recommended GraphQL query tool.

about 4 years ago · Juan Pablo Isaza
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