@cedarjs/web 6.0.0-canary.2652 → 6.0.0-canary.2657

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/apollo/fragmentRegistry.d.ts +23 -6
  2. package/dist/apollo/fragmentRegistry.d.ts.map +1 -1
  3. package/dist/apollo/fragmentRegistry.js +2 -2
  4. package/dist/apollo/index.d.ts +0 -1
  5. package/dist/apollo/index.d.ts.map +1 -1
  6. package/dist/apollo/index.js +2 -25
  7. package/dist/apollo/suspense.d.ts +0 -1
  8. package/dist/apollo/suspense.d.ts.map +1 -1
  9. package/dist/apollo/suspense.js +2 -24
  10. package/dist/cjs/apollo/fragmentRegistry.d.ts +23 -6
  11. package/dist/cjs/apollo/fragmentRegistry.d.ts.map +1 -1
  12. package/dist/cjs/apollo/fragmentRegistry.js +3 -3
  13. package/dist/cjs/apollo/index.d.ts +0 -1
  14. package/dist/cjs/apollo/index.d.ts.map +1 -1
  15. package/dist/cjs/apollo/index.js +1 -16
  16. package/dist/cjs/apollo/suspense.d.ts +0 -1
  17. package/dist/cjs/apollo/suspense.d.ts.map +1 -1
  18. package/dist/cjs/apollo/suspense.js +1 -16
  19. package/dist/cjs/components/cell/CellErrorBoundary.d.ts +3 -2
  20. package/dist/cjs/components/cell/CellErrorBoundary.d.ts.map +1 -1
  21. package/dist/cjs/components/cell/cellTypes.d.ts +3 -3
  22. package/dist/cjs/components/cell/cellTypes.d.ts.map +1 -1
  23. package/dist/cjs/components/cell/createCell.d.ts.map +1 -1
  24. package/dist/cjs/components/cell/createCell.js +2 -2
  25. package/dist/cjs/components/cell/createCell.test.js +69 -83
  26. package/dist/cjs/components/cell/createFragmentCell.d.ts.map +1 -1
  27. package/dist/cjs/components/cell/createFragmentCell.js +1 -2
  28. package/dist/cjs/components/cell/createFragmentCell.test.js +48 -55
  29. package/dist/cjs/components/cell/createSuspendingCell.d.ts.map +1 -1
  30. package/dist/cjs/components/cell/createSuspendingCell.js +2 -3
  31. package/dist/cjs/components/cell/createSuspendingCell.test.js +18 -37
  32. package/dist/cjs/global.web-auto-imports.d.ts +0 -16
  33. package/dist/cjs/global.web-auto-imports.d.ts.map +1 -1
  34. package/dist/cjs/global.web-auto-imports.js +0 -15
  35. package/dist/cjs/index.d.ts +4 -3
  36. package/dist/cjs/index.d.ts.map +1 -1
  37. package/dist/cjs/index.js +6 -7
  38. package/dist/components/cell/CellErrorBoundary.d.ts +3 -2
  39. package/dist/components/cell/CellErrorBoundary.d.ts.map +1 -1
  40. package/dist/components/cell/cellTypes.d.ts +3 -3
  41. package/dist/components/cell/cellTypes.d.ts.map +1 -1
  42. package/dist/components/cell/createCell.d.ts.map +1 -1
  43. package/dist/components/cell/createCell.js +1 -1
  44. package/dist/components/cell/createCell.test.js +70 -84
  45. package/dist/components/cell/createFragmentCell.d.ts.map +1 -1
  46. package/dist/components/cell/createFragmentCell.js +1 -2
  47. package/dist/components/cell/createFragmentCell.test.js +49 -56
  48. package/dist/components/cell/createSuspendingCell.d.ts.map +1 -1
  49. package/dist/components/cell/createSuspendingCell.js +5 -2
  50. package/dist/components/cell/createSuspendingCell.test.js +22 -38
  51. package/dist/global.web-auto-imports.d.ts +0 -16
  52. package/dist/global.web-auto-imports.d.ts.map +1 -1
  53. package/dist/index.d.ts +4 -3
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +3 -5
  56. package/package.json +5 -5
  57. package/dist/apollo/typeOverride.d.ts +0 -21
  58. package/dist/apollo/typeOverride.d.ts.map +0 -1
  59. package/dist/apollo/typeOverride.js +0 -0
  60. package/dist/cjs/apollo/typeOverride.d.ts +0 -21
  61. package/dist/cjs/apollo/typeOverride.d.ts.map +0 -1
  62. package/dist/cjs/apollo/typeOverride.js +0 -16
  63. package/dist/cjs/components/GraphQLHooksProvider.d.ts +0 -77
  64. package/dist/cjs/components/GraphQLHooksProvider.d.ts.map +0 -1
  65. package/dist/cjs/components/GraphQLHooksProvider.js +0 -147
  66. package/dist/components/GraphQLHooksProvider.d.ts +0 -77
  67. package/dist/components/GraphQLHooksProvider.d.ts.map +0 -1
  68. package/dist/components/GraphQLHooksProvider.js +0 -105
@@ -1,24 +1,29 @@
1
1
  import React from "react";
2
+ import { useQuery } from "@apollo/client/react/hooks/hooks.cjs";
2
3
  import { render, screen } from "@testing-library/react";
3
- import { vi, describe, beforeAll, test, expect } from "vitest";
4
- import { GraphQLHooksProvider } from "../GraphQLHooksProvider.js";
4
+ import { vi, describe, beforeAll, beforeEach, test, expect } from "vitest";
5
5
  import { createCell } from "./createCell.js";
6
+ vi.mock("@apollo/client/react/hooks/hooks.cjs", () => ({
7
+ useQuery: vi.fn()
8
+ }));
9
+ const mockUseQuery = useQuery;
6
10
  describe("createCell", () => {
7
11
  beforeAll(() => {
8
12
  globalThis.RWJS_ENV = {
9
13
  RWJS_EXP_STREAMING_SSR: false
10
14
  };
11
15
  });
16
+ beforeEach(() => {
17
+ mockUseQuery.mockReset();
18
+ });
12
19
  test("Renders a static Success component", () => {
13
20
  const TestCell = createCell({
14
21
  // @ts-expect-error - Purposefully using a plain string here.
15
22
  QUERY: "query TestQuery { answer }",
16
23
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!")
17
24
  });
18
- const myUseQueryHook = () => ({ data: {} });
19
- render(
20
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
21
- );
25
+ mockUseQuery.mockImplementation(() => ({ data: {} }));
26
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
22
27
  screen.getByText(/^Great success!$/);
23
28
  });
24
29
  test("Renders Success with data", () => {
@@ -27,12 +32,10 @@ describe("createCell", () => {
27
32
  QUERY: "query TestQuery { answer }",
28
33
  Success: ({ answer }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("dl", null, /* @__PURE__ */ React.createElement("dt", null, "What's the meaning of life?"), /* @__PURE__ */ React.createElement("dd", null, answer)))
29
34
  });
30
- const myUseQueryHook = () => {
35
+ mockUseQuery.mockImplementation(() => {
31
36
  return { data: { answer: 42 } };
32
- };
33
- render(
34
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
35
- );
37
+ });
38
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
36
39
  screen.getByText(/^What's the meaning of life\?$/);
37
40
  screen.getByText(/^42$/);
38
41
  });
@@ -43,17 +46,15 @@ describe("createCell", () => {
43
46
  Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No users or posts"),
44
47
  Success: ({ users, posts }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", null, users.length > 0 ? /* @__PURE__ */ React.createElement("ul", null, users.map(({ name }) => /* @__PURE__ */ React.createElement("li", { key: name }, name))) : "no users"), /* @__PURE__ */ React.createElement("div", null, posts.length > 0 ? /* @__PURE__ */ React.createElement("ul", null, posts.map(({ title }) => /* @__PURE__ */ React.createElement("li", { key: title }, title))) : "no posts"))
45
48
  });
46
- const myUseQueryHook = () => {
49
+ mockUseQuery.mockImplementation(() => {
47
50
  return {
48
51
  data: {
49
52
  users: [],
50
53
  posts: [{ title: "bazinga" }, { title: "kittens" }]
51
54
  }
52
55
  };
53
- };
54
- render(
55
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
56
- );
56
+ });
57
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
57
58
  screen.getByText(/bazinga/);
58
59
  screen.getByText(/kittens/);
59
60
  });
@@ -63,10 +64,8 @@ describe("createCell", () => {
63
64
  QUERY: "query TestQuery { answer }",
64
65
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!")
65
66
  });
66
- const myUseQueryHook = () => ({ loading: true });
67
- render(
68
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
69
- );
67
+ mockUseQuery.mockImplementation(() => ({ loading: true }));
68
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
70
69
  screen.getByText(/^Loading...$/);
71
70
  });
72
71
  test("Renders custom Loading when there is no data", () => {
@@ -76,10 +75,8 @@ describe("createCell", () => {
76
75
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
77
76
  Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
78
77
  });
79
- const myUseQueryHook = () => ({ loading: true });
80
- render(
81
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
82
- );
78
+ mockUseQuery.mockImplementation(() => ({ loading: true }));
79
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
83
80
  screen.getByText(/^Fetching answer...$/);
84
81
  });
85
82
  test("Renders Success even when `loading` is true if there is data", () => {
@@ -89,10 +86,8 @@ describe("createCell", () => {
89
86
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
90
87
  Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
91
88
  });
92
- const myUseQueryHook = () => ({ loading: true, data: {} });
93
- render(
94
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
95
- );
89
+ mockUseQuery.mockImplementation(() => ({ loading: true, data: {} }));
90
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
96
91
  screen.getByText(/^Great success!$/);
97
92
  });
98
93
  test("Renders Empty if available, and data field is null", () => {
@@ -102,10 +97,11 @@ describe("createCell", () => {
102
97
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
103
98
  Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No one knows")
104
99
  });
105
- const myUseQueryHook = () => ({ loading: true, data: { answer: null } });
106
- render(
107
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
108
- );
100
+ mockUseQuery.mockImplementation(() => ({
101
+ loading: true,
102
+ data: { answer: null }
103
+ }));
104
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
109
105
  screen.getByText(/^No one knows$/);
110
106
  });
111
107
  test("Renders Empty if available, and data field is an empty array", () => {
@@ -115,10 +111,11 @@ describe("createCell", () => {
115
111
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
116
112
  Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No one knows")
117
113
  });
118
- const myUseQueryHook = () => ({ loading: true, data: { answers: [] } });
119
- render(
120
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
121
- );
114
+ mockUseQuery.mockImplementation(() => ({
115
+ loading: true,
116
+ data: { answers: [] }
117
+ }));
118
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
122
119
  screen.getByText(/^No one knows$/);
123
120
  });
124
121
  test("Renders Success even if data is empty when no Empty is available", () => {
@@ -127,10 +124,11 @@ describe("createCell", () => {
127
124
  QUERY: "query TestQuery { answer }",
128
125
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Empty success")
129
126
  });
130
- const myUseQueryHook = () => ({ loading: true, data: { answer: null } });
131
- render(
132
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
133
- );
127
+ mockUseQuery.mockImplementation(() => ({
128
+ loading: true,
129
+ data: { answer: null }
130
+ }));
131
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
134
132
  screen.getByText(/^Empty success$/);
135
133
  });
136
134
  test("Allows passing children to Success", () => {
@@ -139,9 +137,9 @@ describe("createCell", () => {
139
137
  QUERY: "query TestQuery { answer }",
140
138
  Success: ({ children }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "Look at my beautiful ", children)
141
139
  });
142
- const myUseQueryHook = () => ({ data: {} });
140
+ mockUseQuery.mockImplementation(() => ({ data: {} }));
143
141
  render(
144
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null, /* @__PURE__ */ React.createElement("div", null, "\u{1F986}")))
142
+ /* @__PURE__ */ React.createElement(TestCell, null, /* @__PURE__ */ React.createElement("div", null, "\u{1F986}"))
145
143
  );
146
144
  screen.getByText(/^Look at my beautiful$/);
147
145
  screen.getByText(/^🦆$/);
@@ -156,12 +154,10 @@ describe("createCell", () => {
156
154
  }`,
157
155
  Success: ({ greeting }) => /* @__PURE__ */ React.createElement("p", null, greeting)
158
156
  });
159
- const myUseQueryHook = (_query, options) => {
157
+ mockUseQuery.mockImplementation((_query, options) => {
160
158
  return { data: { greeting: `Hello ${options.variables.name}!` } };
161
- };
162
- render(
163
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, { name: "Bob" }))
164
- );
159
+ });
160
+ render(/* @__PURE__ */ React.createElement(TestCell, { name: "Bob" }));
165
161
  screen.getByText(/^Hello Bob!$/);
166
162
  });
167
163
  test("Allows QUERY to be a function", () => {
@@ -175,16 +171,16 @@ describe("createCell", () => {
175
171
  },
176
172
  Success: ({ name }) => /* @__PURE__ */ React.createElement("p", null, "Call me ", name)
177
173
  });
178
- const myUseQueryHook = (query) => {
174
+ mockUseQuery.mockImplementation((query) => {
179
175
  if (query.includes("BeastQuery")) {
180
176
  return { data: { name: "Boogeyman" } };
181
177
  } else if (query.includes("HeroQuery")) {
182
178
  return { data: { name: "Lara Croft" } };
183
179
  }
184
180
  return { data: { name: "John Doe" } };
185
- };
181
+ });
186
182
  render(
187
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, { character: "BEAST" }), /* @__PURE__ */ React.createElement(TestCell, { character: "HERO" }))
183
+ /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TestCell, { character: "BEAST" }), /* @__PURE__ */ React.createElement(TestCell, { character: "HERO" }))
188
184
  );
189
185
  screen.getByText(/^Call me Boogeyman$/);
190
186
  screen.getByText(/^Call me Lara Croft$/);
@@ -197,10 +193,8 @@ describe("createCell", () => {
197
193
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
198
194
  Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
199
195
  });
200
- const myUseQueryHook = () => ({ error: true });
201
- render(
202
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
203
- );
196
+ mockUseQuery.mockImplementation(() => ({ error: true }));
197
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
204
198
  screen.getByText(/^Sad face :\($/);
205
199
  });
206
200
  test("Passes error to Failure component", () => {
@@ -211,10 +205,10 @@ describe("createCell", () => {
211
205
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
212
206
  Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
213
207
  });
214
- const myUseQueryHook = () => ({ error: { msg: "System malfunction" } });
215
- render(
216
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
217
- );
208
+ mockUseQuery.mockImplementation(() => ({
209
+ error: { msg: "System malfunction" }
210
+ }));
211
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
218
212
  screen.getByText(/^{"msg":"System malfunction"}$/);
219
213
  });
220
214
  test("Passes error and errorCode to Failure component", () => {
@@ -225,13 +219,11 @@ describe("createCell", () => {
225
219
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
226
220
  Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
227
221
  });
228
- const myUseQueryHook = () => ({
222
+ mockUseQuery.mockImplementation(() => ({
229
223
  error: { msg: "System malfunction" },
230
224
  errorCode: "SIMON_SAYS_NO"
231
- });
232
- render(
233
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
234
- );
225
+ }));
226
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
235
227
  screen.getByText(/^{"msg":"System malfunction"},code:SIMON_SAYS_NO$/);
236
228
  });
237
229
  test("Passes children to Failure", () => {
@@ -240,9 +232,9 @@ describe("createCell", () => {
240
232
  QUERY: "query TestQuery { answer }",
241
233
  Failure: ({ children }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "I'm a failure ", children)
242
234
  });
243
- const myUseQueryHook = () => ({ error: {} });
235
+ mockUseQuery.mockImplementation(() => ({ error: {} }));
244
236
  render(
245
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null, /* @__PURE__ */ React.createElement("div", null, "Child")))
237
+ /* @__PURE__ */ React.createElement(TestCell, null, /* @__PURE__ */ React.createElement("div", null, "Child"))
246
238
  );
247
239
  screen.getByText(/^I'm a failure$/);
248
240
  screen.getByText(/^Child$/);
@@ -254,14 +246,14 @@ describe("createCell", () => {
254
246
  Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
255
247
  Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
256
248
  });
257
- const myUseQueryHook = () => ({ error: { message: "200 GraphQL" } });
249
+ mockUseQuery.mockImplementation(() => ({
250
+ error: { message: "200 GraphQL" }
251
+ }));
258
252
  const err = console.error;
259
253
  console.error = vi.fn();
260
254
  let error;
261
255
  try {
262
- render(
263
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
264
- );
256
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
265
257
  } catch (e) {
266
258
  error = e;
267
259
  }
@@ -276,13 +268,11 @@ describe("createCell", () => {
276
268
  Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Got nothing"),
277
269
  isEmpty: () => true
278
270
  });
279
- const myUseQueryHook = () => ({
271
+ mockUseQuery.mockImplementation(() => ({
280
272
  data: {},
281
273
  loading: false
282
- });
283
- render(
284
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
285
- );
274
+ }));
275
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
286
276
  screen.getByText(/^Got nothing$/);
287
277
  });
288
278
  test("Allows mixing isDataEmpty with custom logic", () => {
@@ -293,13 +283,11 @@ describe("createCell", () => {
293
283
  Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Got nothing"),
294
284
  isEmpty: (data, { isDataEmpty }) => isDataEmpty(data) || data.answer === "0"
295
285
  });
296
- const myUseQueryHook = () => ({
286
+ mockUseQuery.mockImplementation(() => ({
297
287
  data: { answer: "0" },
298
288
  loading: false
299
- });
300
- render(
301
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
302
- );
289
+ }));
290
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
303
291
  screen.getByText(/^Got nothing$/);
304
292
  });
305
293
  test("Allows overriding variables in beforeQuery", () => {
@@ -317,12 +305,10 @@ describe("createCell", () => {
317
305
  }
318
306
  })
319
307
  });
320
- const myUseQueryHook = (_query, options) => {
308
+ mockUseQuery.mockImplementation((_query, options) => {
321
309
  return { data: { greeting: `Hello ${options.variables.name}!` } };
322
- };
323
- render(
324
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
325
- );
310
+ });
311
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
326
312
  screen.getByText(/^Hello Bob!$/);
327
313
  });
328
314
  });
@@ -1 +1 @@
1
- {"version":3,"file":"createFragmentCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createFragmentCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAQzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAqDrD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7C,EACA,QAAQ,EACR,UAA2B,EAC3B,OAAqB,EACrB,KAAK,EACL,OAAO,EACP,WAAoB,GACrB,EAAE,eAAe,CAAC,SAAS,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAkEjE"}
1
+ {"version":3,"file":"createFragmentCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createFragmentCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAqDrD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7C,EACA,QAAQ,EACR,UAA2B,EAC3B,OAAqB,EACrB,KAAK,EACL,OAAO,EACP,WAAoB,GACrB,EAAE,eAAe,CAAC,SAAS,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAkEjE"}
@@ -1,7 +1,6 @@
1
1
  import React from "react";
2
2
  import { Kind } from "graphql";
3
- import { fragmentRegistry } from "../../apollo/fragmentRegistry.js";
4
- import { useFragment } from "../GraphQLHooksProvider.js";
3
+ import { fragmentRegistry, useFragment } from "../../apollo/fragmentRegistry.js";
5
4
  import { isDataEmpty } from "./isCellEmpty.js";
6
5
  function getFragmentDefinition(fragment, displayName) {
7
6
  const fragmentDefinition = fragment.definitions.find(
@@ -1,10 +1,25 @@
1
1
  import React from "react";
2
+ import { useApolloClient, useFragment } from "@apollo/client";
3
+ import { useQuery } from "@apollo/client/react/hooks/hooks.cjs";
2
4
  import { render, screen } from "@testing-library/react";
3
5
  import { parse } from "graphql";
4
- import { vi, describe, beforeAll, test, expect } from "vitest";
6
+ import { vi, describe, beforeAll, beforeEach, test, expect } from "vitest";
5
7
  import { fragmentRegistry } from "../../apollo/fragmentRegistry.js";
6
- import { GraphQLHooksProvider } from "../GraphQLHooksProvider.js";
7
8
  import { createCell } from "./createCell.js";
9
+ vi.mock("@apollo/client", async (importOriginal) => {
10
+ const actual = await importOriginal();
11
+ return {
12
+ ...actual,
13
+ useApolloClient: vi.fn(),
14
+ useFragment: vi.fn()
15
+ };
16
+ });
17
+ vi.mock("@apollo/client/react/hooks/hooks.cjs", () => ({
18
+ useQuery: vi.fn()
19
+ }));
20
+ const mockUseApolloClient = useApolloClient;
21
+ const mockApolloUseFragment = useFragment;
22
+ const mockUseQuery = useQuery;
8
23
  const AUTHOR_FRAGMENT = parse(`
9
24
  fragment AuthorCell_author on User {
10
25
  email
@@ -17,71 +32,59 @@ describe("createFragmentCell", () => {
17
32
  RWJS_EXP_STREAMING_SSR: false
18
33
  };
19
34
  });
35
+ beforeEach(() => {
36
+ mockApolloUseFragment.mockReset();
37
+ mockUseApolloClient.mockReset();
38
+ mockUseApolloClient.mockReturnValue({
39
+ cache: {
40
+ identify: (obj) => obj.__typename && obj.id !== void 0 ? `${obj.__typename}:${obj.id}` : void 0
41
+ }
42
+ });
43
+ mockApolloUseFragment.mockReturnValue({ data: void 0, complete: false });
44
+ });
20
45
  test("renders Success with data from its data prop", () => {
21
46
  const TestCell = createCell({
22
47
  FRAGMENT: AUTHOR_FRAGMENT,
23
48
  Success: ({ author }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "By ", author.fullName)
24
49
  });
25
50
  render(
26
- // No useFragment hook registered, so the Cell falls back to reading
27
- // data straight off the `author` prop
28
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: null, useMutation: null }, /* @__PURE__ */ React.createElement(
51
+ /* @__PURE__ */ React.createElement(
29
52
  TestCell,
30
53
  {
31
54
  author: { __typename: "User", id: 1, fullName: "Story Teller" }
32
55
  }
33
- ))
56
+ )
34
57
  );
35
58
  screen.getByText(/^By Story Teller$/);
36
59
  });
37
- test("prefers complete data from the useFragment hook", () => {
60
+ test("prefers complete data from the cache", () => {
38
61
  const TestCell = createCell({
39
62
  FRAGMENT: AUTHOR_FRAGMENT,
40
63
  Success: ({ author }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "By ", author.fullName)
41
64
  });
42
- const myUseFragmentHook = (options) => {
65
+ mockApolloUseFragment.mockImplementation((options) => {
43
66
  expect(options.fragmentName).toEqual("AuthorCell_author");
44
- expect(options.from).toEqual({ __typename: "User", id: 1 });
67
+ expect(options.from).toEqual("User:1");
45
68
  return {
46
69
  data: { fullName: "Cache Dweller" },
47
70
  complete: true
48
71
  };
49
- };
50
- render(
51
- /* @__PURE__ */ React.createElement(
52
- GraphQLHooksProvider,
53
- {
54
- useQuery: null,
55
- useMutation: null,
56
- useFragment: myUseFragmentHook
57
- },
58
- /* @__PURE__ */ React.createElement(TestCell, { author: { __typename: "User", id: 1 } })
59
- )
60
- );
72
+ });
73
+ render(/* @__PURE__ */ React.createElement(TestCell, { author: { __typename: "User", id: 1 } }));
61
74
  screen.getByText(/^By Cache Dweller$/);
62
75
  });
63
- test("falls back to the data prop for incomplete useFragment reads", () => {
76
+ test("falls back to the data prop for incomplete cache reads", () => {
64
77
  const TestCell = createCell({
65
78
  FRAGMENT: AUTHOR_FRAGMENT,
66
79
  Success: ({ author }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "By ", author.fullName)
67
80
  });
68
- const myUseFragmentHook = () => {
69
- return { data: void 0, complete: false };
70
- };
81
+ mockApolloUseFragment.mockReturnValue({ data: void 0, complete: false });
71
82
  render(
72
83
  /* @__PURE__ */ React.createElement(
73
- GraphQLHooksProvider,
84
+ TestCell,
74
85
  {
75
- useQuery: null,
76
- useMutation: null,
77
- useFragment: myUseFragmentHook
78
- },
79
- /* @__PURE__ */ React.createElement(
80
- TestCell,
81
- {
82
- author: { __typename: "User", id: 1, fullName: "Ref Reader" }
83
- }
84
- )
86
+ author: { __typename: "User", id: 1, fullName: "Ref Reader" }
87
+ }
85
88
  )
86
89
  );
87
90
  screen.getByText(/^By Ref Reader$/);
@@ -96,7 +99,7 @@ describe("createFragmentCell", () => {
96
99
  Success: ({ user }) => /* @__PURE__ */ React.createElement(React.Fragment, null, user.bio)
97
100
  });
98
101
  render(
99
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: null, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, { user: { __typename: "User", id: 1, bio: "Writes things" } }))
102
+ /* @__PURE__ */ React.createElement(TestCell, { user: { __typename: "User", id: 1, bio: "Writes things" } })
100
103
  );
101
104
  screen.getByText(/^Writes things$/);
102
105
  });
@@ -108,7 +111,7 @@ describe("createFragmentCell", () => {
108
111
  Success: ({ author }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "By ", author.fullName)
109
112
  });
110
113
  render(
111
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: null, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, { author: { __typename: "User", id: 1, fullName: "Nobody" } }))
114
+ /* @__PURE__ */ React.createElement(TestCell, { author: { __typename: "User", id: 1, fullName: "Nobody" } })
112
115
  );
113
116
  screen.getByText(/^Nothing to see$/);
114
117
  });
@@ -121,12 +124,12 @@ describe("createFragmentCell", () => {
121
124
  Success: ({ author }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "By ", author.fullName)
122
125
  });
123
126
  render(
124
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: null, useMutation: null }, /* @__PURE__ */ React.createElement(
127
+ /* @__PURE__ */ React.createElement(
125
128
  TestCell,
126
129
  {
127
130
  author: { __typename: "User", id: 1, fullName: "Original Name" }
128
131
  }
129
- ))
132
+ )
130
133
  );
131
134
  screen.getByText(/^By Changed Name$/);
132
135
  });
@@ -136,11 +139,7 @@ describe("createFragmentCell", () => {
136
139
  Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No author"),
137
140
  Success: ({ author }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "By ", author.fullName)
138
141
  });
139
- render(
140
- // A nullable field, or a partial error with `errorPolicy: 'all'`, can
141
- // make the parent pass null here
142
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: null, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, { author: null }))
143
- );
142
+ render(/* @__PURE__ */ React.createElement(TestCell, { author: null }));
144
143
  screen.getByText(/^No author$/);
145
144
  });
146
145
  test("renders Success with null data when the data prop is null and there is no Empty", () => {
@@ -148,9 +147,7 @@ describe("createFragmentCell", () => {
148
147
  FRAGMENT: AUTHOR_FRAGMENT,
149
148
  Success: ({ author }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "By ", author?.fullName ?? "unknown")
150
149
  });
151
- render(
152
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: null, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, { author: null }))
153
- );
150
+ render(/* @__PURE__ */ React.createElement(TestCell, { author: null }));
154
151
  screen.getByText(/^By unknown$/);
155
152
  });
156
153
  test("throws a helpful error naming the prop when it is not passed", () => {
@@ -163,9 +160,7 @@ describe("createFragmentCell", () => {
163
160
  });
164
161
  try {
165
162
  expect(() => {
166
- render(
167
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: null, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
168
- );
163
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
169
164
  }).toThrow(/`author` prop/);
170
165
  } finally {
171
166
  consoleErrorSpy.mockRestore();
@@ -178,12 +173,10 @@ describe("createFragmentCell", () => {
178
173
  FRAGMENT: AUTHOR_FRAGMENT,
179
174
  Success: ({ author }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "By ", author.fullName)
180
175
  });
181
- const myUseQueryHook = () => {
176
+ mockUseQuery.mockImplementation(() => {
182
177
  return { data: { author: { fullName: "Query Result" } } };
183
- };
184
- render(
185
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
186
- );
178
+ });
179
+ render(/* @__PURE__ */ React.createElement(TestCell, null));
187
180
  screen.getByText(/^By Query Result$/);
188
181
  });
189
182
  test("registers the FRAGMENT even when the Cell stays a query Cell", () => {
@@ -1 +1 @@
1
- {"version":3,"file":"createSuspendingCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createSuspendingCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAYvC,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,gBAAgB,CAAA;AAGvB,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AACrC;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,SAAS,MAAM,EACxB,aAAa,SAAS,MAAM,EAE5B,eAAe,EAAE,eAAe,CAAC,MAAM,EAAE,aAAa,CAAC,GACtD,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAiJrB"}
1
+ {"version":3,"file":"createSuspendingCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createSuspendingCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAWvC,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,gBAAgB,CAAA;AAGvB,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AACrC;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,SAAS,MAAM,EACxB,aAAa,SAAS,MAAM,EAE5B,eAAe,EAAE,eAAe,CAAC,MAAM,EAAE,aAAa,CAAC,GACtD,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAiJrB"}
@@ -1,6 +1,9 @@
1
1
  import React, { Suspense } from "react";
2
- import { useApolloClient } from "@apollo/client/react/hooks/hooks.cjs";
3
- import { useBackgroundQuery, useReadQuery } from "../GraphQLHooksProvider.js";
2
+ import {
3
+ useApolloClient,
4
+ useBackgroundQuery,
5
+ useReadQuery
6
+ } from "@apollo/client/react/hooks/hooks.cjs";
4
7
  import { CellErrorBoundary } from "./CellErrorBoundary.js";
5
8
  import { isDataEmpty } from "./isCellEmpty.js";
6
9
  function createSuspendingCell(createCellProps) {