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

252
Vistas
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 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