How can I inject Ionic Storage into the other module's config?

Hello. I made an app using graphQL apollo client. It works well.
But the app is still using the window.localStorage to set the auth header.

When I decide to change it with Ionic Storage, I met the wall.
The apollo’s middleware config is on the outside of the app module.
How can I inject the Ionic storage instance into the apollo’s middleware config?

I know this is not about ionic. It’s my lack of understanding in angular.
But I would like to ask you. Thanks.


import { IonicStorageModule } from '@ionic/storage';
import { ApolloModule } from 'apollo-angular';
import { provideApolloClient } from './apollo-client';

  imports: [
export class AppModule {}


import { ApolloClient, createNetworkInterface } from 'apollo-client';

const networkInterface = createNetworkInterface({ uri: '...' });

  applyMiddleware (req, next) {
    if (!req.options.headers) {
      req.options.headers = {};
    if (localStorage.getItem('token')) {
      req.options.headers.authorization = `Bearer ${localStorage.getItem('token')}`;

const client = new ApolloClient({ networkInterface });

export function provideApolloClient(): ApolloClient {
  return client;

If whatever this apollo thingy is is needing that authorization token to be available in synchronous fashion, this isn’t going to be possible, because ionic-storage works asynchronously.

You’re right. I would rather get the token on the other side by asynchronous way. Thanks.