Skip to content

Commit

Permalink
[Data masking] Fix issue applying accessor warnings to interface types (
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller authored Nov 15, 2024
1 parent d10d702 commit 1e7d009
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-countries-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fix error thrown when applying unmask migrate mode warnings on interface types with selection sets that contain inline fragment conditions.
66 changes: 66 additions & 0 deletions src/core/__tests__/masking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,72 @@ describe("maskOperation", () => {
expect(console.warn).not.toHaveBeenCalled();
});

// https://github.com/apollographql/apollo-client/issues/12127
test('handles interface types when using @unmask(mode: "migrate")', async () => {
using _ = spyOnConsole("warn");
const query = gql`
query PlaybackStateSubscriberQuery {
playbackState {
__typename
...PlaybackStateFragment @unmask(mode: "migrate")
}
}
fragment PlaybackStateFragment on PlaybackState {
item {
__typename
id
... on Track {
album {
__typename
id
}
}
... on Episode {
show {
__typename
id
}
}
}
}
`;

const data = maskOperation(
{
playbackState: {
__typename: "PlaybackState",
item: {
__typename: "Track",
id: "1",
album: {
__typename: "Album",
id: "2",
},
},
},
},
query,
new InMemoryCache()
);

expect(data).toEqual({
playbackState: {
__typename: "PlaybackState",
item: {
__typename: "Track",
id: "1",
album: {
__typename: "Album",
id: "2",
},
},
},
});
});

test("masks fragments in subscription documents", () => {
const subscription = gql`
subscription {
Expand Down
7 changes: 7 additions & 0 deletions src/core/masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ function addFieldAccessorWarnings(
return memo;
}
case Kind.INLINE_FRAGMENT: {
if (
selection.typeCondition &&
!context.cache.fragmentMatches!(selection, (data as any).__typename)
) {
return memo;
}

return addFieldAccessorWarnings(
memo,
data,
Expand Down

0 comments on commit 1e7d009

Please sign in to comment.