Skip to content

add useQueryClientResolver to rpc client#720

Merged
Zetazzz merged 2 commits intomainfrom
query-client-resolver
Jan 25, 2025
Merged

add useQueryClientResolver to rpc client#720
Zetazzz merged 2 commits intomainfrom
query-client-resolver

Conversation

@Zetazzz
Copy link
Contributor

@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);

queryClientResolver
}: {
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;

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
Contributor 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

| `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
Contributor 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.

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
Contributor 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
Contributor 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
Contributor 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