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

Provide service clients through context #366

Open
johanandren opened this issue Jun 23, 2022 · 1 comment
Open

Provide service clients through context #366

johanandren opened this issue Jun 23, 2022 · 1 comment
Labels
javascript-sdk kalix-runtime Runtime and SDKs sub-team

Comments

@johanandren
Copy link
Contributor

Since #355 clients for other services, in the same Kalix service or between services, needs auth information from discovery, that was done through breaking change with a preStart callback on the components initializing the clients.

Since clients is a field on the component itself it gives the feeling that the clients should be available at any time after (or maybe even in) the constructor has been called. As this is no longer the case it would be better to move clients to the contexts so that it is not possible to accidentally try to access them in a place where they will not yet be initialized.

@johanandren
Copy link
Contributor Author

One more aspect is that a user may want to create the client for a component once and re-use it rather than creating it over and over again, I figured out how to hack together an overload solution for TS but it's pretty messy:

import {Action, GrpcClientCreator, GrpcClientLookup, PreStartSettings, Reply } from "@kalix-io/kalix-javascript-sdk";

const action = new Action(...)

const originalPreStart = action.preStart.bind(action);
let entityClient: any;
action.preStart = function(settings: PreStartSettings) {
    originalPreStart(settings);
    const clientFactory = (action.clients!.customer as any).api.CustomerService as GrpcClientCreator;
    entityClient = clientFactory.createClient();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript-sdk kalix-runtime Runtime and SDKs sub-team
Projects
None yet
Development

No branches or pull requests

2 participants