-
Notifications
You must be signed in to change notification settings - Fork 0
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
multiple subgraph queries #38
base: feat/subgraph_query
Are you sure you want to change the base?
Conversation
queries: | ||
- '{ | ||
_meta { block { number } } | ||
tokens { id symbol name decimals } | ||
}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- you basically always want to query the block number alongside the data so that these are associated. We could leave this up to the user to define as aprt of the (list of) query (/ies)
- I did not figure out a nice way to combine a list of queries into a single query.
We could use a library for graphql handling, but rather not introduce a dependency, then again if the alternative is dirty string parsing I would certainly consider it
i.e. if you have these two queries
{ _meta { block { number } } }
{ tokens { id symbol name decimals }
you effectively need to remove outer brackets and wrap them together in a new pair of brackets
{
_meta { block { number } }
tokens { id symbol name decimals }
}
--- | ||
public_id: valory/ledger:0.19.0 | ||
type: connection | ||
config: | ||
ledger_apis: | ||
ethereum: | ||
address: ${CHAIN_ADDRESS:str} | ||
chain_id: ${CHAIN_ID:int} | ||
poa_chain: ${bool:false} | ||
default_gas_price_strategy: ${str:eip1559} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this override is required. However, we may have multiple chains we want to query latest block number for. We have done such a thing in a previous project (multi-chain) but I have not implemented that here yet. I believe that was innovation station, but I don't remember how this was done; in case you have a reference that would be appreciated
if not config.get("subgraph_api_key"): | ||
self.context.logger.warning("No subgraph_api_key provided!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will still need to set the GRAPH_API_KEY
, but can set this to an empty string. If your URL does not contain the {api_key}
part in the string, the str.format(api_key="")
will just leave the string unaltered as is
@@ -129,9 +129,9 @@ models: | |||
use_slashing: false | |||
use_termination: false | |||
validate_timeout: 1205 | |||
subgraph_sync_tolerance: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default on skill is 1
, can always overwrite at agent level as I have done
if not (subgraph_queries := config.get("subgraph_queries")): | ||
raise ValueError("No subgraph queries provided in aea-config.yaml") | ||
|
||
required = ("url", "chain", "queries") | ||
for subgraph_name, config in subgraph_queries.items(): | ||
if not all(map(config.get, required)): | ||
raise ValueError(f"Ensure all required fields are provided for {subgraph_name}: {required}") | ||
|
||
return {name: SubgraphQueryConfig(**data) for name, data in subgraph_queries.items()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are effectively 3 checks.
- First is that subgraph_queries must exist (else this AbciApp doesn't make any sense, and neither can it operate without)
- Second, the subgraph_queries is a mapping, whose values should consist of an
url
,chain
and a list ofqueries
- The
SubgraphQueryConfig
is a pydantic model that will throw if the datatype doesn't match the specification.
responses = {} | ||
for name, config in subgraph_queries.items(): | ||
url = config.url.format(api_key=api_key) | ||
for query in config.queries: | ||
content = serialize({"query": query}).encode("utf-8") | ||
response = yield from self.get_http_response( | ||
method="POST", | ||
url=url, | ||
content=content, | ||
headers=headers, | ||
) | ||
responses.setdefault(name, []).append(response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so ideally this would not be a nested loop, however that would require combining all queries into a single one, and I don't know how this can be achieved without merging the queries into one graphql query. But that requires manipulation of the individual queries, as described in my previous comment here. Though there might be another way that I am unaware of
No description provided.