-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
feat(orm)!: implement gRPC query support #14965
Conversation
@@ -56,7 +61,7 @@ | |||
continue | |||
} | |||
|
|||
out, err := os.OpenFile(fmt.Sprintf("%s_query.proto", f.GeneratedFilenamePrefix), os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0o644) | |||
out, err := os.OpenFile(queryProtoFilename(f), os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0o644) |
Check failure
Code scanning / gosec
Expect file permissions to be 0600 or less
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good start. I'm wondering about the following though:
- converting addresses stored in state as bytes (as well as any other values that might need to be converted)
- return embedded information in response (in regen ledger we often store the primary key of another state object and need to return specific information from the other state object, e.g. a project needs to return the class id stored in a class state object, a sell order needs to return the ask price denom stored in the market state object, etc.)
} | ||
t.P(")") | ||
t.P("if err != nil { return nil, err }") | ||
t.P("return &", name, "Response{Value: res}, nil") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be specific? e.g. Balances
rather than Values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
orm/internal/testpb/bank_query.proto
Outdated
// BalancesByDenom queries the Balance table using the primary key index. | ||
rpc BalancesByDenom(BalancesByDenomRequest) returns (BalancesByDenomResponse) { | ||
option (google.api.http) = { | ||
get: "/testpb/balances.denom" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this conventional? Can this be more user friendly? e.g. balances-by-denom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also worth noting the sdk uses _
but as far as I understand -
is more conventional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's not conventional. Initially I was thinking an HTTP matrix parameter would be nice (balances;index=denom
) but that doesn't play so nicely with grpc gateway.
The thing that bothers me about balances-by-denom
is that it isn't actually a domain type but rather an index, but maybe that's okay. I also considered balances/by-denom
but that conflicts with the actual balances GET query sort of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matrix parameters look interesting but also not yet widely adopted, at least as far as I've seen.
Yea, might be nice to use the actual domain type with an index. A nice thing about balances-by-denom
is that the CLI command is balance-by-denom
and the name of the query is BalancesByDenom
.
We had inconsistent endpoint names in Regen Ledger, which we resolved by adding alternatives, each endpoint reflects the name of the query method and then we added more conventional endpoints. We might have chosen one or the other but wanted to limit breaking changes so we chose to support both in the meantime. For example:
option (google.api.http) = {
get : "/regen/ecocredit/v1/projects-by-class/{class_id}"
additional_bindings : [
{get : "/regen/ecocredit/v1/projects/class/{class_id}"},
{get : "/regen/ecocredit/v1/classes/{class_id}/projects"}
]
};
Thanks for the feedback @ryanchristo
So I think this is important even though it's kind of hard. Would it be sufficient to just include address string parameters in the query parameters and still return the objects as they are stored in state (i.e. as bytes)? That would be much simpler. Otherwise, we need to generate a whole new set of types which include the address strings. Alternatively, we can have some sort of wrapper type (ex.
I was originally thinking a graphql API would be best for ORM queries. That would also play more nicely with address string/bytes conversions. The reason I'm going with the grpc approach is because that's whats' supported everywhere else in the SDK and seems like it's needed at a minimum. I think it'd be hard to traverse relationships with grpc, however. So would it be fine to consider the graphql layer an addon to be developed later? Or would it maybe be preferable to skip grpc and just do graphql? Personally, I'd rather use graphql for queries from a usability perspetive. but that would be at odds with the way everything else is done currently. |
I'm not in favor of returning bytes alone. As a webapp developer, I would rather not convert account bytes to an address in my web application. As a blockchain application developer, I would rather not convert when trying to debug. Maybe in some cases it would be good to support both but I haven't come across the need for bytes personally. |
I think it would be ok to consider as an add-on to be developed later. We probably wouldn't use this feature in Regen Ledger until we have graphql support but new developers could make use of the feature.
Yea, I'm not sure about this and this might be something worth exploring and discussing with other developers. Seems like a pretty big pivot. I agree though that from a usability perspective, graphql would be preferred. |
So I'm thinking that what I will do based on the feedback is:
How does that sound? Any other opinions? |
That all sounds good to me. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Description
Ref #11774
This follows up on #13438 and actually implements the query servers as well as making the following changes:
Balance
andBalances
instead ofGetBalance
andListBalance
. This should play more nicely with autocliGroups
, andGroupsByMember
are separate query methods)users/{id}
). Indexed are separated using a.
which I'm not sure about but seems like the best generic solution so far (ex.balances.by-denom?denom=foo
)The most important files for reviewers to look at are bank_query.proto and test_schema_query.proto
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change