import { ApolloLink , Operation , NextLink , Observable , FetchResult , } from 'apollo-link' ; import { withClientState } from 'apollo-link-state' ; import { Manager } from './manager' ; import { createMutationSchema } from './internal/mutation' ; import { createResolvers } from './internal/resolvers' ; import { Options } from './types/options' ; function isManager ( obj ) { return obj instanceof Manager ; } export class LoonaLink extends ApolloLink { public manager : Manager ; private stateLink : ApolloLink ; constructor ( optionsOrManager ) { super ( ) ; if ( isManager ( optionsOrManager ) ) { this . manager = optionsOrManager ; } else { this . manager = new Manager ( optionsOrManager ) ; } this . stateLink = withClientState ( { cache : this . manager . cache , resolvers : ( ) => { return { Mutation : createMutationSchema ( this . manager ) , ... createResolvers ( this . manager ) , } ; } , defaults : this . manager . defaults , typeDefs : this . manager . typeDefs , } ) ; } public request ( operation , forward ) { return this . stateLink . request ( operation , forward ) as Observable < FetchResult > ; } }