Skip to content

Commit c138ed6

Browse files
committed
Update multipart response
1 parent 2e16da8 commit c138ed6

1 file changed

Lines changed: 73 additions & 5 deletions

File tree

src/__tests__/local-state/export.ts

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,6 @@ describe("@client @export tests", () => {
978978
}
979979
`;
980980

981-
const userId = "1";
982981
let fetchCount = 0;
983982
const link = new ApolloLink((operation) => {
984983
fetchCount += 1;
@@ -1152,7 +1151,6 @@ describe("@client @export tests", () => {
11521151

11531152
test("merges concurrent cache updates during a streamed response when variables come from @export", async () => {
11541153
const multipart = mockDeferStreamGraphQL17Alpha9();
1155-
const userId = "1";
11561154

11571155
const query = gql`
11581156
query FriendListWithExport($userId: ID!) {
@@ -1177,7 +1175,7 @@ describe("@client @export tests", () => {
11771175
userId
11781176
}
11791177
`,
1180-
data: { userId },
1178+
data: { userId: "1" },
11811179
});
11821180

11831181
const stream = new ObservableStream(client.watchQuery({ query }));
@@ -1200,7 +1198,7 @@ describe("@client @export tests", () => {
12001198

12011199
await expect(stream).toEmitTypedValue({
12021200
data: markAsStreaming({
1203-
userId,
1201+
userId: "1",
12041202
friendList: [{ __typename: "Friend", id: "1", name: "Luke" }],
12051203
}),
12061204
dataState: "streaming",
@@ -1237,7 +1235,7 @@ describe("@client @export tests", () => {
12371235

12381236
await expect(stream).toEmitTypedValue({
12391237
data: {
1240-
userId,
1238+
userId: "1",
12411239
friendList: [
12421240
{
12431241
__typename: "Friend",
@@ -1253,6 +1251,76 @@ describe("@client @export tests", () => {
12531251
networkStatus: NetworkStatus.ready,
12541252
partial: false,
12551253
});
1254+
1255+
client.writeQuery({
1256+
query: gql`
1257+
{
1258+
userId
1259+
}
1260+
`,
1261+
data: { userId: "2" },
1262+
});
1263+
1264+
await expect(stream).toEmitSimilarValue({
1265+
expected: (previous) => ({
1266+
...previous,
1267+
loading: true,
1268+
networkStatus: NetworkStatus.loading,
1269+
}),
1270+
});
1271+
1272+
multipart.enqueueInitialChunk({
1273+
data: {
1274+
friendList: [{ __typename: "Friend", id: "10", name: "Padme" }],
1275+
},
1276+
pending: [],
1277+
hasNext: false,
1278+
});
1279+
1280+
await expect(stream).toEmitTypedValue({
1281+
data: {
1282+
userId: "2",
1283+
friendList: [{ __typename: "Friend", id: "10", name: "Padme" }],
1284+
},
1285+
dataState: "complete",
1286+
loading: false,
1287+
networkStatus: NetworkStatus.ready,
1288+
partial: false,
1289+
});
1290+
1291+
client.cache.evict({
1292+
id: "ROOT_QUERY",
1293+
fieldName: "friendList",
1294+
args: { userId: "2" },
1295+
});
1296+
client.cache.gc();
1297+
1298+
await expect(stream).toEmitSimilarValue({
1299+
expected: (previous) => ({
1300+
...previous,
1301+
loading: true,
1302+
networkStatus: NetworkStatus.loading,
1303+
}),
1304+
});
1305+
1306+
multipart.enqueueInitialChunk({
1307+
data: {
1308+
friendList: [{ __typename: "Friend", id: "10", name: "Amidala" }],
1309+
},
1310+
pending: [],
1311+
hasNext: false,
1312+
});
1313+
1314+
await expect(stream).toEmitTypedValue({
1315+
data: {
1316+
userId: "2",
1317+
friendList: [{ __typename: "Friend", id: "10", name: "Amidala" }],
1318+
},
1319+
dataState: "complete",
1320+
loading: false,
1321+
networkStatus: NetworkStatus.ready,
1322+
partial: false,
1323+
});
12561324
});
12571325

12581326
test("should update @client @export variables on each broadcast if they've changed", async () => {

0 commit comments

Comments
 (0)