spacemeshos / pm

Project management. Meta-tasks related to research, dev, and specs for the Spacemesh protocol and infrastructure.
http://spacemesh.io/
Creative Commons Zero v1.0 Universal
2 stars 0 forks source link

GraphQL API #269

Open lrettig opened 7 months ago

lrettig commented 7 months ago

One reason the current API is so broken is that the data model is not well designed. As one example there's currently no way to query a single reward or reward by smesherID (https://github.com/spacemeshos/api/issues/272). It's not possible to query account data (AccountDataQuery, AccountDataStream), smesher reward data (SmesherDataQueryRequest) or global state data (GlobalStateStreamRequest) by layer. It's not possible to read global state data except using a stream, which means there's no way to query historical state data. It's not possible to query account data (AccountMeshDataQueryRequest) using a range of layers (only a start layer). There's no way to look up a block, without looking up a layer, and there's no way to look up an epoch, only a stream EpochStreamRequest. Etc.

For many applications, including the explorer and much of what Smapp does, a GraphQL API would make a lot more sense. It would largely replace the need for the explorer to use streams (which continually time out), and would make historical queries and resyncing/checking data much easier. It would allow custom queries that "drill down" to a specific data item, e.g., a specific block or tx without performing multiple back-and-forth queries (e.g. epoch -> layer -> block -> tx).

I'm not suggesting replacing the existing gRPC API entirely with GraphQL. Certain API services, e.g., admin/debug services, those used to control the node, the new PoST service API, etc. are probably better off as gRPC.