From fc07318d1314d5a994e8163311f220eedb3e7a88 Mon Sep 17 00:00:00 2001 From: Gosuto Inzasheru Date: Wed, 11 Dec 2024 14:41:14 +0700 Subject: [PATCH 1/2] feat: allow gql query to be string instead of a filename --- bal_tools/subgraph.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bal_tools/subgraph.py b/bal_tools/subgraph.py index d5edeaa..d939233 100644 --- a/bal_tools/subgraph.py +++ b/bal_tools/subgraph.py @@ -218,9 +218,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 a query string + gql_query = gql(query) + else: + # 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()) result = client.execute(gql_query, variable_values=params) return result From 3394ca6055f36aba68dfa93ae899f0ae3fb5f44e Mon Sep 17 00:00:00 2001 From: Gosuto Inzasheru Date: Wed, 11 Dec 2024 16:00:02 +0700 Subject: [PATCH 2/2] docs: improve inline comments --- bal_tools/subgraph.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bal_tools/subgraph.py b/bal_tools/subgraph.py index d939233..4a3fb2c 100644 --- a/bal_tools/subgraph.py +++ b/bal_tools/subgraph.py @@ -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, @@ -219,10 +218,10 @@ def fetch_graphql_data( client = Client(transport=transport, fetch_schema_from_transport=False) if "{" and "}" in query: - # `query`` is a query string + # `query` is the actual query itself gql_query = gql(query) else: - # retrieve the query from its file and execute it + # `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)