Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination to pull records on all DAOs #48

Open
clemp opened this issue Aug 25, 2021 · 1 comment
Open

Pagination to pull records on all DAOs #48

clemp opened this issue Aug 25, 2021 · 1 comment

Comments

@clemp
Copy link

clemp commented Aug 25, 2021

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
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants