• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

152
Vistas
Cannot access object from GraphQL query (JavaScript)

Subgraph query returns results to console, but my javascript module can't access any values from it, returning an error:

TypeError: Cannot read properties of undefined (reading 'symbol')

According to everything I read online, this is how to access object properties.

quni.mjs:

import axios from 'axios'
export async function quni() {
  const uniData = async () => {
    var result;
    try{
      result = await axios.post(
        'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-polygon',
        {   
          query:`
          {
            pools(
              first: 2,
            where: {
              liquidity_gt: 100
            }
          )
            {
              id
              token1{symbol}
              token0{symbol}
            }
          } 
          `
        }    
      );
    } catch(error){
      console.error(error);
    }
    const unipairs = result.data.data.pools;
    //console.log(unipairs);
    return result.data.data.pools;
  }
  return uniData();
}
quni();

quniparse.mjs:

    import { quni } from './quni.mjs';
    async function unicheck() {
    var uni = await quni();
    var unitoken0 = uni.token0.symbol;
    var unitoken1 = uni.token1.symbol;
    var ticker = toString([unitoken0+"/"+unitoken1]);
    console.log(ticker)
    };
    unicheck();

Solutions I've tried:

JSON.stringify(unipairs) to try accessing using JSON objects in quniparse.mjs, but that yields identical results.

fs.writeFile('./unipairs', JSON.stringify(unipairs), null, 2) to see if accessing properties from .json file might help.

All yield identical results (cannot read 'symbol').

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

0

Turns out I just needed a loop, ex.;

uni.forEach(unipair => {
    console.log(unipair);
about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda