Skip to content

Commit

Permalink
Don't warn for caches that don't enable data masking
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 23, 2024
1 parent 18f43cf commit 25c47f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
27 changes: 27 additions & 0 deletions src/cache/core/__tests__/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,33 @@ describe("abstract cache", () => {
);
});

it("returns original data and does not warn on caches that don't implement the required interface with the default data masking config", () => {
using consoleSpy = spyOnConsole("warn");

const query = gql`
query {
user {
__typename
id
...UserFields
}
}
fragment UserFields on User {
name
}
`;
const data = {
user: { __typename: "User", id: 1, name: "Mister Masked" },
};
const cache = new TestCache();

const result = cache.maskOperation(query, data);

expect(result).toBe(data);
expect(consoleSpy.warn).not.toHaveBeenCalled();
});

it("returns masked query for caches that implement required interface", () => {
class MaskingCache extends TestCache {
public readonly dataMasking = true;
Expand Down
8 changes: 4 additions & 4 deletions src/cache/core/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
}

public maskOperation<TData = unknown>(document: DocumentNode, data: TData) {
if (!this.dataMasking) {
return data;
}

if (!this.fragmentMatches) {
if (__DEV__) {
invariant.warn(
Expand All @@ -392,10 +396,6 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
return data;
}

if (!this.dataMasking) {
return data;
}

return maskOperation(data, document, this.fragmentMatches.bind(this));
}

Expand Down

0 comments on commit 25c47f1

Please sign in to comment.