Skip to content

Commit

Permalink
Merge pull request #256 from convoyinc/nevir/selective-freeze
Browse files Browse the repository at this point in the history
Freeze snapshot values, but not the read cache
  • Loading branch information
nevir authored Dec 15, 2017
2 parents f1cea35 + cde4782 commit 5e2b760
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/GraphSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import deepFreeze = require('deep-freeze-strict');

import { NodeSnapshot } from './nodes';
import { QueryResult, QueryResultWithNodeIds } from './operations/read';
import { NodeId, OperationInstance } from './schema';
Expand Down Expand Up @@ -57,4 +59,13 @@ export class GraphSnapshot {
return Object.keys(this._values);
}

/**
* Freezes the snapshot (generally for development mode)
*
* @internal
*/
freeze(): void {
deepFreeze(this._values);
}

}
3 changes: 1 addition & 2 deletions src/operations/SnapshotEditor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isEqual } from 'apollo-utilities';
import deepFreeze = require('deep-freeze-strict');

import { CacheContext } from '../context';
import { InvalidPayloadError, OperationError } from '../errors';
Expand Down Expand Up @@ -442,7 +441,7 @@ export class SnapshotEditor {

const snapshot = this._buildNewSnapshot();
if (this._context.freezeSnapshots) {
deepFreeze(snapshot);
snapshot.freeze();
}

return {
Expand Down

0 comments on commit 5e2b760

Please sign in to comment.