docs icon indicating copy to clipboard operation
docs copied to clipboard

Current `store` interface is confusing when using `Bytes` `id`

Open lutter opened this issue 3 years ago • 3 comments

The functions in the store module (get, set, remove) are a bit confusing right now when subgraph use Bytes as their id; the host interface still requires that the id is passed as a string, for Bytes it needs to be id.toHexString(). For get and set, the difference is hidden by the code that graph-cli generates, so that subgraph authors can say Thing.get(id) no matter whether Thing uses String or Bytes for its ids.

But for remove, users need to use the 'raw' interface and write store.remove(id.toHexString()) which can be confusing.

I don't think we should actually change the calling convention for the store functions; instead, we should document this more clearly and explain how to work with these functions when id has type Bytes.

This was first reported as part of graphprotocol/graph-node#3476

lutter avatar Apr 25 '22 20:04 lutter

Nice - would this primarily be an update here, or is this also about documentation within the graph-node repo?

azf20 avatar Apr 25 '22 21:04 azf20

Nice - would this primarily be an update here, or is this also about documentation within the graph-node repo?

No, I think that would be all in the docs repo; not really in graph-node - so we should probably move the issue?

lutter avatar Apr 25 '22 22:04 lutter

Currently, Bytes is required as the id type when indexing. But I'm unable to remove item with store.remove() which requires a String id... I've tried to stringify the Bytes with toString() but it just throws an error. Anyone know how I can get around this conflict?

ValentineCodes avatar Apr 02 '23 17:04 ValentineCodes