graphprotocol / graph-node

Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL
https://thegraph.com
Apache License 2.0
2.92k stars 984 forks source link

Make it possible to express 'query at latest block' with a block constraint #3169

Open lutter opened 2 years ago

lutter commented 2 years ago

Queries can contain a block constraint like block: { number: 79 } to execute the query at block 79. It is not possible to express 'give me data for the latest block' with that constraint which forces apps that want to sometime query at a certain block, and sometimes at the latest block, to change the text of their GraphQL query.

We should make it possible to always include block: { number: $block } in a query, and have a special value that means 'latest block'. Using -1 as that special value would probably be best since some languages support negative array indexes to count from the back, where array[-1] means 'give me the last array entry'.

poonai commented 2 years ago

does BlockConstraint::Latest solves it?

lutter commented 2 years ago

does BlockConstraint::Latest solves it?

Yes, internally that would be represented as BlockConstraint::Latest - what this ticket talks about is that it's not possible to express that in the GraphQL. The only way to query the latest block is to not have a block constraint at all. But sometimes it would be good to always have block: { number: $block } in the query and just set $block to some special value when you want the latest block rather than a specific block.