Skip to content

Commit

Permalink
Freeze snapshot values, but not the read cache
Browse files Browse the repository at this point in the history
  • Loading branch information
nevir committed Dec 15, 2017
1 parent f1cea35 commit cde4782
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

2 comments on commit cde4782

@jamesreggio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah... yeah. I'm guessing you also got Cannot assigned to readonly property on Android?

(What a pain in the ass that was to debug.)

@nevir
Copy link
Contributor Author

@nevir nevir commented on cde4782 Dec 20, 2017 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.