Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Data masking] Fix issue with @unmask(mode: "migrate") with nested partial objects from parent query #12134

Merged
merged 8 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gorgeous-zebras-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fix issue where data went missing when an unmasked fragment in migrate mode selected fields that the parent did not.
4 changes: 2 additions & 2 deletions .size-limits.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dist/apollo-client.min.cjs": 41601,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 34359
"dist/apollo-client.min.cjs": 41638,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 34394
}
122 changes: 122 additions & 0 deletions src/core/__tests__/masking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,128 @@ describe("maskOperation", () => {
});
});

test('handles overlapping types when subtype has accessor warnings with @unmask(mode: "migrate")', async () => {
using consoleSpy = spyOnConsole("warn");
const query = gql`
query PlaylistQuery {
playlist {
...PlaylistFragment @unmask(mode: "migrate")
id
name
album {
id
tracks {
id
__typename
}
__typename
}
artist {
id
topTracks {
id
__typename
}
__typename
}
__typename

...PlaylistTitleCell @unmask(mode: "migrate")
}
}

fragment PlaylistFragment on Playlist {
album {
id
images {
url
__typename
}
tracks {
id
name
__typename
}
__typename
}
}

fragment PlaylistTitleCell on Playlist {
artist {
id
images {
url
__typename
}
topTracks {
id
name
__typename
}
__typename
}
}
`;

const data = maskOperation(
{
playlist: {
id: "1",
name: "Playlist",
album: {
id: "2RSIoPew2TOy41ASHpzOx3",
__typename: "Album",
images: [{ url: "https://i.scdn.co/image/1", __typename: "Image" }],
tracks: [{ id: "1", name: "Track 1", __typename: "Track" }],
},
artist: {
id: "2",
__typename: "Artist",
images: [{ url: "https://i.scdn.co/image/1", __typename: "Image" }],
topTracks: [{ id: "2", name: "Track 2", __typename: "Track" }],
},
},
},
query,
new InMemoryCache()
);

expect(consoleSpy.warn).not.toHaveBeenCalled();

consoleSpy.warn.mockClear();

data.playlist.album;
data.playlist.album.id;
data.playlist.album.__typename;
data.playlist.artist;
data.playlist.artist.id;
data.playlist.artist.__typename;
expect(console.warn).not.toHaveBeenCalled();
jerelmiller marked this conversation as resolved.
Show resolved Hide resolved

data.playlist.album.images;
data.playlist.artist.images;
expect(console.warn).toHaveBeenCalledTimes(2);

expect(data).toEqual({
playlist: {
id: "1",
name: "Playlist",
album: {
id: "2RSIoPew2TOy41ASHpzOx3",
__typename: "Album",
images: [{ url: "https://i.scdn.co/image/1", __typename: "Image" }],
tracks: [{ id: "1", name: "Track 1", __typename: "Track" }],
},
artist: {
id: "2",
__typename: "Artist",
images: [{ url: "https://i.scdn.co/image/1", __typename: "Image" }],
topTracks: [{ id: "2", name: "Track 2", __typename: "Track" }],
},
},
});
});

test("masks fragments in subscription documents", () => {
const subscription = gql`
subscription {
Expand Down
Loading