HausDAO / daohaus-supergraph

MIT License
6 stars 22 forks source link

Pagination to pull records on all DAOs #48

Open clemp opened 3 years ago

clemp commented 3 years ago

I'm using the Daohaus Xdai API (https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-xdai) to create a dataset of DAOs. What I want to know is how to deal with pagination and get all records?

import json
import requests

def run_query():
    q = """
        {
            moloches { 
                id
                totalShares
                totalLoot
            }
        }
        """
    # The Graph DAOhaus xDAI endpoint
    response = requests.post(
        'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-xdai',
        '',
        json={"query": q}
        )

    if response.status_code == 200:
        result = response.text
        daos = []
        # put each moloch record into a list
        for dao in json.loads(result)['data']['moloches']:
            data = dict()
            data["dao_hash"] = dao["id"]
            daos.append(dao)
        # return count of moloch records added to list
        return print(len(daos))
    else:
        raise Exception("Query failed. Return code is {}.   {}".format(response.status_code, q))

if __name__ == "__main__":
    run_query()

This short example returns 100 records. There are far more DAOs than that on the xDAI network I assume if correct - how does the API handle pagination?

daviddavo commented 2 years ago

I don't know if you still have this problem, but there is a guide in TheGraph API

You can find more info on this issue: grasia/dao-analyzer#39

You can find a working example in this file, or searching more through that project files

Hope this helps!