Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!