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))
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.