import Cache from '../Cache'; import { ApolloPersistOptions, PersistedData } from '../types'; export default class MockCache implements Cache { cache: null; serialize: boolean; data: PersistedData; constructor(options: Pick, 'serialize'>) { const { serialize = true } = options; this.serialize = serialize; } extract(): PersistedData { let data: PersistedData = this.data; if (this.serialize) { data = JSON.stringify(this.data) as string; } return data; } restore(data: PersistedData): void { if (this.serialize && typeof data === 'string') { data = JSON.parse(data); } if (data != null) { this.data = data; } } }