At work we are building a large project that leverages libraries made by different teams. We are running into an issue with Apollo-Angular, in that when importing a single module with its own graphql module with APOLLO_NAMED_OPTIONS, it runs correctly. However if the particular application needs to import multiple modules with their own graphql modules, it seems as though something is colliding. We get an error where only the named options from a single file are loaded, leaving many of the services and components broken with errors of missing graphql names.
I made a Stackblitz to demonstrate the basic flaw, but the other graphql modules are coming bundled with other components and libraries, not side-by-side as in my Stackblitz example.
GraphQL Module #1:
import { NgModule } from '@angular/core';
import { APOLLO_NAMED_OPTIONS, NamedOptions } from 'apollo-angular';
import { InMemoryCache } from '@apollo/client/core';
import { HttpLink } from 'apollo-angular/http';
@NgModule({
providers: [
{
provide: APOLLO_NAMED_OPTIONS,
useFactory(httpLink: HttpLink): NamedOptions {
return {
appList: {
cache: new InMemoryCache(),
link: httpLink.create({
uri: 'https://graphql-voter-app.herokuapp.com/";',
}),
defaultOptions: {
query: {
fetchPolicy: 'no-cache',
},
watchQuery: {
fetchPolicy: 'no-cache',
},
},
},
};
},
deps: [HttpLink],
},
],
})
export class AppListGraphQLModule {}
GraphQL Module #2:
import { NgModule } from '@angular/core';
import { APOLLO_NAMED_OPTIONS, NamedOptions } from 'apollo-angular';
import { InMemoryCache } from '@apollo/client/core';
import { HttpLink } from 'apollo-angular/http';
@NgModule({
providers: [
{
provide: APOLLO_NAMED_OPTIONS,
useFactory(httpLink: HttpLink): NamedOptions {
return {
switchFauna: {
cache: new InMemoryCache(),
link: httpLink.create({
uri: 'https://graphql-voter-app.herokuapp.com/',
}),
defaultOptions: {
query: {
fetchPolicy: 'no-cache',
},
watchQuery: {
fetchPolicy: 'no-cache',
},
},
},
};
},
deps: [HttpLink],
},
],
})
export class GameGraphQLModule {}
Stackblitz:
In the example, only one named option from one graphql module can be found.