Skip to content
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

add useQueryClientResolver to rpc client #720

Merged
merged 2 commits into from
Jan 25, 2025
Merged

Conversation

Zetazzz
Copy link
Collaborator

@Zetazzz Zetazzz commented Jan 16, 2025

No description provided.

}) => {
const tmClient = await connectComet(rpcEndpoint);
const client = new QueryClient(tmClient);
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should still be const, right?

Suggested change
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
const makeClient = queryClientResolver || createConnectCometQueryClient;
const client = await makeClient(rpcEndpoint);

}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this optional?

Suggested change
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
queryClientResolver?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;

"resolver" is a little confusing to me. This makes a client. Consider treating the current behavior as the an explicit default:

Suggested change
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
makeClient?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient> = createConnectCometQueryClient;

@@ -40,3 +40,15 @@ export const createRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {

return rpc;
}

export const createTm34QueryClient = async (rpcEndpoint: string | HttpEndpoint) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please excuse me, I think I need to keep this as the default values for makeClient

@@ -443,6 +443,8 @@ See [LCD Clients](#lcd-clients) for more info.
| `rpcClients.scopedIsExclusive` | will allow both scoped bundles and all RPC Clients | `true` |
| `rpcClients.enabledServices` | which services to enable | [`Msg`,`Query`,`Service`] |
| `rpcClients.instantOps` | will generate instant rpc operations in the file `service-ops.ts` under root folder, which contains customized classes having selected rpc methods | `undefined` |
| `rpcClients.useConnectComet` | will use connectComet function to get a tendermint client | `undefined` |
| `rpcClients.useQueryClientResolver` | allow user to pass a query client resolver to create query client in createRPCQueryClient function | `undefined` |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be a codegen option? couldn't the code just allow it always as an optional param?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we have to do it for people who don't want generate this code.

@@ -43,7 +43,7 @@ export function buildQuery<TReq, TRes>(opts: QueryBuilderOptions<TReq, TRes>) {

export interface ITxArgs<TMsg> {
signerAddress: string;
message: TMsg;
message: TMsg | TMsg[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change intentional? seems unrelated to the PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a minor fix for other purpose, never mind about this.

Copy link
Contributor

@turadg turadg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Higher level… I see this is the status quo:

export const createRPCQueryClient = async ({
  rpcEndpoint
}: {
  rpcEndpoint: string | HttpEndpoint;
}) => {
  const tmClient = await connectComet(rpcEndpoint);
  const client = new QueryClient(tmClient);

What I'd really like is for createRPCQueryClient to do less. It shouldn't even need to import connectComet, imo. That alone pulls in Axios which is quite opinionated.

What I'd really like to see is for createRPCQueryClient to itself take the Tendermint34Client value that needs to be passed to the QueryClient constructor. In some other module you could have a convenience factory that takes an HttpEndpoint and chooses an HTTP client but this module should prescribe the query transport.

Would that be feasible? Then you wouldn't need a config option that complicates your docs, testing and maintenance. It's just a more flexible factoring.

@Zetazzz Zetazzz merged commit dbb47dd into main Jan 25, 2025
2 checks passed
@Zetazzz
Copy link
Collaborator Author

Zetazzz commented Jan 25, 2025

I don't why this's merged, I didn't press any button yet, strange.
No worry, I'll open another to do the fix

@Zetazzz
Copy link
Collaborator Author

Zetazzz commented Jan 25, 2025

Higher level… I see this is the status quo:

export const createRPCQueryClient = async ({
  rpcEndpoint
}: {
  rpcEndpoint: string | HttpEndpoint;
}) => {
  const tmClient = await connectComet(rpcEndpoint);
  const client = new QueryClient(tmClient);

What I'd really like is for createRPCQueryClient to do less. It shouldn't even need to import connectComet, imo. That alone pulls in Axios which is quite opinionated.

What I'd really like to see is for createRPCQueryClient to itself take the Tendermint34Client value that needs to be passed to the QueryClient constructor. In some other module you could have a convenience factory that takes an HttpEndpoint and chooses an HTTP client but this module should prescribe the query transport.

Would that be feasible? Then you wouldn't need a config option that complicates your docs, testing and maintenance. It's just a more flexible factoring.

Thank you very much for you review, we'll have a better way to handle this after some higher priority issues are handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants