You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to write a test using the ApolloTestingModule and ApolloClientOptions.
I provide custom ApolloClientOptions with the APOLLO_OPTION injection token. In the options I set the "no-cache" fetch-policy for my queries.
In my Test I import the ApolloTestingModule. When I run my test, I get the following error: "Error: Apollo has been already created." I'm not sure which part already created the default client but the ApolloTestingModule also tries to create the default client with the fake backend and a cache (that might be provided).
I made a local copy of the ApolloTestingModuleCore and modified the code a bit:
exportclassApolloTestingModuleCore{constructor(apollo: Apollo,backend: ApolloTestingBackend,
@Optional()
@Inject(APOLLO_TESTING_CLIENTS)namedClients?: string[],
@Optional()
@Inject(APOLLO_TESTING_CACHE)cache?: ApolloCache<any>,
@Optional()
@Inject(APOLLO_TESTING_NAMED_CACHE)namedCaches?: any,// FIX: using NamedCaches here makes ngc fail
@Optional()
@Inject(APOLLO_OPTIONS)options?: ApolloClientOptions<any>,){functioncreateOptions(name: string,c?: ApolloCache<any>|null){return{
...options,link: newApolloLink((operation)=>backend.handle(addClient(name,operation)),),cache:
c||newInMemoryCache({addTypename: false,}),};}apollo.removeClient('default');apollo.create(createOptions('default',cache));if(namedClients&&namedClients.length){namedClients.forEach((name)=>{constcaches=namedCaches&&typeofnamedCaches==='object' ? namedCaches : {};apollo.createNamed(name,createOptions(name,caches[name]));});}}}
When I use the modified version of the ApolloTestingModuleCore everything works as expected.
Is it possible to change this part or is there an intended way to test with ApolloClientOptions?
The text was updated successfully, but these errors were encountered:
I'm trying to write a test using the ApolloTestingModule and ApolloClientOptions.
I provide custom ApolloClientOptions with the APOLLO_OPTION injection token. In the options I set the "no-cache" fetch-policy for my queries.
In my Test I import the ApolloTestingModule. When I run my test, I get the following error: "Error: Apollo has been already created." I'm not sure which part already created the default client but the ApolloTestingModule also tries to create the default client with the fake backend and a cache (that might be provided).
I made a local copy of the ApolloTestingModuleCore and modified the code a bit:
When I use the modified version of the ApolloTestingModuleCore everything works as expected.
Is it possible to change this part or is there an intended way to test with ApolloClientOptions?
The text was updated successfully, but these errors were encountered: