import { ApolloClient, HttpLink, InMemoryCache, NormalizedCacheObject, } from '../libs'; import { IGraphqlInitOptions } from '../types'; import { GraphqlClient } from '../client/GraphqlClient'; import { init as initEvents } from '../events'; import middleware from '../middleware'; /** * Creates a new Graphql client. */ export function init(uri: string, options: IGraphqlInitOptions = {}) { const events = initEvents(); // Initialize the embedded Apollo client. const cache = new InMemoryCache(); const http = new HttpLink({ uri }); const link = middleware(options) .concat(events.errorLink) .concat(http as any); const apollo = new ApolloClient({ link, cache }); // Construct the client wrapper. const client = new GraphqlClient(apollo, events); return client; }