Skip to main content

Custom ApolloClient

Overview

By default, Orbit uses the default ApolloClient implementation provided by @apollo/client library.
But, it is possible in some scenarios that an application needs to provide its own custom implementation of ApolloClient.

This can be achieved by providing a custom ApolloClientFactory function to APOLLO_CLIENT_FACTORY injection token.

To customize the cache type, use Apollo's cache type declaration and provide that cache through withApolloOptions. Orbit preserves its methods in apollo.cache and state callbacks.

Usage

import { ApolloClientFactory } from '@apollo-orbit/angular';
import { CustomApolloClient } from 'custom-apollo-client';

const customApolloClientFactory: ApolloClientFactory = (options: ApolloClient.Options): ApolloClient => {
return new CustomApolloClient(options);
};

...

{
providers: [
{ provide: APOLLO_CLIENT_FACTORY, useValue: customApolloClientFactory }
]
}