graphprotocol / support

Community support for the Hosted Service of The Graph
https://thegraph.com/
10 stars 3 forks source link

Automatic entity versioning would be really helpful for queries that include `block` #50

Open asselstine opened 4 years ago

asselstine commented 4 years ago

We are querying entities using the new 'block' time travel feature. We query the Pool contract for the current prize size, then query it with past blocks to determine past prize sizes.

We use Apollo Client for our front-end. It's caching layer keys objects using "typename:id" to determine object uniqueness. The problem is that old "versions" of the Pool entity are clobbering new versions as they share the same key.

We solved this problem by adding a "version: BigInt" to each of our entities in schema.graphql that we need to pull historic data for. Any time we update those entities, we increment the version field.

I would have loved to add this increment code to the generated save() function, but we re-generate our code fairly often so it would be a pain to add it again every time.

Versioned entities definitely seems like the framework could provide pretty easily! It would be very useful to us.

Thanks!