-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible strategy to help us produce reliable JSON-RPC response #610
Comments
Schemas and schema validation sound great. If we can reuse the code and remove some duplication serialisation to JSON, that's good too. However, we do need to remain compatible with JSON-RPC spec, and the direction we should be aiming with JSON-RPC support is all of the below (they can be done at the same time). Other clients are working towards this too, there's some effort to organise it.
Is the GraphQL code flexible enough to describe what JSON-RPC clients using the above will be looking for? If GraphQL can't do it along, let's find a way to reuse the code, schemas and validation etc that works for both. |
Side note: Due to history, Eth2 clients are standardising APIs and schemas for a REST API instead of JSON-RPC or, as far as I know, GraphQL. This doesn't affect Eth1 for now, but it might be good to give a little thought anticipating how REST could fit in. In other words, if there's a natural way for the GraphQL-derived schema and validation system in nimbus-eth1 (maybe extended to suit JSON-RPC needs) to present the same info via a REST API as well, that could be worth considering. |
very flexible, you can try our graphql toy server to find out how flexible the query language is. it can simulate
we only use graphql for validating and shaping the response content, the delivery mechanism still handled by JSON-RPC the same way to Graphql HTTP server. Both have their own response format, but the content is the same. OpenRPC is looks similar enough to Graphql, but Graphql syntax is more cleaner and graphql introspection system is more sophisticated.
From https://github.com/ethereum/eth2.0-APIs: |
That sounds like a good direction to take it then. Is it difficult to add new types of ad-hoc queries / responses while developing, when you just want to get some new type of data out? With our current JSON-RPC, it may be rather basic code, but it's easy and clear how to add add-hoc RPCs in just a few lines of code. |
It depends on how strong the validation required. our JSON-RPC may looks easy, but the content validation is weak.
Both your question and your statement inspire a crazy idea in my mind. After that, mapping REST call to GraphQL is roughly similar. |
Turn out, some of RPC to GraphQL already mapped in EIP1767: when implementing nimbus-eth1 graphql, I only copy the GraphQL DSL schema, and never scroll down the page, this will save a lot of time figuring out myself the correct mapping. |
One major obstacle when using GraphQL as JSON-RPC backend will came from Of course we can make the |
There is still a chance for GraphQL to overcome this freestyle json using |
Isn't using Nim types for the json requests/responses viable? |
yes, but writing test case for conventional JSON-RPC server is far from easy/convenient. if we can piggyback the json rpc using graphql, it will far easier to write test case. we can delegate much of the validation to graphql engine instead of writing complicated test case. better use our time/energy for the implementation itself. |
A standardized test suite for RPC request and response is located in |
One of the weakness and most annoying thing when implement JSON-RPC function is the lack of response validation. The other thing is we need to craft the response shape in a non reliable way.
On the other hand, Graphql have builtin validation and execution system that greatly simplify the process of constructing response based on the defined schema while at the same time validate the response is correct for both the structure and serialization format. it is more akin to
what you ask is what you get
.Graphql doesn't care how you deliver the result, you can serve it over HTTP, Websocket, RPC, etc. Graphql also doesn't dictate which serialization format you use. And fortunately, the common serialization format for Graphql is JSON. So usually a Graphql implementation already have a JSON serialization builtin.
Based on this fact, I have an idea worth exploring. The idea is we simply wrap the JSON-RPC function over a Graphql query.
And then let the Graphql engine produce a consistent response based on the Graphql-schema we defined or reuse/extend standard eth1.0 schema.
Benefits:
existingmodified Graphql test framework can be reused.The text was updated successfully, but these errors were encountered: