@cedarjs/web 5.0.3 → 5.0.4-next.167

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 (188) hide show
  1. package/dist/apollo/ApolloProviderWithFetchConfig.d.ts +15 -0
  2. package/dist/apollo/ApolloProviderWithFetchConfig.d.ts.map +1 -0
  3. package/dist/apollo/ApolloProviderWithFetchConfig.js +134 -0
  4. package/dist/apollo/CedarApolloProvider.d.ts +14 -0
  5. package/dist/apollo/CedarApolloProvider.d.ts.map +1 -0
  6. package/dist/apollo/CedarApolloProvider.js +35 -0
  7. package/dist/apollo/ErrorBoundary.d.ts +13 -0
  8. package/dist/apollo/ErrorBoundary.d.ts.map +1 -0
  9. package/dist/apollo/ErrorBoundary.js +13 -0
  10. package/dist/{cjs/apollo/suspense.d.ts → apollo/apolloLinkTypes.d.ts} +22 -22
  11. package/dist/apollo/apolloLinkTypes.d.ts.map +1 -0
  12. package/dist/apollo/fragmentRegistry.d.ts +25 -0
  13. package/dist/apollo/fragmentRegistry.d.ts.map +1 -1
  14. package/dist/apollo/fragmentRegistry.js +19 -1
  15. package/dist/apollo/index.d.ts +50 -70
  16. package/dist/apollo/index.d.ts.map +1 -1
  17. package/dist/apollo/index.js +2 -184
  18. package/dist/apollo/suspense.d.ts +16 -7
  19. package/dist/apollo/suspense.d.ts.map +1 -1
  20. package/dist/apollo/suspense.js +9 -26
  21. package/dist/bins/cedar.js +14 -0
  22. package/dist/bins/cfw.js +14 -0
  23. package/dist/bins/cross-env.js +8 -0
  24. package/dist/bins/msw.js +6 -0
  25. package/dist/bins/redwood.js +14 -0
  26. package/dist/bins/storybook.js +27 -0
  27. package/dist/bins/tsc.js +8 -0
  28. package/dist/bundled/apollo-upload-client.js +2899 -1
  29. package/dist/components/FetchConfigProvider.d.ts +3 -2
  30. package/dist/components/FetchConfigProvider.d.ts.map +1 -1
  31. package/dist/components/cell/CellErrorBoundary.d.ts +3 -2
  32. package/dist/components/cell/CellErrorBoundary.d.ts.map +1 -1
  33. package/dist/components/cell/cellTypes.d.ts +17 -4
  34. package/dist/components/cell/cellTypes.d.ts.map +1 -1
  35. package/dist/components/cell/createCell.d.ts +1 -7
  36. package/dist/components/cell/createCell.d.ts.map +1 -1
  37. package/dist/components/cell/createCell.js +22 -3
  38. package/dist/components/cell/createFragmentCell.d.ts +19 -0
  39. package/dist/components/cell/createFragmentCell.d.ts.map +1 -0
  40. package/dist/components/cell/createFragmentCell.js +73 -0
  41. package/dist/components/cell/createSuspendingCell.d.ts.map +1 -1
  42. package/dist/components/cell/createSuspendingCell.js +12 -3
  43. package/dist/global.web-auto-imports.d.ts +0 -16
  44. package/dist/global.web-auto-imports.d.ts.map +1 -1
  45. package/dist/index.d.ts +5 -2
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +5 -3
  48. package/package.json +48 -106
  49. package/dist/apollo/typeOverride.d.ts +0 -21
  50. package/dist/apollo/typeOverride.d.ts.map +0 -1
  51. package/dist/cjs/apollo/fragmentRegistry.d.ts +0 -43
  52. package/dist/cjs/apollo/fragmentRegistry.d.ts.map +0 -1
  53. package/dist/cjs/apollo/fragmentRegistry.js +0 -75
  54. package/dist/cjs/apollo/index.d.ts +0 -76
  55. package/dist/cjs/apollo/index.d.ts.map +0 -1
  56. package/dist/cjs/apollo/index.js +0 -218
  57. package/dist/cjs/apollo/links.d.ts +0 -27
  58. package/dist/cjs/apollo/links.d.ts.map +0 -1
  59. package/dist/cjs/apollo/links.js +0 -122
  60. package/dist/cjs/apollo/sseLink.d.ts +0 -29
  61. package/dist/cjs/apollo/sseLink.d.ts.map +0 -1
  62. package/dist/cjs/apollo/sseLink.js +0 -120
  63. package/dist/cjs/apollo/suspense.d.ts.map +0 -1
  64. package/dist/cjs/apollo/suspense.js +0 -127
  65. package/dist/cjs/apollo/typeOverride.d.ts +0 -21
  66. package/dist/cjs/apollo/typeOverride.d.ts.map +0 -1
  67. package/dist/cjs/apollo/typeOverride.js +0 -16
  68. package/dist/cjs/apollo/useCache.d.ts +0 -22
  69. package/dist/cjs/apollo/useCache.d.ts.map +0 -1
  70. package/dist/cjs/apollo/useCache.js +0 -49
  71. package/dist/cjs/bins/cedar.d.ts +0 -9
  72. package/dist/cjs/bins/cedar.d.ts.map +0 -1
  73. package/dist/cjs/bins/cedar.js +0 -36
  74. package/dist/cjs/bins/cfw.d.ts +0 -3
  75. package/dist/cjs/bins/cfw.d.ts.map +0 -1
  76. package/dist/cjs/bins/cfw.js +0 -36
  77. package/dist/cjs/bins/cross-env.d.ts +0 -3
  78. package/dist/cjs/bins/cross-env.d.ts.map +0 -1
  79. package/dist/cjs/bins/cross-env.js +0 -30
  80. package/dist/cjs/bins/msw.d.ts +0 -3
  81. package/dist/cjs/bins/msw.d.ts.map +0 -1
  82. package/dist/cjs/bins/msw.js +0 -28
  83. package/dist/cjs/bins/redwood.d.ts +0 -9
  84. package/dist/cjs/bins/redwood.d.ts.map +0 -1
  85. package/dist/cjs/bins/redwood.js +0 -36
  86. package/dist/cjs/bins/storybook.d.ts +0 -3
  87. package/dist/cjs/bins/storybook.d.ts.map +0 -1
  88. package/dist/cjs/bins/storybook.js +0 -49
  89. package/dist/cjs/bins/tsc.d.ts +0 -3
  90. package/dist/cjs/bins/tsc.d.ts.map +0 -1
  91. package/dist/cjs/bins/tsc.js +0 -30
  92. package/dist/cjs/bundled/apollo-upload-client.d.ts +0 -3
  93. package/dist/cjs/bundled/apollo-upload-client.d.ts.map +0 -1
  94. package/dist/cjs/bundled/apollo-upload-client.js +0 -2925
  95. package/dist/cjs/components/DevFatalErrorPage.d.ts +0 -21
  96. package/dist/cjs/components/DevFatalErrorPage.d.ts.map +0 -1
  97. package/dist/cjs/components/DevFatalErrorPage.js +0 -552
  98. package/dist/cjs/components/FatalErrorBoundary.d.ts +0 -24
  99. package/dist/cjs/components/FatalErrorBoundary.d.ts.map +0 -1
  100. package/dist/cjs/components/FatalErrorBoundary.js +0 -63
  101. package/dist/cjs/components/FetchConfigProvider.d.ts +0 -25
  102. package/dist/cjs/components/FetchConfigProvider.d.ts.map +0 -1
  103. package/dist/cjs/components/FetchConfigProvider.js +0 -80
  104. package/dist/cjs/components/GraphQLHooksProvider.d.ts +0 -45
  105. package/dist/cjs/components/GraphQLHooksProvider.d.ts.map +0 -1
  106. package/dist/cjs/components/GraphQLHooksProvider.js +0 -135
  107. package/dist/cjs/components/MetaTags.d.ts +0 -52
  108. package/dist/cjs/components/MetaTags.d.ts.map +0 -1
  109. package/dist/cjs/components/MetaTags.js +0 -68
  110. package/dist/cjs/components/Metadata.d.ts +0 -9
  111. package/dist/cjs/components/Metadata.d.ts.map +0 -1
  112. package/dist/cjs/components/Metadata.js +0 -94
  113. package/dist/cjs/components/PortalHead.d.ts +0 -4
  114. package/dist/cjs/components/PortalHead.d.ts.map +0 -1
  115. package/dist/cjs/components/PortalHead.js +0 -59
  116. package/dist/cjs/components/RedwoodProvider.d.ts +0 -9
  117. package/dist/cjs/components/RedwoodProvider.d.ts.map +0 -1
  118. package/dist/cjs/components/RedwoodProvider.js +0 -57
  119. package/dist/cjs/components/ServerInject.d.ts +0 -26
  120. package/dist/cjs/components/ServerInject.d.ts.map +0 -1
  121. package/dist/cjs/components/ServerInject.js +0 -75
  122. package/dist/cjs/components/cell/CellCacheContext.d.ts +0 -20
  123. package/dist/cjs/components/cell/CellCacheContext.d.ts.map +0 -1
  124. package/dist/cjs/components/cell/CellCacheContext.js +0 -53
  125. package/dist/cjs/components/cell/CellErrorBoundary.d.ts +0 -25
  126. package/dist/cjs/components/cell/CellErrorBoundary.d.ts.map +0 -1
  127. package/dist/cjs/components/cell/CellErrorBoundary.js +0 -66
  128. package/dist/cjs/components/cell/cellTypes.d.ts +0 -152
  129. package/dist/cjs/components/cell/cellTypes.d.ts.map +0 -1
  130. package/dist/cjs/components/cell/cellTypes.js +0 -16
  131. package/dist/cjs/components/cell/createCell.d.ts +0 -10
  132. package/dist/cjs/components/cell/createCell.d.ts.map +0 -1
  133. package/dist/cjs/components/cell/createCell.js +0 -165
  134. package/dist/cjs/components/cell/createCell.test.js +0 -351
  135. package/dist/cjs/components/cell/createServerCell.d.ts +0 -15
  136. package/dist/cjs/components/cell/createServerCell.d.ts.map +0 -1
  137. package/dist/cjs/components/cell/createServerCell.js +0 -91
  138. package/dist/cjs/components/cell/createSuspendingCell.d.ts +0 -11
  139. package/dist/cjs/components/cell/createSuspendingCell.d.ts.map +0 -1
  140. package/dist/cjs/components/cell/createSuspendingCell.js +0 -152
  141. package/dist/cjs/components/cell/createSuspendingCell.test.js +0 -115
  142. package/dist/cjs/components/cell/isCellEmpty.d.ts +0 -41
  143. package/dist/cjs/components/cell/isCellEmpty.d.ts.map +0 -1
  144. package/dist/cjs/components/cell/isCellEmpty.js +0 -35
  145. package/dist/cjs/components/htmlTags.d.ts +0 -52
  146. package/dist/cjs/components/htmlTags.d.ts.map +0 -1
  147. package/dist/cjs/components/htmlTags.js +0 -88
  148. package/dist/cjs/config.d.ts +0 -2
  149. package/dist/cjs/config.d.ts.map +0 -1
  150. package/dist/cjs/config.js +0 -6
  151. package/dist/cjs/global.web-auto-imports.d.ts +0 -30
  152. package/dist/cjs/global.web-auto-imports.d.ts.map +0 -1
  153. package/dist/cjs/global.web-auto-imports.js +0 -16
  154. package/dist/cjs/graphql.d.ts +0 -23
  155. package/dist/cjs/graphql.d.ts.map +0 -1
  156. package/dist/cjs/graphql.js +0 -36
  157. package/dist/cjs/index.d.ts +0 -19
  158. package/dist/cjs/index.d.ts.map +0 -1
  159. package/dist/cjs/index.js +0 -69
  160. package/dist/cjs/package.json +0 -1
  161. package/dist/cjs/routeHooks.types.d.ts +0 -12
  162. package/dist/cjs/routeHooks.types.d.ts.map +0 -1
  163. package/dist/cjs/routeHooks.types.js +0 -16
  164. package/dist/cjs/server/MiddlewareRequest.d.ts +0 -28
  165. package/dist/cjs/server/MiddlewareRequest.d.ts.map +0 -1
  166. package/dist/cjs/server/MiddlewareRequest.js +0 -71
  167. package/dist/cjs/server/MiddlewareResponse.d.ts +0 -44
  168. package/dist/cjs/server/MiddlewareResponse.d.ts.map +0 -1
  169. package/dist/cjs/server/MiddlewareResponse.js +0 -130
  170. package/dist/cjs/server/middleware.d.ts +0 -17
  171. package/dist/cjs/server/middleware.d.ts.map +0 -1
  172. package/dist/cjs/server/middleware.js +0 -24
  173. package/dist/cjs/server/request.d.ts +0 -2
  174. package/dist/cjs/server/request.d.ts.map +0 -1
  175. package/dist/cjs/server/request.js +0 -34
  176. package/dist/cjs/streamUtils/useDocumentReady.d.ts +0 -11
  177. package/dist/cjs/streamUtils/useDocumentReady.d.ts.map +0 -1
  178. package/dist/cjs/streamUtils/useDocumentReady.js +0 -41
  179. package/dist/cjs/toast/index.d.ts +0 -3
  180. package/dist/cjs/toast/index.d.ts.map +0 -1
  181. package/dist/cjs/toast/index.js +0 -41
  182. package/dist/components/GraphQLHooksProvider.d.ts +0 -45
  183. package/dist/components/GraphQLHooksProvider.d.ts.map +0 -1
  184. package/dist/components/GraphQLHooksProvider.js +0 -94
  185. package/dist/components/cell/createCell.test.js +0 -328
  186. package/dist/components/cell/createSuspendingCell.test.js +0 -92
  187. package/dist/package.json +0 -1
  188. /package/dist/apollo/{typeOverride.js → apolloLinkTypes.js} +0 -0
@@ -1,94 +0,0 @@
1
- import React from "react";
2
- const GraphQLHooksContext = React.createContext({
3
- useQuery: () => {
4
- throw new Error(
5
- "You must register a useQuery hook via the `GraphQLHooksProvider`"
6
- );
7
- },
8
- useMutation: () => {
9
- throw new Error(
10
- "You must register a useMutation hook via the `GraphQLHooksProvider`"
11
- );
12
- },
13
- useSubscription: () => {
14
- throw new Error(
15
- "You must register a useSubscription hook via the `GraphQLHooksProvider`"
16
- );
17
- },
18
- useSuspenseQuery: () => {
19
- throw new Error(
20
- "You must register a useSuspenseQuery hook via the `GraphQLHooksProvider`."
21
- );
22
- },
23
- // These are apollo specific hooks!
24
- useBackgroundQuery: () => {
25
- throw new Error(
26
- "You must register a useBackgroundQuery hook via the `GraphQLHooksProvider`."
27
- );
28
- },
29
- useReadQuery: () => {
30
- throw new Error(
31
- "You must register a useReadQuery hook via the `GraphQLHooksProvider`."
32
- );
33
- }
34
- });
35
- const GraphQLHooksProvider = ({
36
- useQuery: useQuery2,
37
- useMutation: useMutation2,
38
- useSubscription: useSubscription2,
39
- useSuspenseQuery: useSuspenseQuery2,
40
- useBackgroundQuery: useBackgroundQuery2,
41
- useReadQuery: useReadQuery2,
42
- children
43
- }) => {
44
- return /* @__PURE__ */ React.createElement(
45
- GraphQLHooksContext.Provider,
46
- {
47
- value: {
48
- useQuery: useQuery2,
49
- useMutation: useMutation2,
50
- useSubscription: useSubscription2,
51
- useSuspenseQuery: useSuspenseQuery2,
52
- useBackgroundQuery: useBackgroundQuery2,
53
- useReadQuery: useReadQuery2
54
- }
55
- },
56
- children
57
- );
58
- };
59
- function useQuery(query, options) {
60
- return React.useContext(GraphQLHooksContext).useQuery(
61
- query,
62
- options
63
- );
64
- }
65
- function useMutation(mutation, options) {
66
- return React.useContext(GraphQLHooksContext).useMutation(
67
- mutation,
68
- options
69
- );
70
- }
71
- function useSubscription(query, options) {
72
- return React.useContext(GraphQLHooksContext).useSubscription(query, options);
73
- }
74
- function useSuspenseQuery(query, options) {
75
- return React.useContext(GraphQLHooksContext).useSuspenseQuery(query, options);
76
- }
77
- const useBackgroundQuery = (...args) => {
78
- return React.useContext(GraphQLHooksContext).useBackgroundQuery(
79
- ...args
80
- );
81
- };
82
- const useReadQuery = (...args) => {
83
- return React.useContext(GraphQLHooksContext).useReadQuery(...args);
84
- };
85
- export {
86
- GraphQLHooksContext,
87
- GraphQLHooksProvider,
88
- useBackgroundQuery,
89
- useMutation,
90
- useQuery,
91
- useReadQuery,
92
- useSubscription,
93
- useSuspenseQuery
94
- };
@@ -1,328 +0,0 @@
1
- import React from "react";
2
- import { render, screen } from "@testing-library/react";
3
- import { vi, describe, beforeAll, test, expect } from "vitest";
4
- import { GraphQLHooksProvider } from "../GraphQLHooksProvider.js";
5
- import { createCell } from "./createCell.js";
6
- describe("createCell", () => {
7
- beforeAll(() => {
8
- globalThis.RWJS_ENV = {
9
- RWJS_EXP_STREAMING_SSR: false
10
- };
11
- });
12
- test("Renders a static Success component", () => {
13
- const TestCell = createCell({
14
- // @ts-expect-error - Purposefully using a plain string here.
15
- QUERY: "query TestQuery { answer }",
16
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!")
17
- });
18
- const myUseQueryHook = () => ({ data: {} });
19
- render(
20
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
21
- );
22
- screen.getByText(/^Great success!$/);
23
- });
24
- test("Renders Success with data", () => {
25
- const TestCell = createCell({
26
- // @ts-expect-error - Purposefully using a plain string here.
27
- QUERY: "query TestQuery { answer }",
28
- 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
- });
30
- const myUseQueryHook = () => {
31
- return { data: { answer: 42 } };
32
- };
33
- render(
34
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
35
- );
36
- screen.getByText(/^What's the meaning of life\?$/);
37
- screen.getByText(/^42$/);
38
- });
39
- test("Renders Success if any of the fields have data (i.e. not just the first)", () => {
40
- const TestCell = createCell({
41
- // @ts-expect-error - Purposefully using a plain string here.
42
- QUERY: "query TestQuery { users { name } posts { title } }",
43
- Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No users or posts"),
44
- 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
- });
46
- const myUseQueryHook = () => {
47
- return {
48
- data: {
49
- users: [],
50
- posts: [{ title: "bazinga" }, { title: "kittens" }]
51
- }
52
- };
53
- };
54
- render(
55
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
56
- );
57
- screen.getByText(/bazinga/);
58
- screen.getByText(/kittens/);
59
- });
60
- test("Renders default Loading when there is no data", () => {
61
- const TestCell = createCell({
62
- // @ts-expect-error - Purposefully using a plain string here.
63
- QUERY: "query TestQuery { answer }",
64
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!")
65
- });
66
- const myUseQueryHook = () => ({ loading: true });
67
- render(
68
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
69
- );
70
- screen.getByText(/^Loading...$/);
71
- });
72
- test("Renders custom Loading when there is no data", () => {
73
- const TestCell = createCell({
74
- // @ts-expect-error - Purposefully using a plain string here.
75
- QUERY: "query TestQuery { answer }",
76
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
77
- Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
78
- });
79
- const myUseQueryHook = () => ({ loading: true });
80
- render(
81
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
82
- );
83
- screen.getByText(/^Fetching answer...$/);
84
- });
85
- test("Renders Success even when `loading` is true if there is data", () => {
86
- const TestCell = createCell({
87
- // @ts-expect-error - Purposefully using a plain string here.
88
- QUERY: "query TestQuery { answer }",
89
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
90
- Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
91
- });
92
- const myUseQueryHook = () => ({ loading: true, data: {} });
93
- render(
94
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
95
- );
96
- screen.getByText(/^Great success!$/);
97
- });
98
- test("Renders Empty if available, and data field is null", () => {
99
- const TestCell = createCell({
100
- // @ts-expect-error - Purposefully using a plain string here.
101
- QUERY: "query TestQuery { answer }",
102
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
103
- Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No one knows")
104
- });
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
- );
109
- screen.getByText(/^No one knows$/);
110
- });
111
- test("Renders Empty if available, and data field is an empty array", () => {
112
- const TestCell = createCell({
113
- // @ts-expect-error - Purposefully using a plain string here.
114
- QUERY: "query TestQuery { answers }",
115
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
116
- Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No one knows")
117
- });
118
- const myUseQueryHook = () => ({ loading: true, data: { answers: [] } });
119
- render(
120
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
121
- );
122
- screen.getByText(/^No one knows$/);
123
- });
124
- test("Renders Success even if data is empty when no Empty is available", () => {
125
- const TestCell = createCell({
126
- // @ts-expect-error - Purposefully using a plain string here.
127
- QUERY: "query TestQuery { answer }",
128
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Empty success")
129
- });
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
- );
134
- screen.getByText(/^Empty success$/);
135
- });
136
- test("Allows passing children to Success", () => {
137
- const TestCell = createCell({
138
- // @ts-expect-error - Purposefully using a plain string here.
139
- QUERY: "query TestQuery { answer }",
140
- Success: ({ children }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "Look at my beautiful ", children)
141
- });
142
- const myUseQueryHook = () => ({ data: {} });
143
- render(
144
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null, /* @__PURE__ */ React.createElement("div", null, "\u{1F986}")))
145
- );
146
- screen.getByText(/^Look at my beautiful$/);
147
- screen.getByText(/^🦆$/);
148
- });
149
- test("Cell props are passed to the query as variables", () => {
150
- const TestCell = createCell({
151
- // @ts-expect-error - Purposefully using a plain string here.
152
- QUERY: `query Greet($name: String!) {
153
- greet(name: $name) {
154
- greeting
155
- }
156
- }`,
157
- Success: ({ greeting }) => /* @__PURE__ */ React.createElement("p", null, greeting)
158
- });
159
- const myUseQueryHook = (_query, options) => {
160
- 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
- );
165
- screen.getByText(/^Hello Bob!$/);
166
- });
167
- test("Allows QUERY to be a function", () => {
168
- const TestCell = createCell({
169
- // @ts-expect-error - Purposefully using a plain string here.
170
- QUERY: ({ variables }) => {
171
- if (variables.character === "BEAST") {
172
- return "query BeastQuery { name }";
173
- }
174
- return "query HeroQuery { name }";
175
- },
176
- Success: ({ name }) => /* @__PURE__ */ React.createElement("p", null, "Call me ", name)
177
- });
178
- const myUseQueryHook = (query) => {
179
- if (query.includes("BeastQuery")) {
180
- return { data: { name: "Boogeyman" } };
181
- } else if (query.includes("HeroQuery")) {
182
- return { data: { name: "Lara Croft" } };
183
- }
184
- return { data: { name: "John Doe" } };
185
- };
186
- render(
187
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, { character: "BEAST" }), /* @__PURE__ */ React.createElement(TestCell, { character: "HERO" }))
188
- );
189
- screen.getByText(/^Call me Boogeyman$/);
190
- screen.getByText(/^Call me Lara Croft$/);
191
- });
192
- test("Renders Failure when there is an error", () => {
193
- const TestCell = createCell({
194
- // @ts-expect-error - Purposefully using a plain string here.
195
- QUERY: "query TestQuery { answer }",
196
- Failure: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Sad face :("),
197
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
198
- Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
199
- });
200
- const myUseQueryHook = () => ({ error: true });
201
- render(
202
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
203
- );
204
- screen.getByText(/^Sad face :\($/);
205
- });
206
- test("Passes error to Failure component", () => {
207
- const TestCell = createCell({
208
- // @ts-expect-error - Purposefully using a plain string here.
209
- QUERY: "query TestQuery { answer }",
210
- Failure: ({ error }) => /* @__PURE__ */ React.createElement(React.Fragment, null, JSON.stringify(error)),
211
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
212
- Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
213
- });
214
- const myUseQueryHook = () => ({ error: { msg: "System malfunction" } });
215
- render(
216
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
217
- );
218
- screen.getByText(/^{"msg":"System malfunction"}$/);
219
- });
220
- test("Passes error and errorCode to Failure component", () => {
221
- const TestCell = createCell({
222
- // @ts-expect-error - Purposefully using a plain string here.
223
- QUERY: "query TestQuery { answer }",
224
- Failure: ({ error, errorCode }) => /* @__PURE__ */ React.createElement(React.Fragment, null, JSON.stringify(error), ",code:", errorCode),
225
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
226
- Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
227
- });
228
- const myUseQueryHook = () => ({
229
- error: { msg: "System malfunction" },
230
- errorCode: "SIMON_SAYS_NO"
231
- });
232
- render(
233
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
234
- );
235
- screen.getByText(/^{"msg":"System malfunction"},code:SIMON_SAYS_NO$/);
236
- });
237
- test("Passes children to Failure", () => {
238
- const TestCell = createCell({
239
- // @ts-expect-error - Purposefully using a plain string here.
240
- QUERY: "query TestQuery { answer }",
241
- Failure: ({ children }) => /* @__PURE__ */ React.createElement(React.Fragment, null, "I'm a failure ", children)
242
- });
243
- const myUseQueryHook = () => ({ error: {} });
244
- render(
245
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null, /* @__PURE__ */ React.createElement("div", null, "Child")))
246
- );
247
- screen.getByText(/^I'm a failure$/);
248
- screen.getByText(/^Child$/);
249
- });
250
- test("Throws an error when there is an error if no Failure component exists", () => {
251
- const TestCell = createCell({
252
- // @ts-expect-error - Purposefully using a plain string here.
253
- QUERY: "query TestQuery { answer }",
254
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
255
- Loading: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Fetching answer...")
256
- });
257
- const myUseQueryHook = () => ({ error: { message: "200 GraphQL" } });
258
- const err = console.error;
259
- console.error = vi.fn();
260
- let error;
261
- try {
262
- render(
263
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
264
- );
265
- } catch (e) {
266
- error = e;
267
- }
268
- expect(error.message).toEqual("200 GraphQL");
269
- console.error = err;
270
- });
271
- test("Allows overriding of default isDataEmpty", () => {
272
- const TestCell = createCell({
273
- // @ts-expect-error - Purposefully using a plain string here.
274
- QUERY: "query TestQuery { answer }",
275
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
276
- Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Got nothing"),
277
- isEmpty: () => true
278
- });
279
- const myUseQueryHook = () => ({
280
- data: {},
281
- loading: false
282
- });
283
- render(
284
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
285
- );
286
- screen.getByText(/^Got nothing$/);
287
- });
288
- test("Allows mixing isDataEmpty with custom logic", () => {
289
- const TestCell = createCell({
290
- // @ts-expect-error - Purposefully using a plain string here.
291
- QUERY: "query TestQuery { answer }",
292
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!"),
293
- Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Got nothing"),
294
- isEmpty: (data, { isDataEmpty }) => isDataEmpty(data) || data.answer === "0"
295
- });
296
- const myUseQueryHook = () => ({
297
- data: { answer: "0" },
298
- loading: false
299
- });
300
- render(
301
- /* @__PURE__ */ React.createElement(GraphQLHooksProvider, { useQuery: myUseQueryHook, useMutation: null }, /* @__PURE__ */ React.createElement(TestCell, null))
302
- );
303
- screen.getByText(/^Got nothing$/);
304
- });
305
- test("Allows overriding variables in beforeQuery", () => {
306
- const TestCell = createCell({
307
- // @ts-expect-error - Purposefully using a plain string here.
308
- QUERY: `query Greet($name: String!) {
309
- greet(name: $name) {
310
- greeting
311
- }
312
- }`,
313
- Success: ({ greeting }) => /* @__PURE__ */ React.createElement("p", null, greeting),
314
- beforeQuery: () => ({
315
- variables: {
316
- name: "Bob"
317
- }
318
- })
319
- });
320
- const myUseQueryHook = (_query, options) => {
321
- 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
- );
326
- screen.getByText(/^Hello Bob!$/);
327
- });
328
- });
@@ -1,92 +0,0 @@
1
- import React from "react";
2
- import { loadErrorMessages, loadDevMessages } from "@apollo/client/dev";
3
- import { render, screen } from "@testing-library/react";
4
- import { vi, describe, beforeAll, test } from "vitest";
5
- import { GraphQLHooksProvider } from "../GraphQLHooksProvider.js";
6
- import { createSuspendingCell } from "./createSuspendingCell.js";
7
- vi.mock("@apollo/client/react/hooks/hooks.cjs", () => {
8
- return {
9
- useApolloClient: vi.fn()
10
- };
11
- });
12
- describe("createSuspendingCell", () => {
13
- beforeAll(() => {
14
- globalThis.RWJS_ENV = {
15
- RWJS_EXP_STREAMING_SSR: true
16
- };
17
- loadDevMessages();
18
- loadErrorMessages();
19
- });
20
- const mockedUseBgQuery = (() => {
21
- return ["mocked-query-ref", { refetch: vi.fn(), fetchMore: vi.fn() }];
22
- });
23
- const mockedQueryHook = () => ({ data: {} });
24
- test("Renders a static Success component", () => {
25
- const TestCell = createSuspendingCell({
26
- // @ts-expect-error - Purposefully using a plain string here.
27
- QUERY: "query TestQuery { answer }",
28
- Success: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "Great success!")
29
- });
30
- render(
31
- /* @__PURE__ */ React.createElement(
32
- GraphQLHooksProvider,
33
- {
34
- useBackgroundQuery: mockedUseBgQuery,
35
- useReadQuery: mockedQueryHook
36
- },
37
- /* @__PURE__ */ React.createElement(TestCell, null)
38
- )
39
- );
40
- screen.getByText(/^Great success!$/);
41
- });
42
- test("Renders Success with data", () => {
43
- const TestCell = createSuspendingCell({
44
- // @ts-expect-error - Purposefully using a plain string here.
45
- QUERY: "query TestQuery { answer }",
46
- 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)))
47
- });
48
- const myUseQueryHook = (() => {
49
- return { data: { answer: 42 } };
50
- });
51
- render(
52
- /* @__PURE__ */ React.createElement(
53
- GraphQLHooksProvider,
54
- {
55
- useReadQuery: myUseQueryHook,
56
- useBackgroundQuery: mockedUseBgQuery
57
- },
58
- /* @__PURE__ */ React.createElement(TestCell, null)
59
- )
60
- );
61
- screen.getByText(/^What's the meaning of life\?$/);
62
- screen.getByText(/^42$/);
63
- });
64
- test("Renders Success if any of the fields have data (i.e. not just the first)", () => {
65
- const TestCell = createSuspendingCell({
66
- // @ts-expect-error - Purposefully using a plain string here.
67
- QUERY: "query TestQuery { users { name } posts { title } }",
68
- Empty: () => /* @__PURE__ */ React.createElement(React.Fragment, null, "No users or posts"),
69
- 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"))
70
- });
71
- const myReadQueryHook = (() => {
72
- return {
73
- data: {
74
- users: [],
75
- posts: [{ title: "bazinga" }, { title: "kittens" }]
76
- }
77
- };
78
- });
79
- render(
80
- /* @__PURE__ */ React.createElement(
81
- GraphQLHooksProvider,
82
- {
83
- useReadQuery: myReadQueryHook,
84
- useBackgroundQuery: mockedUseBgQuery
85
- },
86
- /* @__PURE__ */ React.createElement(TestCell, null)
87
- )
88
- );
89
- screen.getByText(/bazinga/);
90
- screen.getByText(/kittens/);
91
- });
92
- });
package/dist/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"module"}