I am in the process of making an Angular library that includes auth/graphql related code that all our apps require.
Issue is, I store the uri
in an Angular environment variable, which do not exist in an Angular libraries.
Performing an ng add apollo-angular
generates the following module:
graphql.module.ts (removed imports for clarity):
const uri = ''; // <-- add the URL of the GraphQL server here
export function createApollo(httpLink: HttpLink) {
return {
link: httpLink.create({uri}),
cache: new InMemoryCache(),
};
}
@NgModule({
exports: [ApolloModule, HttpLinkModule],
providers: [
{
provide: APOLLO_OPTIONS,
useFactory: createApollo,
deps: [HttpLink],
},
],
})
export class GraphQLModule {}
Notice the uri
, which creates a dependency on this module which should be injected.
In my apps app.module.ts
, I created a provider which grabs the environment:
providers: [
{
provide: 'envVars', useValue: environment
}
]
Which I typically inject via the constructor like so:
constructor(@Inject('envVars') private envVars: any) {}
I've tried many ways to inject this uri
to no avail! Suggestions?