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

multiple subgraph queries #38

Open
wants to merge 13 commits into
base: feat/subgraph_query
Choose a base branch
from

Conversation

Karrenbelt
Copy link
Owner

No description provided.

Comment on lines +130 to +134
queries:
- '{
_meta { block { number } }
tokens { id symbol name decimals }
}'
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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)
  2. 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 }
}

Comment on lines +157 to +166
---
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}
Copy link
Owner Author

@Karrenbelt Karrenbelt Aug 16, 2024

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

Comment on lines +230 to +231
if not config.get("subgraph_api_key"):
self.context.logger.warning("No subgraph_api_key provided!")
Copy link
Owner Author

@Karrenbelt Karrenbelt Aug 16, 2024

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

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

Comment on lines +232 to +240
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()}
Copy link
Owner Author

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.

  1. First is that subgraph_queries must exist (else this AbciApp doesn't make any sense, and neither can it operate without)
  2. Second, the subgraph_queries is a mapping, whose values should consist of an url, chain and a list of queries
  3. The SubgraphQueryConfig is a pydantic model that will throw if the datatype doesn't match the specification.

Comment on lines +173 to +184
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)
Copy link
Owner Author

@Karrenbelt Karrenbelt Aug 18, 2024

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

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

Successfully merging this pull request may close these issues.

1 participant