Skip to content

Conversation

@saitunc
Copy link
Contributor

@saitunc saitunc commented Dec 16, 2025

Description

This PR refactors query logic in ClientAppChain by extracting it into a dedicated QueryService class with lazy initialization patterns.

Changes

  • Added QueryService class with lazy-initialized getters for runtime, protocol, network, and explorer query modules f00c371
  • Implemented resolver functions for transport modules QueryTransportModule, NetworkStateTransportModule, BlockExplorerTransportModule f00c371
  • Added lazy initialization pattern to QueryService for query modules 23b6d4b
  • Updated ClientAppChain to use QueryService 880358f

This PR closes #349

@saitunc saitunc requested a review from rpanic December 16, 2025 01:27
@saitunc saitunc marked this pull request as ready for review December 16, 2025 01:27
*/
private get blockExplorerTransport(): BlockExplorerTransportModule {
if (this.BlockExplorerTransport === undefined) {
if (!this.container.isRegistered("BlockExplorerTransportModule")) {
Copy link
Member

Choose a reason for hiding this comment

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

We can save this line, tsyringe will throw a more descriptive error when it can't resolve a dependency anyways

Copy link
Member

Choose a reason for hiding this comment

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

Same for all the others in this class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed since it is injected now: 3385f1d

AppChainModules extends MinimalAppChainDefinition,
> extends AppChain<AppChainModules> {
// Optional for our lazy initialization purpose.
private QueryService?: QueryService<
Copy link
Member

Choose a reason for hiding this comment

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

lowercase

MandatoryProtocolModulesRecord,
> {
// Here, fields are optional for lazy initialization.
private QueryTransport?: QueryTransportModule;
Copy link
Member

Choose a reason for hiding this comment

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

So - I had a bit of a different structure in mind here - and I think this would save a lot of LOCs:
We use all the features the tsyringe gives us.
First, we make the QueryService @injectable() and @scoped(Lifecycle.ContainerScoped)
Then, we inject al the transport module in the constructor using @inject("Token", { isOptional: true }) private readonly module: Module | undefined
And then, we can use this.module for all the actual queries that we have

Copy link
Member

Choose a reason for hiding this comment

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

Also, in the ClientAppChain, we need to use this.parentContainer.resolve(QueryService)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved from parent container: 011abc8

and transport modules are now injected, so they are not directly defined in class: 3385f1d

@rpanic rpanic linked an issue Dec 18, 2025 that may be closed by this pull request
@saitunc saitunc requested a review from rpanic December 19, 2025 11:52
@saitunc saitunc merged commit 87b1ec8 into develop Dec 19, 2025
5 checks passed
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.

Make Query a service

3 participants