I am using apollo graphql, and it has a module with a function inside of it.
export function createApollo(httpLink: HttpLink, connectToDevTools: true){
Inside this function you define the url for the graphql endpoint const uri = http://127.0.0.1/graphql for instance.
I would like to import this url form a service (so that I only have to change the backend server url in one place), but I can not inject the service, for the property stays undefined.
export function createApollo(httpLink: HttpLink, connectToDevTools: true, urlservice: UrlsService) {
const uri = urlservice.graphqlAddress;
Error: Cannot read property 'graphqlAddress' of undefined
I have also tried injecting the service into the modules constructor, but this is even lower down the chain, with the same results.
How do I get an outside property into the function createApollo?
My service basically looks like this:
export class UrlsService {
...
graphqlAddress = 'http://192.168.2.24:8000/graphql/';
...
}
GraphQLModule providers:
@NgModule({
exports: [ApolloModule, HttpLinkModule],
providers: [
UrlsService,
{
provide: APOLLO_OPTIONS,
useFactory: createApollo,
deps: [HttpLink],
},
],
})
export class GraphQLModule {
}
UrlsServiceas a dependencydeps: [HttpLink, UrlsService],it does not work ? Also, yourconnectToDevTools: true,looks like a mistake. Try removing it if it's always true, otherwise you need to provide it