subgrounds icon indicating copy to clipboard operation
subgrounds copied to clipboard

Subgrounds requests with arguments

Open cvauclair opened this issue 3 years ago • 0 comments

Description

Subgrounds fieldpaths and requests creation whould allow developers to specify variables in their queries.

The requests containing variables would act as request templates which can be used to create actual requests.

Example

sg = Subgrounds()
uniswapV2 = sg.load_subgraph("https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2")

swaps = Query.swaps(
  orderBy=Swap.timestamp,
  orderDirection='desc',
  first=500,
  where=[
    Swap.pair == Variable('address')
  ]
)

req_template = sg.mk_request([
  swaps.timestamp, 
  swaps.pair.token0.symbol,
  swaps.pair.token1.symbol,
  swaps.amount0In,
  swaps.amount1In,
  swaps.amount0Out,
  swaps.amount1Out
])

actual_req = req_template(address='0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc')

data = sg.execute(actual_req)

cvauclair avatar Jan 23 '22 15:01 cvauclair