Skip to content

Commit

Permalink
Merge pull request #67 from BalancerMaxis/feat/allow-qgl-query-as-string
Browse files Browse the repository at this point in the history
feat: allow gql query to be string instead of a filename
  • Loading branch information
gosuto-inzasheru authored Dec 12, 2024
2 parents 5caf009 + 3394ca6 commit fed4e0b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bal_tools/subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def fetch_graphql_data(
raise ValueError(
f"Subgraph url not found for {subgraph} on chain {self.chain}"
)

transport = RequestsHTTPTransport(
url=url or self.subgraph_url[subgraph],
retries=retries,
Expand All @@ -218,9 +217,13 @@ def fetch_graphql_data(
)
client = Client(transport=transport, fetch_schema_from_transport=False)

# retrieve the query from its file and execute it
with open(f"{graphql_base_path}/{subgraph}/{query}.gql") as f:
gql_query = gql(f.read())
if "{" and "}" in query:
# `query` is the actual query itself
gql_query = gql(query)
else:
# `query` is the filename; load it from the graphql folder
with open(f"{graphql_base_path}/{subgraph}/{query}.gql") as f:
gql_query = gql(f.read())
result = client.execute(gql_query, variable_values=params)

return result
Expand Down

0 comments on commit fed4e0b

Please sign in to comment.