@cedarjs/web 5.0.4-next.167 → 5.0.4
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.
- package/dist/apollo/fragmentRegistry.d.ts +0 -25
- package/dist/apollo/fragmentRegistry.d.ts.map +1 -1
- package/dist/apollo/fragmentRegistry.js +1 -19
- package/dist/apollo/index.d.ts +70 -50
- package/dist/apollo/index.d.ts.map +1 -1
- package/dist/apollo/index.js +184 -2
- package/dist/apollo/suspense.d.ts +7 -16
- package/dist/apollo/suspense.d.ts.map +1 -1
- package/dist/apollo/suspense.js +26 -9
- package/dist/apollo/typeOverride.d.ts +21 -0
- package/dist/apollo/typeOverride.d.ts.map +1 -0
- package/dist/bundled/apollo-upload-client.js +1 -2899
- package/dist/cjs/apollo/fragmentRegistry.d.ts +43 -0
- package/dist/cjs/apollo/fragmentRegistry.d.ts.map +1 -0
- package/dist/cjs/apollo/fragmentRegistry.js +75 -0
- package/dist/cjs/apollo/index.d.ts +76 -0
- package/dist/cjs/apollo/index.d.ts.map +1 -0
- package/dist/cjs/apollo/index.js +218 -0
- package/dist/cjs/apollo/links.d.ts +27 -0
- package/dist/cjs/apollo/links.d.ts.map +1 -0
- package/dist/cjs/apollo/links.js +122 -0
- package/dist/cjs/apollo/sseLink.d.ts +29 -0
- package/dist/cjs/apollo/sseLink.d.ts.map +1 -0
- package/dist/cjs/apollo/sseLink.js +120 -0
- package/dist/{apollo/apolloLinkTypes.d.ts → cjs/apollo/suspense.d.ts} +22 -22
- package/dist/cjs/apollo/suspense.d.ts.map +1 -0
- package/dist/cjs/apollo/suspense.js +127 -0
- package/dist/cjs/apollo/typeOverride.d.ts +21 -0
- package/dist/cjs/apollo/typeOverride.d.ts.map +1 -0
- package/dist/cjs/apollo/typeOverride.js +16 -0
- package/dist/cjs/apollo/useCache.d.ts +22 -0
- package/dist/cjs/apollo/useCache.d.ts.map +1 -0
- package/dist/cjs/apollo/useCache.js +49 -0
- package/dist/cjs/bins/cedar.d.ts +9 -0
- package/dist/cjs/bins/cedar.d.ts.map +1 -0
- package/dist/cjs/bins/cedar.js +36 -0
- package/dist/cjs/bins/cfw.d.ts +3 -0
- package/dist/cjs/bins/cfw.d.ts.map +1 -0
- package/dist/cjs/bins/cfw.js +36 -0
- package/dist/cjs/bins/cross-env.d.ts +3 -0
- package/dist/cjs/bins/cross-env.d.ts.map +1 -0
- package/dist/cjs/bins/cross-env.js +30 -0
- package/dist/cjs/bins/msw.d.ts +3 -0
- package/dist/cjs/bins/msw.d.ts.map +1 -0
- package/dist/cjs/bins/msw.js +28 -0
- package/dist/cjs/bins/redwood.d.ts +9 -0
- package/dist/cjs/bins/redwood.d.ts.map +1 -0
- package/dist/cjs/bins/redwood.js +36 -0
- package/dist/cjs/bins/storybook.d.ts +3 -0
- package/dist/cjs/bins/storybook.d.ts.map +1 -0
- package/dist/cjs/bins/storybook.js +49 -0
- package/dist/cjs/bins/tsc.d.ts +3 -0
- package/dist/cjs/bins/tsc.d.ts.map +1 -0
- package/dist/cjs/bins/tsc.js +30 -0
- package/dist/cjs/bundled/apollo-upload-client.d.ts +3 -0
- package/dist/cjs/bundled/apollo-upload-client.d.ts.map +1 -0
- package/dist/cjs/bundled/apollo-upload-client.js +2925 -0
- package/dist/cjs/components/DevFatalErrorPage.d.ts +21 -0
- package/dist/cjs/components/DevFatalErrorPage.d.ts.map +1 -0
- package/dist/cjs/components/DevFatalErrorPage.js +552 -0
- package/dist/cjs/components/FatalErrorBoundary.d.ts +24 -0
- package/dist/cjs/components/FatalErrorBoundary.d.ts.map +1 -0
- package/dist/cjs/components/FatalErrorBoundary.js +63 -0
- package/dist/cjs/components/FetchConfigProvider.d.ts +25 -0
- package/dist/cjs/components/FetchConfigProvider.d.ts.map +1 -0
- package/dist/cjs/components/FetchConfigProvider.js +80 -0
- package/dist/cjs/components/GraphQLHooksProvider.d.ts +45 -0
- package/dist/cjs/components/GraphQLHooksProvider.d.ts.map +1 -0
- package/dist/cjs/components/GraphQLHooksProvider.js +135 -0
- package/dist/cjs/components/MetaTags.d.ts +52 -0
- package/dist/cjs/components/MetaTags.d.ts.map +1 -0
- package/dist/cjs/components/MetaTags.js +68 -0
- package/dist/cjs/components/Metadata.d.ts +9 -0
- package/dist/cjs/components/Metadata.d.ts.map +1 -0
- package/dist/cjs/components/Metadata.js +94 -0
- package/dist/cjs/components/PortalHead.d.ts +4 -0
- package/dist/cjs/components/PortalHead.d.ts.map +1 -0
- package/dist/cjs/components/PortalHead.js +59 -0
- package/dist/cjs/components/RedwoodProvider.d.ts +9 -0
- package/dist/cjs/components/RedwoodProvider.d.ts.map +1 -0
- package/dist/cjs/components/RedwoodProvider.js +57 -0
- package/dist/cjs/components/ServerInject.d.ts +26 -0
- package/dist/cjs/components/ServerInject.d.ts.map +1 -0
- package/dist/cjs/components/ServerInject.js +75 -0
- package/dist/cjs/components/cell/CellCacheContext.d.ts +20 -0
- package/dist/cjs/components/cell/CellCacheContext.d.ts.map +1 -0
- package/dist/cjs/components/cell/CellCacheContext.js +53 -0
- package/dist/cjs/components/cell/CellErrorBoundary.d.ts +25 -0
- package/dist/cjs/components/cell/CellErrorBoundary.d.ts.map +1 -0
- package/dist/cjs/components/cell/CellErrorBoundary.js +66 -0
- package/dist/cjs/components/cell/cellTypes.d.ts +152 -0
- package/dist/cjs/components/cell/cellTypes.d.ts.map +1 -0
- package/dist/cjs/components/cell/cellTypes.js +16 -0
- package/dist/cjs/components/cell/createCell.d.ts +10 -0
- package/dist/cjs/components/cell/createCell.d.ts.map +1 -0
- package/dist/cjs/components/cell/createCell.js +165 -0
- package/dist/cjs/components/cell/createCell.test.js +351 -0
- package/dist/cjs/components/cell/createServerCell.d.ts +15 -0
- package/dist/cjs/components/cell/createServerCell.d.ts.map +1 -0
- package/dist/cjs/components/cell/createServerCell.js +91 -0
- package/dist/cjs/components/cell/createSuspendingCell.d.ts +11 -0
- package/dist/cjs/components/cell/createSuspendingCell.d.ts.map +1 -0
- package/dist/cjs/components/cell/createSuspendingCell.js +152 -0
- package/dist/cjs/components/cell/createSuspendingCell.test.js +115 -0
- package/dist/cjs/components/cell/isCellEmpty.d.ts +41 -0
- package/dist/cjs/components/cell/isCellEmpty.d.ts.map +1 -0
- package/dist/cjs/components/cell/isCellEmpty.js +35 -0
- package/dist/cjs/components/htmlTags.d.ts +52 -0
- package/dist/cjs/components/htmlTags.d.ts.map +1 -0
- package/dist/cjs/components/htmlTags.js +88 -0
- package/dist/cjs/config.d.ts +2 -0
- package/dist/cjs/config.d.ts.map +1 -0
- package/dist/cjs/config.js +6 -0
- package/dist/cjs/global.web-auto-imports.d.ts +30 -0
- package/dist/cjs/global.web-auto-imports.d.ts.map +1 -0
- package/dist/cjs/global.web-auto-imports.js +16 -0
- package/dist/cjs/graphql.d.ts +23 -0
- package/dist/cjs/graphql.d.ts.map +1 -0
- package/dist/cjs/graphql.js +36 -0
- package/dist/cjs/index.d.ts +19 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +69 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/routeHooks.types.d.ts +12 -0
- package/dist/cjs/routeHooks.types.d.ts.map +1 -0
- package/dist/cjs/routeHooks.types.js +16 -0
- package/dist/cjs/server/MiddlewareRequest.d.ts +28 -0
- package/dist/cjs/server/MiddlewareRequest.d.ts.map +1 -0
- package/dist/cjs/server/MiddlewareRequest.js +71 -0
- package/dist/cjs/server/MiddlewareResponse.d.ts +44 -0
- package/dist/cjs/server/MiddlewareResponse.d.ts.map +1 -0
- package/dist/cjs/server/MiddlewareResponse.js +130 -0
- package/dist/cjs/server/middleware.d.ts +17 -0
- package/dist/cjs/server/middleware.d.ts.map +1 -0
- package/dist/cjs/server/middleware.js +24 -0
- package/dist/cjs/server/request.d.ts +2 -0
- package/dist/cjs/server/request.d.ts.map +1 -0
- package/dist/cjs/server/request.js +34 -0
- package/dist/cjs/streamUtils/useDocumentReady.d.ts +11 -0
- package/dist/cjs/streamUtils/useDocumentReady.d.ts.map +1 -0
- package/dist/cjs/streamUtils/useDocumentReady.js +41 -0
- package/dist/cjs/toast/index.d.ts +3 -0
- package/dist/cjs/toast/index.d.ts.map +1 -0
- package/dist/cjs/toast/index.js +41 -0
- package/dist/components/FetchConfigProvider.d.ts +2 -3
- package/dist/components/FetchConfigProvider.d.ts.map +1 -1
- package/dist/components/GraphQLHooksProvider.d.ts +45 -0
- package/dist/components/GraphQLHooksProvider.d.ts.map +1 -0
- package/dist/components/GraphQLHooksProvider.js +94 -0
- package/dist/components/cell/CellErrorBoundary.d.ts +2 -3
- package/dist/components/cell/CellErrorBoundary.d.ts.map +1 -1
- package/dist/components/cell/cellTypes.d.ts +4 -17
- package/dist/components/cell/cellTypes.d.ts.map +1 -1
- package/dist/components/cell/createCell.d.ts +7 -1
- package/dist/components/cell/createCell.d.ts.map +1 -1
- package/dist/components/cell/createCell.js +3 -22
- package/dist/components/cell/createCell.test.js +328 -0
- package/dist/components/cell/createSuspendingCell.d.ts.map +1 -1
- package/dist/components/cell/createSuspendingCell.js +3 -12
- package/dist/components/cell/createSuspendingCell.test.js +92 -0
- package/dist/global.web-auto-imports.d.ts +16 -0
- package/dist/global.web-auto-imports.d.ts.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/package.json +1 -0
- package/package.json +106 -48
- package/dist/apollo/ApolloProviderWithFetchConfig.d.ts +0 -15
- package/dist/apollo/ApolloProviderWithFetchConfig.d.ts.map +0 -1
- package/dist/apollo/ApolloProviderWithFetchConfig.js +0 -134
- package/dist/apollo/CedarApolloProvider.d.ts +0 -14
- package/dist/apollo/CedarApolloProvider.d.ts.map +0 -1
- package/dist/apollo/CedarApolloProvider.js +0 -35
- package/dist/apollo/ErrorBoundary.d.ts +0 -13
- package/dist/apollo/ErrorBoundary.d.ts.map +0 -1
- package/dist/apollo/ErrorBoundary.js +0 -13
- package/dist/apollo/apolloLinkTypes.d.ts.map +0 -1
- package/dist/bins/cedar.js +0 -14
- package/dist/bins/cfw.js +0 -14
- package/dist/bins/cross-env.js +0 -8
- package/dist/bins/msw.js +0 -6
- package/dist/bins/redwood.js +0 -14
- package/dist/bins/storybook.js +0 -27
- package/dist/bins/tsc.js +0 -8
- package/dist/components/cell/createFragmentCell.d.ts +0 -19
- package/dist/components/cell/createFragmentCell.d.ts.map +0 -1
- package/dist/components/cell/createFragmentCell.js +0 -73
- /package/dist/apollo/{apolloLinkTypes.js → typeOverride.js} +0 -0
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import React, { Suspense } from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
useBackgroundQuery,
|
|
5
|
-
useReadQuery
|
|
6
|
-
} from "@apollo/client/react/hooks/hooks.cjs";
|
|
2
|
+
import { useApolloClient } from "@apollo/client/react/hooks/hooks.cjs";
|
|
3
|
+
import { useBackgroundQuery, useReadQuery } from "../GraphQLHooksProvider.js";
|
|
7
4
|
import { CellErrorBoundary } from "./CellErrorBoundary.js";
|
|
8
5
|
import { isDataEmpty } from "./isCellEmpty.js";
|
|
9
6
|
function createSuspendingCell(createCellProps) {
|
|
@@ -29,12 +26,6 @@ function createSuspendingCell(createCellProps) {
|
|
|
29
26
|
Success,
|
|
30
27
|
displayName = "Cell"
|
|
31
28
|
} = createCellProps;
|
|
32
|
-
if (!QUERY) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Can't create a Cell (${displayName}) without a QUERY or FRAGMENT export`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
const cellQuery = QUERY;
|
|
38
29
|
function SuspendingSuccess(props) {
|
|
39
30
|
const { queryRef, suspenseQueryResult, userProps } = props;
|
|
40
31
|
const { data, networkStatus } = useReadQuery(queryRef);
|
|
@@ -66,7 +57,7 @@ function createSuspendingCell(createCellProps) {
|
|
|
66
57
|
return (props) => {
|
|
67
58
|
const { children: _, ...variables } = props;
|
|
68
59
|
const options = beforeQuery(variables);
|
|
69
|
-
const query = typeof
|
|
60
|
+
const query = typeof QUERY === "function" ? QUERY(options) : QUERY;
|
|
70
61
|
const [queryRef, other] = useBackgroundQuery(query, options);
|
|
71
62
|
const client = useApolloClient();
|
|
72
63
|
const suspenseQueryResult = {
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
});
|
|
@@ -10,5 +10,21 @@ declare global {
|
|
|
10
10
|
RWJS_API_URL: string;
|
|
11
11
|
__REDWOOD__APP_TITLE: string;
|
|
12
12
|
}
|
|
13
|
+
type GraphQLOperationVariables = Record<string, any>;
|
|
14
|
+
interface QueryOperationResult<TData = any, TVariables = GraphQLOperationVariables> {
|
|
15
|
+
data: TData | undefined;
|
|
16
|
+
loading: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface MutationOperationResult<TData, TVariables> {
|
|
19
|
+
}
|
|
20
|
+
interface GraphQLQueryHookOptions<TData, TVariables> {
|
|
21
|
+
variables?: TVariables;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}
|
|
24
|
+
export interface GraphQLMutationHookOptions<TData, TVariables> {
|
|
25
|
+
variables?: TVariables;
|
|
26
|
+
onCompleted?: (data: TData) => void;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
13
29
|
}
|
|
14
30
|
//# sourceMappingURL=global.web-auto-imports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.web-auto-imports.d.ts","sourceRoot":"","sources":["../src/global.web-auto-imports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,OAAO,CAAA;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAK3C,OAAO,CAAC,MAAM,CAAC;IAMb,MAAM,GAAG,EAAE,CACT,MAAM,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,MAAM,EAAE,EACzD,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,YAAY,CAAA;IAIjB,KAAK,KAAK,GAAG,OAAO,MAAM,CAAA;IAE1B,UAAU,MAAM;QACd,8DAA8D;QAC9D,oBAAoB,EAAE,MAAM,CAAA;QAC5B,mDAAmD;QACnD,YAAY,EAAE,MAAM,CAAA;QACpB,oBAAoB,EAAE,MAAM,CAAA;KAC7B;CACF"}
|
|
1
|
+
{"version":3,"file":"global.web-auto-imports.d.ts","sourceRoot":"","sources":["../src/global.web-auto-imports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,OAAO,CAAA;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAK3C,OAAO,CAAC,MAAM,CAAC;IAMb,MAAM,GAAG,EAAE,CACT,MAAM,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,MAAM,EAAE,EACzD,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,YAAY,CAAA;IAIjB,KAAK,KAAK,GAAG,OAAO,MAAM,CAAA;IAE1B,UAAU,MAAM;QACd,8DAA8D;QAC9D,oBAAoB,EAAE,MAAM,CAAA;QAC5B,mDAAmD;QACnD,YAAY,EAAE,MAAM,CAAA;QACpB,oBAAoB,EAAE,MAAM,CAAA;KAC7B;IAED,KAAK,yBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAIpD,UAAU,oBAAoB,CAC5B,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,yBAAyB;QAEtC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAA;QACvB,OAAO,EAAE,OAAO,CAAA;KAGjB;IAID,UAAU,uBAAuB,CAAC,KAAK,EAAE,UAAU;KAAI;IAGvD,UAAU,uBAAuB,CAAC,KAAK,EAAE,UAAU;QACjD,SAAS,CAAC,EAAE,UAAU,CAAA;QACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KACnB;IAED,MAAM,WAAW,0BAA0B,CAAC,KAAK,EAAE,UAAU;QAC3D,SAAS,CAAC,EAAE,UAAU,CAAA;QACtB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI,CAAA;QACnC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KACnB;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,9 @@ import './global.web-auto-imports.js';
|
|
|
2
2
|
import './config.js';
|
|
3
3
|
export { FatalErrorBoundary } from './components/FatalErrorBoundary.js';
|
|
4
4
|
export { FetchConfigProvider, useFetchConfig, } from './components/FetchConfigProvider.js';
|
|
5
|
-
export { useQuery, useMutation, useSubscription, } from '
|
|
6
|
-
export { useFragment } from './apollo/fragmentRegistry.js';
|
|
7
|
-
export type { FragmentHookOptions, FragmentHookResult, } from './apollo/fragmentRegistry.js';
|
|
5
|
+
export { GraphQLHooksProvider, useQuery, useMutation, useSubscription, } from './components/GraphQLHooksProvider.js';
|
|
8
6
|
export * from './components/cell/CellCacheContext.js';
|
|
9
7
|
export { createCell } from './components/cell/createCell.js';
|
|
10
|
-
export { createFragmentCell } from './components/cell/createFragmentCell.js';
|
|
11
8
|
export type { CellProps, CellFailureProps, CellLoadingProps, CellSuccessProps, CellSuccessData, } from './components/cell/cellTypes.js';
|
|
12
9
|
export * from './graphql.js';
|
|
13
10
|
export * from './components/RedwoodProvider.js';
|
|
@@ -18,5 +15,5 @@ export { Helmet as Head, Helmet };
|
|
|
18
15
|
export * from './components/htmlTags.js';
|
|
19
16
|
export * from './routeHooks.types.js';
|
|
20
17
|
export * from './components/ServerInject.js';
|
|
21
|
-
export type { TypedDocumentNode } from '
|
|
18
|
+
export type { TypedDocumentNode } from './components/GraphQLHooksProvider.js';
|
|
22
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AACrC,OAAO,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AAEvE,OAAO,EACL,mBAAmB,EACnB,cAAc,GACf,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACL,QAAQ,EACR,WAAW,EACX,eAAe,GAChB,MAAM,sCAAsC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AACrC,OAAO,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AAEvE,OAAO,EACL,mBAAmB,EACnB,cAAc,GACf,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACL,oBAAoB,EACpB,QAAQ,EACR,WAAW,EACX,eAAe,GAChB,MAAM,sCAAsC,CAAA;AAE7C,cAAc,uCAAuC,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAE5D,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,GAChB,MAAM,gCAAgC,CAAA;AAEvC,cAAc,cAAc,CAAA;AAE5B,cAAc,iCAAiC,CAAA;AAE/C,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,MAAM,IAAI,IAAI,EAAE,MAAM,EAAE,CAAA;AAEjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AAErC,cAAc,8BAA8B,CAAA;AAE5C,YAAY,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -6,14 +6,13 @@ import {
|
|
|
6
6
|
useFetchConfig
|
|
7
7
|
} from "./components/FetchConfigProvider.js";
|
|
8
8
|
import {
|
|
9
|
+
GraphQLHooksProvider,
|
|
9
10
|
useQuery,
|
|
10
11
|
useMutation,
|
|
11
12
|
useSubscription
|
|
12
|
-
} from "
|
|
13
|
-
import { useFragment } from "./apollo/fragmentRegistry.js";
|
|
13
|
+
} from "./components/GraphQLHooksProvider.js";
|
|
14
14
|
export * from "./components/cell/CellCacheContext.js";
|
|
15
15
|
import { createCell } from "./components/cell/createCell.js";
|
|
16
|
-
import { createFragmentCell } from "./components/cell/createFragmentCell.js";
|
|
17
16
|
export * from "./graphql.js";
|
|
18
17
|
export * from "./components/RedwoodProvider.js";
|
|
19
18
|
export * from "./components/MetaTags.js";
|
|
@@ -25,12 +24,11 @@ export * from "./components/ServerInject.js";
|
|
|
25
24
|
export {
|
|
26
25
|
FatalErrorBoundary,
|
|
27
26
|
FetchConfigProvider,
|
|
27
|
+
GraphQLHooksProvider,
|
|
28
28
|
Helmet as Head,
|
|
29
29
|
Helmet,
|
|
30
30
|
createCell,
|
|
31
|
-
createFragmentCell,
|
|
32
31
|
useFetchConfig,
|
|
33
|
-
useFragment,
|
|
34
32
|
useMutation,
|
|
35
33
|
useQuery,
|
|
36
34
|
useSubscription
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/web",
|
|
3
|
-
"version": "5.0.4
|
|
3
|
+
"version": "5.0.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -10,57 +10,116 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"
|
|
14
|
-
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"require": {
|
|
18
|
+
"types": "./dist/cjs/index.d.ts",
|
|
19
|
+
"default": "./dist/cjs/index.js"
|
|
20
|
+
}
|
|
15
21
|
},
|
|
16
22
|
"./serverInject": {
|
|
17
|
-
"
|
|
18
|
-
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/components/ServerInject.d.ts",
|
|
25
|
+
"default": "./dist/components/ServerInject.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/cjs/components/ServerInject.d.ts",
|
|
29
|
+
"default": "./dist/cjs/components/ServerInject.js"
|
|
30
|
+
}
|
|
19
31
|
},
|
|
20
32
|
"./request": {
|
|
21
|
-
"
|
|
22
|
-
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/server/request.d.ts",
|
|
35
|
+
"default": "./dist/server/request.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/cjs/server/request.d.ts",
|
|
39
|
+
"default": "./dist/cjs/server/request.js"
|
|
40
|
+
}
|
|
23
41
|
},
|
|
24
42
|
"./middleware": {
|
|
25
|
-
"
|
|
26
|
-
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./dist/server/middleware.d.ts",
|
|
45
|
+
"default": "./dist/server/middleware.js"
|
|
46
|
+
},
|
|
47
|
+
"require": {
|
|
48
|
+
"types": "./dist/cjs/server/middleware.d.ts",
|
|
49
|
+
"default": "./dist/cjs/server/middleware.js"
|
|
50
|
+
}
|
|
27
51
|
},
|
|
28
52
|
"./dist/server/middleware": {
|
|
29
|
-
"
|
|
30
|
-
|
|
53
|
+
"import": {
|
|
54
|
+
"types": "./dist/server/middleware.d.ts",
|
|
55
|
+
"default": "./dist/server/middleware.js"
|
|
56
|
+
},
|
|
57
|
+
"require": {
|
|
58
|
+
"types": "./dist/cjs/server/middleware.d.ts",
|
|
59
|
+
"default": "./dist/cjs/server/middleware.js"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"./dist/components/*": {
|
|
63
|
+
"require": "./dist/cjs/components/*.js",
|
|
64
|
+
"import": "./dist/components/*.js"
|
|
65
|
+
},
|
|
66
|
+
"./htmlTags": {
|
|
67
|
+
"require": "./dist/cjs/components/htmlTags.js",
|
|
68
|
+
"import": "./dist/components/htmlTags.js"
|
|
69
|
+
},
|
|
70
|
+
"./Metadata": {
|
|
71
|
+
"require": "./dist/cjs/components/Metadata.js",
|
|
72
|
+
"import": "./dist/components/Metadata.js"
|
|
73
|
+
},
|
|
74
|
+
"./dist/apollo/suspense": {
|
|
75
|
+
"require": "./dist/cjs/apollo/suspense.js",
|
|
76
|
+
"import": "./dist/apollo/suspense.js"
|
|
77
|
+
},
|
|
78
|
+
"./dist/apollo/sseLink": {
|
|
79
|
+
"require": "./dist/cjs/apollo/sseLink.js",
|
|
80
|
+
"import": "./dist/apollo/sseLink.js"
|
|
81
|
+
},
|
|
82
|
+
"./dist/graphql.js": {
|
|
83
|
+
"require": "./dist/cjs/graphql.js",
|
|
84
|
+
"import": "./dist/graphql.js"
|
|
31
85
|
},
|
|
32
|
-
"./dist/components/*": "./dist/components/*.js",
|
|
33
|
-
"./htmlTags": "./dist/components/htmlTags.js",
|
|
34
|
-
"./Metadata": "./dist/components/Metadata.js",
|
|
35
|
-
"./dist/apollo/suspense": "./dist/apollo/suspense.js",
|
|
36
|
-
"./dist/apollo/sseLink": "./dist/apollo/sseLink.js",
|
|
37
|
-
"./dist/graphql.js": "./dist/graphql.js",
|
|
38
86
|
"./toast": {
|
|
39
|
-
"
|
|
40
|
-
|
|
87
|
+
"import": {
|
|
88
|
+
"types": "./dist/toast/index.d.ts",
|
|
89
|
+
"default": "./dist/toast/index.js"
|
|
90
|
+
},
|
|
91
|
+
"require": {
|
|
92
|
+
"types": "./dist/cjs/toast/index.d.ts",
|
|
93
|
+
"default": "./dist/cjs/toast/index.js"
|
|
94
|
+
}
|
|
41
95
|
},
|
|
42
96
|
"./apollo": {
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
97
|
+
"import": {
|
|
98
|
+
"types": "./dist/apollo/index.d.ts",
|
|
99
|
+
"default": "./dist/apollo/index.js"
|
|
100
|
+
},
|
|
101
|
+
"require": {
|
|
102
|
+
"types": "./dist/cjs/apollo/index.d.ts",
|
|
103
|
+
"default": "./dist/cjs/apollo/index.js"
|
|
104
|
+
}
|
|
49
105
|
},
|
|
50
|
-
"./forceEsmApollo":
|
|
106
|
+
"./forceEsmApollo": {
|
|
107
|
+
"require": "./dist/apollo/index.js",
|
|
108
|
+
"import": "./dist/apollo/index.js"
|
|
109
|
+
}
|
|
51
110
|
},
|
|
52
111
|
"main": "./dist/index.js",
|
|
53
112
|
"types": "dist/index.d.ts",
|
|
54
113
|
"bin": {
|
|
55
|
-
"cedar": "./dist/bins/cedar.js",
|
|
56
|
-
"cedarjs": "./dist/bins/cedar.js",
|
|
57
|
-
"cfw": "./dist/bins/cfw.js",
|
|
58
|
-
"cross-env": "./dist/bins/cross-env.js",
|
|
59
|
-
"msw": "./dist/bins/msw.js",
|
|
60
|
-
"redwood": "./dist/bins/redwood.js",
|
|
61
|
-
"rw": "./dist/bins/redwood.js",
|
|
62
|
-
"storybook": "./dist/bins/storybook.js",
|
|
63
|
-
"tsc": "./dist/bins/tsc.js"
|
|
114
|
+
"cedar": "./dist/cjs/bins/cedar.js",
|
|
115
|
+
"cedarjs": "./dist/cjs/bins/cedar.js",
|
|
116
|
+
"cfw": "./dist/cjs/bins/cfw.js",
|
|
117
|
+
"cross-env": "./dist/cjs/bins/cross-env.js",
|
|
118
|
+
"msw": "./dist/cjs/bins/msw.js",
|
|
119
|
+
"redwood": "./dist/cjs/bins/redwood.js",
|
|
120
|
+
"rw": "./dist/cjs/bins/redwood.js",
|
|
121
|
+
"storybook": "./dist/cjs/bins/storybook.js",
|
|
122
|
+
"tsc": "./dist/cjs/bins/tsc.js"
|
|
64
123
|
},
|
|
65
124
|
"files": [
|
|
66
125
|
"dist",
|
|
@@ -68,11 +127,11 @@
|
|
|
68
127
|
"toast"
|
|
69
128
|
],
|
|
70
129
|
"scripts": {
|
|
71
|
-
"build": "node ./build.ts",
|
|
130
|
+
"build": "node ./build.ts && yarn build:types",
|
|
72
131
|
"build:pack": "yarn pack -o cedarjs-web.tgz",
|
|
73
|
-
"build:types": "tsc --build --verbose ./tsconfig.build.json",
|
|
132
|
+
"build:types": "tsc --build --verbose ./tsconfig.build.json ./tsconfig.cjs.json",
|
|
74
133
|
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"",
|
|
75
|
-
"check:attw": "
|
|
134
|
+
"check:attw": "node ./attw.ts",
|
|
76
135
|
"check:package": "concurrently npm:check:attw yarn:publint",
|
|
77
136
|
"prepublishOnly": "NODE_ENV=production yarn build",
|
|
78
137
|
"test": "vitest run",
|
|
@@ -81,7 +140,7 @@
|
|
|
81
140
|
},
|
|
82
141
|
"dependencies": {
|
|
83
142
|
"@apollo/client": "3.14.1",
|
|
84
|
-
"@cedarjs/server-store": "5.0.4
|
|
143
|
+
"@cedarjs/server-store": "5.0.4",
|
|
85
144
|
"@dr.pogodin/react-helmet": "2.0.4",
|
|
86
145
|
"@whatwg-node/fetch": "0.10.13",
|
|
87
146
|
"apollo-upload-client": "18.0.1",
|
|
@@ -95,32 +154,31 @@
|
|
|
95
154
|
},
|
|
96
155
|
"devDependencies": {
|
|
97
156
|
"@apollo/client-react-streaming": "0.12.3",
|
|
98
|
-
"@arethetypeswrong/cli": "0.18.
|
|
157
|
+
"@arethetypeswrong/cli": "0.18.4",
|
|
99
158
|
"@babel/cli": "7.29.7",
|
|
100
159
|
"@babel/core": "^7.26.10",
|
|
101
160
|
"@babel/plugin-transform-runtime": "7.29.7",
|
|
102
161
|
"@babel/runtime": "7.29.7",
|
|
103
|
-
"@cedarjs/auth": "5.0.4
|
|
104
|
-
"@cedarjs/framework-tools": "5.0.4
|
|
105
|
-
"@cedarjs/internal": "5.0.4
|
|
162
|
+
"@cedarjs/auth": "5.0.4",
|
|
163
|
+
"@cedarjs/framework-tools": "5.0.4",
|
|
164
|
+
"@cedarjs/internal": "5.0.4",
|
|
106
165
|
"@rollup/plugin-babel": "6.1.0",
|
|
107
|
-
"@testing-library/dom": "10.4.1",
|
|
108
166
|
"@testing-library/jest-dom": "6.9.1",
|
|
109
|
-
"@testing-library/react": "
|
|
167
|
+
"@testing-library/react": "14.3.1",
|
|
110
168
|
"@types/apollo-upload-client": "^18",
|
|
111
169
|
"@types/react": "^18.2.55",
|
|
112
170
|
"@types/react-dom": "^18.2.19",
|
|
113
171
|
"concurrently": "9.2.4",
|
|
114
172
|
"nodemon": "3.1.14",
|
|
115
|
-
"publint": "0.3.
|
|
173
|
+
"publint": "0.3.21",
|
|
116
174
|
"react": "18.3.1",
|
|
117
175
|
"react-dom": "18.3.1",
|
|
118
176
|
"tstyche": "5.0.2",
|
|
119
177
|
"typescript": "5.9.3",
|
|
120
|
-
"vitest": "
|
|
178
|
+
"vitest": "3.2.6"
|
|
121
179
|
},
|
|
122
180
|
"peerDependencies": {
|
|
123
|
-
"@cedarjs/auth": "5.0.4
|
|
181
|
+
"@cedarjs/auth": "5.0.4",
|
|
124
182
|
"react": "18.3.1",
|
|
125
183
|
"react-dom": "18.3.1"
|
|
126
184
|
},
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { ApolloCache, setLogVerbosity } from '@apollo/client';
|
|
3
|
-
import type { UseAuth } from '@cedarjs/auth';
|
|
4
|
-
import type { GraphQLClientConfigProp } from './apolloLinkTypes.js';
|
|
5
|
-
interface Props {
|
|
6
|
-
config: Omit<GraphQLClientConfigProp, 'cacheConfig' | 'cache'> & {
|
|
7
|
-
cache: ApolloCache<unknown>;
|
|
8
|
-
};
|
|
9
|
-
useAuth?: UseAuth;
|
|
10
|
-
logLevel: ReturnType<typeof setLogVerbosity>;
|
|
11
|
-
children: React.ReactNode;
|
|
12
|
-
}
|
|
13
|
-
export declare function ApolloProviderWithFetchConfig({ config, children, useAuth, logLevel, }: Props): React.JSX.Element;
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=ApolloProviderWithFetchConfig.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloProviderWithFetchConfig.d.ts","sourceRoot":"","sources":["../../src/apollo/ApolloProviderWithFetchConfig.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,KAAK,EAAE,WAAW,EAAgB,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAYhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAM5C,OAAO,KAAK,EAEV,uBAAuB,EACxB,MAAM,sBAAsB,CAAA;AAoC7B,UAAU,KAAK;IACb,MAAM,EAAE,IAAI,CAAC,uBAAuB,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG;QAC/D,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;KAC5B,CAAA;IACD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;IAC5C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED,wBAAgB,6BAA6B,CAAC,EAC5C,MAAM,EACN,QAAQ,EACR,OAAmB,EACnB,QAAQ,GACT,EAAE,KAAK,qBAgKP"}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
ApolloClient,
|
|
4
|
-
setLogVerbosity as apolloSetLogVerbosity
|
|
5
|
-
} from "@apollo/client/core/core.cjs";
|
|
6
|
-
import { setContext } from "@apollo/client/link/context/context.cjs";
|
|
7
|
-
import { ApolloLink, split } from "@apollo/client/link/core/core.cjs";
|
|
8
|
-
import { createPersistedQueryLink } from "@apollo/client/link/persisted-queries/persisted-queries.cjs";
|
|
9
|
-
import { ApolloProvider } from "@apollo/client/react/react.cjs";
|
|
10
|
-
import { getMainDefinition } from "@apollo/client/utilities/utilities.cjs";
|
|
11
|
-
import { print } from "graphql/language/printer.js";
|
|
12
|
-
import { useNoAuth } from "@cedarjs/auth";
|
|
13
|
-
import { createUploadLink } from "../bundled/apollo-upload-client.js";
|
|
14
|
-
import { useFetchConfig } from "../components/FetchConfigProvider.js";
|
|
15
|
-
import { ErrorBoundary } from "./ErrorBoundary.js";
|
|
16
|
-
import * as SSELinkExports from "./sseLink.js";
|
|
17
|
-
const { SSELink, isSubscription, isLiveQuery } = SSELinkExports;
|
|
18
|
-
function ApolloProviderWithFetchConfig({
|
|
19
|
-
config,
|
|
20
|
-
children,
|
|
21
|
-
useAuth = useNoAuth,
|
|
22
|
-
logLevel
|
|
23
|
-
}) {
|
|
24
|
-
apolloSetLogVerbosity(logLevel);
|
|
25
|
-
const { getToken, type: authProviderType } = useAuth();
|
|
26
|
-
const data = {
|
|
27
|
-
mostRecentRequest: void 0,
|
|
28
|
-
mostRecentResponse: void 0
|
|
29
|
-
};
|
|
30
|
-
const updateDataApolloLink = new ApolloLink((operation, forward) => {
|
|
31
|
-
const { operationName, query, variables } = operation;
|
|
32
|
-
data.mostRecentRequest = {};
|
|
33
|
-
data.mostRecentRequest.operationName = operationName;
|
|
34
|
-
data.mostRecentRequest.operationKind = query?.kind.toString();
|
|
35
|
-
data.mostRecentRequest.variables = variables;
|
|
36
|
-
data.mostRecentRequest.query = query && print(operation.query);
|
|
37
|
-
return forward(operation).map((result) => {
|
|
38
|
-
data.mostRecentResponse = result;
|
|
39
|
-
return result;
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
const withToken = setContext(async () => {
|
|
43
|
-
const token = await getToken();
|
|
44
|
-
return { token };
|
|
45
|
-
});
|
|
46
|
-
const { headers, uri } = useFetchConfig();
|
|
47
|
-
const authMiddleware = new ApolloLink((operation, forward) => {
|
|
48
|
-
const { token } = operation.getContext();
|
|
49
|
-
const authHeaders = token ? {
|
|
50
|
-
"auth-provider": authProviderType,
|
|
51
|
-
authorization: `Bearer ${token}`
|
|
52
|
-
} : {};
|
|
53
|
-
operation.setContext(() => ({
|
|
54
|
-
headers: {
|
|
55
|
-
...operation.getContext().headers,
|
|
56
|
-
...headers,
|
|
57
|
-
// Duped auth headers, because we may remove the `FetchConfigProvider` at a later date.
|
|
58
|
-
...authHeaders
|
|
59
|
-
}
|
|
60
|
-
}));
|
|
61
|
-
return forward(operation);
|
|
62
|
-
});
|
|
63
|
-
const { httpLinkConfig, link: cedarApolloLink, ...rest } = config ?? {};
|
|
64
|
-
const uploadLink = createUploadLink({
|
|
65
|
-
uri,
|
|
66
|
-
...httpLinkConfig
|
|
67
|
-
});
|
|
68
|
-
const uploadOrSSELink = typeof SSELink !== "undefined" ? split(
|
|
69
|
-
({ query }) => {
|
|
70
|
-
const definition = getMainDefinition(query);
|
|
71
|
-
return isSubscription(definition) || isLiveQuery(definition);
|
|
72
|
-
},
|
|
73
|
-
new SSELink({
|
|
74
|
-
url: uri,
|
|
75
|
-
auth: { authProviderType, tokenFn: getToken },
|
|
76
|
-
httpLinkConfig,
|
|
77
|
-
headers
|
|
78
|
-
}),
|
|
79
|
-
uploadLink
|
|
80
|
-
) : uploadLink;
|
|
81
|
-
const terminatingLink = split(
|
|
82
|
-
({ query }) => {
|
|
83
|
-
const documentQuery = query;
|
|
84
|
-
return documentQuery?.["__meta__"]?.["hash"] !== void 0;
|
|
85
|
-
},
|
|
86
|
-
createPersistedQueryLink({
|
|
87
|
-
generateHash: (document) => document["__meta__"]["hash"]
|
|
88
|
-
}).concat(uploadOrSSELink),
|
|
89
|
-
uploadOrSSELink
|
|
90
|
-
);
|
|
91
|
-
const cedarApolloLinks = [
|
|
92
|
-
{ name: "withToken", link: withToken },
|
|
93
|
-
{ name: "authMiddleware", link: authMiddleware },
|
|
94
|
-
{ name: "updateDataApolloLink", link: updateDataApolloLink },
|
|
95
|
-
{ name: "httpLink", link: terminatingLink }
|
|
96
|
-
];
|
|
97
|
-
let link = cedarApolloLink;
|
|
98
|
-
link ??= ApolloLink.from(cedarApolloLinks.map((l) => l.link));
|
|
99
|
-
if (typeof link === "function") {
|
|
100
|
-
link = link(cedarApolloLinks);
|
|
101
|
-
}
|
|
102
|
-
const client = new ApolloClient({
|
|
103
|
-
// Default options for every Cell. Better to specify them here than in
|
|
104
|
-
// `beforeQuery` where it's too easy to overwrite them.
|
|
105
|
-
// See https://www.apollographql.com/docs/react/api/core/ApolloClient/#example-defaultoptions-object.
|
|
106
|
-
defaultOptions: {
|
|
107
|
-
watchQuery: {
|
|
108
|
-
// The `fetchPolicy` we expect:
|
|
109
|
-
//
|
|
110
|
-
// > Apollo Client executes the full query against both the cache and
|
|
111
|
-
// > your GraphQL server.
|
|
112
|
-
// > The query automatically updates if the result of the server-side
|
|
113
|
-
// > query modifies cached fields.
|
|
114
|
-
//
|
|
115
|
-
// See https://www.apollographql.com/docs/react/data/queries/#cache-and-network.
|
|
116
|
-
fetchPolicy: "cache-and-network",
|
|
117
|
-
// So that Cells rerender when refetching.
|
|
118
|
-
// See https://www.apollographql.com/docs/react/data/queries/#inspecting-loading-states.
|
|
119
|
-
notifyOnNetworkStatusChange: true
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
link,
|
|
123
|
-
...rest
|
|
124
|
-
});
|
|
125
|
-
const extendErrorAndRethrow = (error, _errorInfo) => {
|
|
126
|
-
error["mostRecentRequest"] = data.mostRecentRequest;
|
|
127
|
-
error["mostRecentResponse"] = data.mostRecentResponse;
|
|
128
|
-
throw error;
|
|
129
|
-
};
|
|
130
|
-
return /* @__PURE__ */ React.createElement(ApolloProvider, { client }, /* @__PURE__ */ React.createElement(ErrorBoundary, { onError: extendErrorAndRethrow }, children));
|
|
131
|
-
}
|
|
132
|
-
export {
|
|
133
|
-
ApolloProviderWithFetchConfig
|
|
134
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { DocumentNode, setLogVerbosity } from '@apollo/client';
|
|
3
|
-
import type { UseAuth } from '@cedarjs/auth';
|
|
4
|
-
import type { GraphQLClientConfigProp } from './apolloLinkTypes.js';
|
|
5
|
-
export type { ApolloClientCacheConfig, CedarApolloLink, CedarApolloLinkFactory, CedarApolloLinkName, CedarApolloLinks, GraphQLClientConfigProp, } from './apolloLinkTypes.js';
|
|
6
|
-
interface Props {
|
|
7
|
-
graphQLClientConfig?: GraphQLClientConfigProp;
|
|
8
|
-
fragments?: DocumentNode[];
|
|
9
|
-
useAuth?: UseAuth;
|
|
10
|
-
logLevel?: ReturnType<typeof setLogVerbosity>;
|
|
11
|
-
children: React.ReactNode;
|
|
12
|
-
}
|
|
13
|
-
export declare function CedarApolloProvider({ graphQLClientConfig, fragments, useAuth, logLevel, children, }: Props): React.JSX.Element;
|
|
14
|
-
//# sourceMappingURL=CedarApolloProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CedarApolloProvider.d.ts","sourceRoot":"","sources":["../../src/apollo/CedarApolloProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAK5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAInE,YAAY,EACV,uBAAuB,EACvB,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,sBAAsB,CAAA;AAE7B,UAAU,KAAK;IACb,mBAAmB,CAAC,EAAE,uBAAuB,CAAA;IAC7C,SAAS,CAAC,EAAE,YAAY,EAAE,CAAA;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;IAC7C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED,wBAAgB,mBAAmB,CAAC,EAClC,mBAAmB,EACnB,SAAS,EACT,OAAmB,EACnB,QAAkB,EAClB,QAAQ,GACT,EAAE,KAAK,qBA4BP"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { InMemoryCache } from "@apollo/client/cache/cache.cjs";
|
|
3
|
-
import { useNoAuth } from "@cedarjs/auth";
|
|
4
|
-
import { FetchConfigProvider } from "../components/FetchConfigProvider.js";
|
|
5
|
-
import { ApolloProviderWithFetchConfig } from "./ApolloProviderWithFetchConfig.js";
|
|
6
|
-
import { fragmentRegistry } from "./fragmentRegistry.js";
|
|
7
|
-
function CedarApolloProvider({
|
|
8
|
-
graphQLClientConfig,
|
|
9
|
-
fragments,
|
|
10
|
-
useAuth = useNoAuth,
|
|
11
|
-
logLevel = "debug",
|
|
12
|
-
children
|
|
13
|
-
}) {
|
|
14
|
-
const { cacheConfig, ...config } = graphQLClientConfig ?? {};
|
|
15
|
-
if (fragments) {
|
|
16
|
-
fragmentRegistry.register(...fragments);
|
|
17
|
-
}
|
|
18
|
-
const cache = new InMemoryCache({
|
|
19
|
-
fragments: fragmentRegistry,
|
|
20
|
-
possibleTypes: cacheConfig?.possibleTypes,
|
|
21
|
-
...cacheConfig
|
|
22
|
-
}).restore(globalThis?.__CEDAR__APOLLO_STATE ?? {});
|
|
23
|
-
return /* @__PURE__ */ React.createElement(FetchConfigProvider, { useAuth }, /* @__PURE__ */ React.createElement(
|
|
24
|
-
ApolloProviderWithFetchConfig,
|
|
25
|
-
{
|
|
26
|
-
config: { cache, ...config },
|
|
27
|
-
useAuth,
|
|
28
|
-
logLevel
|
|
29
|
-
},
|
|
30
|
-
children
|
|
31
|
-
));
|
|
32
|
-
}
|
|
33
|
-
export {
|
|
34
|
-
CedarApolloProvider
|
|
35
|
-
};
|