-
Notifications
You must be signed in to change notification settings - Fork 8
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
Not clear why JSON response receives an auto-generated key #51
Comments
I can see how this might be a bit confusing. While this key seems a bit random, there is actually some purpose for this key (it's also not generated randomly). A Subgrounds query is a bit more than the exact GraphQL it is replicating, it actually injects a bit of extra stuff to the query to help us sort through the response when organizing the output required by the main querying function For example: >>> url = "https://api.thegraph.com/subgraphs/name/protofire/omen-xdai"
>>> with Subgrounds() as sg:
... subgraph = sg.load_subgraph(url)
... field = subgraph.Query.fixedProductMarketMakers(
... first=2,
... where={"outcomes": ["Yes", "No"]} # using relative form
... )
... request = sg.make_request([field.id, field.outcomes])
>>> print(request.graphql) query {
x8b50aedfc3bfeb1f: fixedProductMarketMakers(first: 2, where: {outcomes: ["Yes", "No"]}) {
id
outcomes
}
} While this query seems to match up with the GraphQL API link you posted, Subgrounds actually injected some extra data (starting with >>> with Subgrounds() as sg:
... subgraph = sg.load_api(url)
... yes = subgraph.Query.fixedProductMarketMakers(first=2, where={"outcomes": ["yes"]})
... no = subgraph.Query.fixedProductMarketMakers(first=2, where={"outcomes": ["no"]})
... request = sg.make_request([yes.id, yes.outcomes, no.id, no.outcomes])
>>> print(request.graphql) query {
xe6482a7b42808c65: fixedProductMarketMakers(first: 2, where: {outcomes: ["yes"]}) {
id
outcomes
}
x626d33e4fd087f66: fixedProductMarketMakers(first: 2, where: {outcomes: ["no"]}) {
id
outcomes
}
} This is a bit of a more thorough breakdown to explain this behavior but the true resolution to this is actually more of an interface design POV. When the I realize there's not an issue for this currently, but there have been ideas internally about a more fleshed out / updated API interface for the |
Describe the bug
When calling the method
result = sg.query_json()
, the returned object looks roughly like this:It's not clear to me (also could not find anything in the docs) why the results are indexed by this (apparently random) key. Isn't it easier to just return all flattened items?
I apologize if this behaviour is documented somewhere.
To Reproduce
fixedProductMarketMakers
)Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Python version (please complete the following information):
The text was updated successfully, but these errors were encountered: