I am working on an Angular 9 app that uses @apollo/client@3.4.16 and apollo-angular@2.6.0. I'm trying to use named clients. I initialize the clients in the forRoot method of a module that is passed the url. (My module is in a library and the url is passed from a json file from the consuming app). Here is my code:
@NgModule({})
export class MyModule {
public static forRoot(myUrls): ModuleWithProviders<MyModule > {
return {
ngModule: OdpCovid19UiModule,
providers: [
{
provide: APOLLO_NAMED_OPTIONS,
useFactory: (httpLink: HttpLink): NamedOptions => {
return {
'default': {
link: httpLink.create({
uri: myUrls.firstUrl
}),
cache: new InMemoryCache(),
defaultOptions
},
'secondClient': {
link: httpLink.create({
uri: myUrls.secondUrl
}),
cache: new InMemoryCache(),
defaultOptions
}
};
},
deps: [HttpLink]
}
]
};
}
}
Running the app with this code doesn't cause errors, but my endpoints are never called. If I run the app configured with APOLLO_OPTIONS instead of APOLLO_NAMED_OPTIONS the endpoints are called.
How can I configure this correclty? Is there another way I can used named clients that are passed a url loaded from a config file?