@cedarjs/web 9.0.0-canary.1784 → 9.0.0-canary.3124
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/ApolloClientFactoryContext.d.ts +26 -0
- package/dist/apollo/ApolloClientFactoryContext.d.ts.map +1 -0
- package/dist/apollo/ApolloClientFactoryContext.js +5 -0
- package/dist/apollo/ApolloProviderWithFetchConfig.d.ts +21 -0
- package/dist/apollo/ApolloProviderWithFetchConfig.d.ts.map +1 -0
- package/dist/apollo/ApolloProviderWithFetchConfig.js +153 -0
- package/dist/apollo/CedarApolloProvider.d.ts +14 -0
- package/dist/apollo/CedarApolloProvider.d.ts.map +1 -0
- package/dist/apollo/CedarApolloProvider.js +39 -0
- package/dist/apollo/ErrorBoundary.d.ts +13 -0
- package/dist/apollo/ErrorBoundary.d.ts.map +1 -0
- package/dist/apollo/ErrorBoundary.js +13 -0
- package/dist/apollo/apolloLinkTypes.d.ts +60 -0
- package/dist/apollo/apolloLinkTypes.d.ts.map +1 -0
- package/dist/apollo/fragmentRegistry.d.ts +28 -3
- package/dist/apollo/fragmentRegistry.d.ts.map +1 -1
- package/dist/apollo/fragmentRegistry.js +52 -7
- package/dist/apollo/index.d.ts +54 -70
- package/dist/apollo/index.d.ts.map +1 -1
- package/dist/apollo/index.js +5 -185
- package/dist/apollo/links.d.ts +4 -5
- package/dist/apollo/links.d.ts.map +1 -1
- package/dist/apollo/links.js +7 -7
- package/dist/apollo/sseLink.d.ts +5 -8
- package/dist/apollo/sseLink.d.ts.map +1 -1
- package/dist/apollo/sseLink.js +9 -12
- package/dist/apollo/suspense.d.ts +20 -10
- package/dist/apollo/suspense.d.ts.map +1 -1
- package/dist/apollo/suspense.js +37 -28
- package/dist/apollo/useCache.d.ts +4 -6
- package/dist/apollo/useCache.d.ts.map +1 -1
- package/dist/apollo/useCache.js +1 -1
- package/dist/apollo/useCreateApolloClient.d.ts +11 -0
- package/dist/apollo/useCreateApolloClient.d.ts.map +1 -0
- package/dist/apollo/useCreateApolloClient.js +14 -0
- package/dist/bins/cedar.js +14 -0
- package/dist/bins/cfw.js +14 -0
- package/dist/bins/cross-env.js +8 -0
- package/dist/bins/msw.js +6 -0
- package/dist/bins/redwood.js +14 -0
- package/dist/bins/storybook.js +27 -0
- package/dist/bins/tsc.js +8 -0
- package/dist/bundled/apollo-upload-client.d.ts +2 -2
- package/dist/bundled/apollo-upload-client.d.ts.map +1 -1
- package/dist/bundled/apollo-upload-client.js +2728 -2
- package/dist/components/{RedwoodProvider.d.ts → CedarProvider.d.ts} +3 -1
- package/dist/components/CedarProvider.d.ts.map +1 -0
- package/dist/components/{RedwoodProvider.js → CedarProvider.js} +4 -3
- package/dist/components/DevFatalErrorPage.d.ts +3 -3
- package/dist/components/DevFatalErrorPage.d.ts.map +1 -1
- package/dist/components/DevFatalErrorPage.js +3 -3
- package/dist/components/FatalErrorBoundary.d.ts +1 -1
- package/dist/components/FetchConfigProvider.d.ts +3 -2
- package/dist/components/FetchConfigProvider.d.ts.map +1 -1
- package/dist/components/MetaTags.d.ts.map +1 -1
- package/dist/components/MetaTags.js +1 -2
- package/dist/components/Metadata.d.ts.map +1 -1
- package/dist/components/Metadata.js +1 -2
- package/dist/components/cell/CellErrorBoundary.d.ts +3 -2
- package/dist/components/cell/CellErrorBoundary.d.ts.map +1 -1
- package/dist/components/cell/cellTypes.d.ts +69 -21
- package/dist/components/cell/cellTypes.d.ts.map +1 -1
- package/dist/components/cell/createCell.d.ts +2 -7
- package/dist/components/cell/createCell.d.ts.map +1 -1
- package/dist/components/cell/createCell.js +84 -60
- package/dist/components/cell/createFragmentCell.d.ts +20 -0
- package/dist/components/cell/createFragmentCell.d.ts.map +1 -0
- package/dist/components/cell/createFragmentCell.js +75 -0
- package/dist/components/cell/createServerCell.d.ts +3 -2
- package/dist/components/cell/createServerCell.d.ts.map +1 -1
- package/dist/components/cell/createServerCell.js +4 -2
- package/dist/components/cell/createSuspendingCell.d.ts +2 -1
- package/dist/components/cell/createSuspendingCell.d.ts.map +1 -1
- package/dist/components/cell/createSuspendingCell.js +47 -35
- package/dist/global.web-auto-imports.d.ts +0 -16
- package/dist/global.web-auto-imports.d.ts.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -10
- package/package.json +70 -137
- package/LICENSE +0 -21
- package/apollo/index.js +0 -1
- package/apollo/package.json +0 -4
- package/dist/apollo/typeOverride.d.ts +0 -21
- package/dist/apollo/typeOverride.d.ts.map +0 -1
- package/dist/cjs/apollo/fragmentRegistry.d.ts +0 -43
- package/dist/cjs/apollo/fragmentRegistry.d.ts.map +0 -1
- package/dist/cjs/apollo/fragmentRegistry.js +0 -75
- package/dist/cjs/apollo/index.d.ts +0 -76
- package/dist/cjs/apollo/index.d.ts.map +0 -1
- package/dist/cjs/apollo/index.js +0 -218
- package/dist/cjs/apollo/links.d.ts +0 -27
- package/dist/cjs/apollo/links.d.ts.map +0 -1
- package/dist/cjs/apollo/links.js +0 -122
- package/dist/cjs/apollo/sseLink.d.ts +0 -29
- package/dist/cjs/apollo/sseLink.d.ts.map +0 -1
- package/dist/cjs/apollo/sseLink.js +0 -120
- package/dist/cjs/apollo/suspense.d.ts +0 -60
- package/dist/cjs/apollo/suspense.d.ts.map +0 -1
- package/dist/cjs/apollo/suspense.js +0 -127
- package/dist/cjs/apollo/typeOverride.d.ts +0 -21
- package/dist/cjs/apollo/typeOverride.d.ts.map +0 -1
- package/dist/cjs/apollo/typeOverride.js +0 -16
- package/dist/cjs/apollo/useCache.d.ts +0 -22
- package/dist/cjs/apollo/useCache.d.ts.map +0 -1
- package/dist/cjs/apollo/useCache.js +0 -49
- package/dist/cjs/bins/cedar.d.ts +0 -9
- package/dist/cjs/bins/cedar.d.ts.map +0 -1
- package/dist/cjs/bins/cedar.js +0 -36
- package/dist/cjs/bins/cfw.d.ts +0 -3
- package/dist/cjs/bins/cfw.d.ts.map +0 -1
- package/dist/cjs/bins/cfw.js +0 -36
- package/dist/cjs/bins/cross-env.d.ts +0 -3
- package/dist/cjs/bins/cross-env.d.ts.map +0 -1
- package/dist/cjs/bins/cross-env.js +0 -30
- package/dist/cjs/bins/msw.d.ts +0 -3
- package/dist/cjs/bins/msw.d.ts.map +0 -1
- package/dist/cjs/bins/msw.js +0 -28
- package/dist/cjs/bins/redwood.d.ts +0 -9
- package/dist/cjs/bins/redwood.d.ts.map +0 -1
- package/dist/cjs/bins/redwood.js +0 -36
- package/dist/cjs/bins/storybook.d.ts +0 -3
- package/dist/cjs/bins/storybook.d.ts.map +0 -1
- package/dist/cjs/bins/storybook.js +0 -49
- package/dist/cjs/bins/tsc.d.ts +0 -3
- package/dist/cjs/bins/tsc.d.ts.map +0 -1
- package/dist/cjs/bins/tsc.js +0 -30
- package/dist/cjs/bundled/apollo-upload-client.d.ts +0 -3
- package/dist/cjs/bundled/apollo-upload-client.d.ts.map +0 -1
- package/dist/cjs/bundled/apollo-upload-client.js +0 -2511
- package/dist/cjs/components/DevFatalErrorPage.d.ts +0 -21
- package/dist/cjs/components/DevFatalErrorPage.d.ts.map +0 -1
- package/dist/cjs/components/DevFatalErrorPage.js +0 -552
- package/dist/cjs/components/FatalErrorBoundary.d.ts +0 -24
- package/dist/cjs/components/FatalErrorBoundary.d.ts.map +0 -1
- package/dist/cjs/components/FatalErrorBoundary.js +0 -63
- package/dist/cjs/components/FetchConfigProvider.d.ts +0 -25
- package/dist/cjs/components/FetchConfigProvider.d.ts.map +0 -1
- package/dist/cjs/components/FetchConfigProvider.js +0 -80
- package/dist/cjs/components/GraphQLHooksProvider.d.ts +0 -45
- package/dist/cjs/components/GraphQLHooksProvider.d.ts.map +0 -1
- package/dist/cjs/components/GraphQLHooksProvider.js +0 -135
- package/dist/cjs/components/MetaTags.d.ts +0 -52
- package/dist/cjs/components/MetaTags.d.ts.map +0 -1
- package/dist/cjs/components/MetaTags.js +0 -69
- package/dist/cjs/components/Metadata.d.ts +0 -9
- package/dist/cjs/components/Metadata.d.ts.map +0 -1
- package/dist/cjs/components/Metadata.js +0 -95
- package/dist/cjs/components/PortalHead.d.ts +0 -4
- package/dist/cjs/components/PortalHead.d.ts.map +0 -1
- package/dist/cjs/components/PortalHead.js +0 -59
- package/dist/cjs/components/RedwoodProvider.d.ts +0 -9
- package/dist/cjs/components/RedwoodProvider.d.ts.map +0 -1
- package/dist/cjs/components/RedwoodProvider.js +0 -58
- package/dist/cjs/components/ServerInject.d.ts +0 -26
- package/dist/cjs/components/ServerInject.d.ts.map +0 -1
- package/dist/cjs/components/ServerInject.js +0 -75
- package/dist/cjs/components/cell/CellCacheContext.d.ts +0 -20
- package/dist/cjs/components/cell/CellCacheContext.d.ts.map +0 -1
- package/dist/cjs/components/cell/CellCacheContext.js +0 -53
- package/dist/cjs/components/cell/CellErrorBoundary.d.ts +0 -25
- package/dist/cjs/components/cell/CellErrorBoundary.d.ts.map +0 -1
- package/dist/cjs/components/cell/CellErrorBoundary.js +0 -66
- package/dist/cjs/components/cell/cellTypes.d.ts +0 -152
- package/dist/cjs/components/cell/cellTypes.d.ts.map +0 -1
- package/dist/cjs/components/cell/cellTypes.js +0 -16
- package/dist/cjs/components/cell/createCell.d.ts +0 -10
- package/dist/cjs/components/cell/createCell.d.ts.map +0 -1
- package/dist/cjs/components/cell/createCell.js +0 -165
- package/dist/cjs/components/cell/createCell.test.js +0 -351
- package/dist/cjs/components/cell/createServerCell.d.ts +0 -15
- package/dist/cjs/components/cell/createServerCell.d.ts.map +0 -1
- package/dist/cjs/components/cell/createServerCell.js +0 -91
- package/dist/cjs/components/cell/createSuspendingCell.d.ts +0 -11
- package/dist/cjs/components/cell/createSuspendingCell.d.ts.map +0 -1
- package/dist/cjs/components/cell/createSuspendingCell.js +0 -152
- package/dist/cjs/components/cell/createSuspendingCell.test.js +0 -115
- package/dist/cjs/components/cell/isCellEmpty.d.ts +0 -41
- package/dist/cjs/components/cell/isCellEmpty.d.ts.map +0 -1
- package/dist/cjs/components/cell/isCellEmpty.js +0 -35
- package/dist/cjs/components/htmlTags.d.ts +0 -52
- package/dist/cjs/components/htmlTags.d.ts.map +0 -1
- package/dist/cjs/components/htmlTags.js +0 -88
- package/dist/cjs/config.d.ts +0 -2
- package/dist/cjs/config.d.ts.map +0 -1
- package/dist/cjs/config.js +0 -6
- package/dist/cjs/entry/index.js +0 -38
- package/dist/cjs/global.web-auto-imports.d.ts +0 -30
- package/dist/cjs/global.web-auto-imports.d.ts.map +0 -1
- package/dist/cjs/global.web-auto-imports.js +0 -16
- package/dist/cjs/graphql.d.ts +0 -23
- package/dist/cjs/graphql.d.ts.map +0 -1
- package/dist/cjs/graphql.js +0 -36
- package/dist/cjs/index.d.ts +0 -20
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -80
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/routeHooks.types.d.ts +0 -12
- package/dist/cjs/routeHooks.types.d.ts.map +0 -1
- package/dist/cjs/routeHooks.types.js +0 -16
- package/dist/cjs/server/MiddlewareRequest.d.ts +0 -28
- package/dist/cjs/server/MiddlewareRequest.d.ts.map +0 -1
- package/dist/cjs/server/MiddlewareRequest.js +0 -71
- package/dist/cjs/server/MiddlewareResponse.d.ts +0 -44
- package/dist/cjs/server/MiddlewareResponse.d.ts.map +0 -1
- package/dist/cjs/server/MiddlewareResponse.js +0 -130
- package/dist/cjs/server/middleware.d.ts +0 -17
- package/dist/cjs/server/middleware.d.ts.map +0 -1
- package/dist/cjs/server/middleware.js +0 -24
- package/dist/cjs/server/request.d.ts +0 -2
- package/dist/cjs/server/request.d.ts.map +0 -1
- package/dist/cjs/server/request.js +0 -34
- package/dist/cjs/streamUtils/useDocumentReady.d.ts +0 -11
- package/dist/cjs/streamUtils/useDocumentReady.d.ts.map +0 -1
- package/dist/cjs/streamUtils/useDocumentReady.js +0 -41
- package/dist/cjs/toast/index.d.ts +0 -3
- package/dist/cjs/toast/index.d.ts.map +0 -1
- package/dist/cjs/toast/index.js +0 -41
- package/dist/components/GraphQLHooksProvider.d.ts +0 -45
- package/dist/components/GraphQLHooksProvider.d.ts.map +0 -1
- package/dist/components/GraphQLHooksProvider.js +0 -94
- package/dist/components/RedwoodProvider.d.ts.map +0 -1
- package/dist/components/cell/createCell.test.js +0 -328
- package/dist/components/cell/createSuspendingCell.test.js +0 -92
- package/dist/entry/index.d.ts +0 -1
- package/dist/entry/index.js +0 -15
- package/dist/package.json +0 -1
- package/src/entry/index.jsx +0 -27
- package/toast/index.js +0 -1
- package/toast/package.json +0 -4
- /package/dist/apollo/{typeOverride.js → apolloLinkTypes.js} +0 -0
package/dist/apollo/index.js
CHANGED
|
@@ -1,197 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { InMemoryCache } from "@apollo/client/cache/cache.cjs";
|
|
3
|
-
import {
|
|
4
|
-
ApolloClient,
|
|
5
|
-
setLogVerbosity as apolloSetLogVerbosity
|
|
6
|
-
} from "@apollo/client/core/core.cjs";
|
|
7
|
-
import { setContext } from "@apollo/client/link/context/context.cjs";
|
|
8
|
-
import { ApolloLink, split } from "@apollo/client/link/core/core.cjs";
|
|
9
|
-
import { createPersistedQueryLink } from "@apollo/client/link/persisted-queries/persisted-queries.cjs";
|
|
10
|
-
import {
|
|
11
|
-
useQuery,
|
|
12
|
-
useMutation,
|
|
13
|
-
useSubscription,
|
|
14
|
-
useBackgroundQuery,
|
|
15
|
-
useReadQuery,
|
|
16
|
-
useSuspenseQuery
|
|
17
|
-
} from "@apollo/client/react/hooks/hooks.cjs";
|
|
18
|
-
import { ApolloProvider } from "@apollo/client/react/react.cjs";
|
|
19
|
-
import { getMainDefinition } from "@apollo/client/utilities/utilities.cjs";
|
|
20
|
-
import { print } from "graphql/language/printer.js";
|
|
21
|
-
import { useNoAuth } from "@cedarjs/auth";
|
|
22
|
-
import "./typeOverride.js";
|
|
23
|
-
import { createUploadLink } from "../bundled/apollo-upload-client.js";
|
|
24
|
-
import {
|
|
25
|
-
FetchConfigProvider,
|
|
26
|
-
useFetchConfig
|
|
27
|
-
} from "../components/FetchConfigProvider.js";
|
|
28
|
-
import { GraphQLHooksProvider } from "../components/GraphQLHooksProvider.js";
|
|
1
|
+
import { CedarApolloProvider } from "./CedarApolloProvider.js";
|
|
29
2
|
import {
|
|
30
3
|
fragmentRegistry,
|
|
31
4
|
registerFragment,
|
|
32
5
|
registerFragments
|
|
33
6
|
} from "./fragmentRegistry.js";
|
|
34
|
-
import * as SSELinkExports from "./sseLink.js";
|
|
35
7
|
import { useCache } from "./useCache.js";
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
apolloSetLogVerbosity(logLevel);
|
|
39
|
-
const { getToken, type: authProviderType } = useAuth();
|
|
40
|
-
const data = {
|
|
41
|
-
mostRecentRequest: void 0,
|
|
42
|
-
mostRecentResponse: void 0
|
|
43
|
-
};
|
|
44
|
-
const updateDataApolloLink = new ApolloLink((operation, forward) => {
|
|
45
|
-
const { operationName, query, variables } = operation;
|
|
46
|
-
data.mostRecentRequest = {};
|
|
47
|
-
data.mostRecentRequest.operationName = operationName;
|
|
48
|
-
data.mostRecentRequest.operationKind = query?.kind.toString();
|
|
49
|
-
data.mostRecentRequest.variables = variables;
|
|
50
|
-
data.mostRecentRequest.query = query && print(operation.query);
|
|
51
|
-
return forward(operation).map((result) => {
|
|
52
|
-
data.mostRecentResponse = result;
|
|
53
|
-
return result;
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
const withToken = setContext(async () => {
|
|
57
|
-
const token = await getToken();
|
|
58
|
-
return { token };
|
|
59
|
-
});
|
|
60
|
-
const { headers, uri } = useFetchConfig();
|
|
61
|
-
const authMiddleware = new ApolloLink((operation, forward) => {
|
|
62
|
-
const { token } = operation.getContext();
|
|
63
|
-
const authHeaders = token ? {
|
|
64
|
-
"auth-provider": authProviderType,
|
|
65
|
-
authorization: `Bearer ${token}`
|
|
66
|
-
} : {};
|
|
67
|
-
operation.setContext(() => ({
|
|
68
|
-
headers: {
|
|
69
|
-
...operation.getContext().headers,
|
|
70
|
-
...headers,
|
|
71
|
-
// Duped auth headers, because we may remove the `FetchConfigProvider` at a later date.
|
|
72
|
-
...authHeaders
|
|
73
|
-
}
|
|
74
|
-
}));
|
|
75
|
-
return forward(operation);
|
|
76
|
-
});
|
|
77
|
-
const { httpLinkConfig, link: redwoodApolloLink, ...rest } = config ?? {};
|
|
78
|
-
const uploadLink = createUploadLink({
|
|
79
|
-
uri,
|
|
80
|
-
...httpLinkConfig
|
|
81
|
-
// The upload link types don't match the ApolloLink types, even though it comes from Apollo
|
|
82
|
-
// because they use ESM imports and we're using the default ones.
|
|
83
|
-
});
|
|
84
|
-
const uploadOrSSELink = typeof SSELink !== "undefined" ? split(
|
|
85
|
-
({ query }) => {
|
|
86
|
-
const definition = getMainDefinition(query);
|
|
87
|
-
return isSubscription(definition) || isLiveQuery(definition);
|
|
88
|
-
},
|
|
89
|
-
new SSELink({
|
|
90
|
-
url: uri,
|
|
91
|
-
auth: { authProviderType, tokenFn: getToken },
|
|
92
|
-
httpLinkConfig,
|
|
93
|
-
headers
|
|
94
|
-
}),
|
|
95
|
-
uploadLink
|
|
96
|
-
) : uploadLink;
|
|
97
|
-
const terminatingLink = split(
|
|
98
|
-
({ query }) => {
|
|
99
|
-
const documentQuery = query;
|
|
100
|
-
return documentQuery?.["__meta__"]?.["hash"] !== void 0;
|
|
101
|
-
},
|
|
102
|
-
createPersistedQueryLink({
|
|
103
|
-
generateHash: (document) => document["__meta__"]["hash"]
|
|
104
|
-
}).concat(uploadOrSSELink),
|
|
105
|
-
uploadOrSSELink
|
|
106
|
-
);
|
|
107
|
-
const redwoodApolloLinks = [
|
|
108
|
-
{ name: "withToken", link: withToken },
|
|
109
|
-
{ name: "authMiddleware", link: authMiddleware },
|
|
110
|
-
{ name: "updateDataApolloLink", link: updateDataApolloLink },
|
|
111
|
-
{ name: "httpLink", link: terminatingLink }
|
|
112
|
-
];
|
|
113
|
-
let link = redwoodApolloLink;
|
|
114
|
-
link ??= ApolloLink.from(redwoodApolloLinks.map((l) => l.link));
|
|
115
|
-
if (typeof link === "function") {
|
|
116
|
-
link = link(redwoodApolloLinks);
|
|
117
|
-
}
|
|
118
|
-
const client = new ApolloClient({
|
|
119
|
-
// Default options for every Cell. Better to specify them here than in `beforeQuery` where it's too easy to overwrite them.
|
|
120
|
-
// See https://www.apollographql.com/docs/react/api/core/ApolloClient/#example-defaultoptions-object.
|
|
121
|
-
defaultOptions: {
|
|
122
|
-
watchQuery: {
|
|
123
|
-
// The `fetchPolicy` we expect:
|
|
124
|
-
//
|
|
125
|
-
// > Apollo Client executes the full query against both the cache and your GraphQL server.
|
|
126
|
-
// > The query automatically updates if the result of the server-side query modifies cached fields.
|
|
127
|
-
//
|
|
128
|
-
// See https://www.apollographql.com/docs/react/data/queries/#cache-and-network.
|
|
129
|
-
fetchPolicy: "cache-and-network",
|
|
130
|
-
// So that Cells rerender when refetching.
|
|
131
|
-
// See https://www.apollographql.com/docs/react/data/queries/#inspecting-loading-states.
|
|
132
|
-
notifyOnNetworkStatusChange: true
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
link,
|
|
136
|
-
...rest
|
|
137
|
-
});
|
|
138
|
-
const extendErrorAndRethrow = (error, _errorInfo) => {
|
|
139
|
-
error["mostRecentRequest"] = data.mostRecentRequest;
|
|
140
|
-
error["mostRecentResponse"] = data.mostRecentResponse;
|
|
141
|
-
throw error;
|
|
142
|
-
};
|
|
143
|
-
return /* @__PURE__ */ React.createElement(ApolloProvider, { client }, /* @__PURE__ */ React.createElement(ErrorBoundary, { onError: extendErrorAndRethrow }, children));
|
|
144
|
-
};
|
|
145
|
-
class ErrorBoundary extends React.Component {
|
|
146
|
-
componentDidCatch(...args) {
|
|
147
|
-
this.setState({});
|
|
148
|
-
this.props.onError(...args);
|
|
149
|
-
}
|
|
150
|
-
render() {
|
|
151
|
-
return this.props.children;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const RedwoodApolloProvider = ({
|
|
155
|
-
graphQLClientConfig,
|
|
156
|
-
fragments,
|
|
157
|
-
useAuth = useNoAuth,
|
|
158
|
-
logLevel = "debug",
|
|
159
|
-
children
|
|
160
|
-
}) => {
|
|
161
|
-
const { cacheConfig, ...config } = graphQLClientConfig ?? {};
|
|
162
|
-
if (fragments) {
|
|
163
|
-
fragmentRegistry.register(...fragments);
|
|
164
|
-
}
|
|
165
|
-
const cache = new InMemoryCache({
|
|
166
|
-
fragments: fragmentRegistry,
|
|
167
|
-
possibleTypes: cacheConfig?.possibleTypes,
|
|
168
|
-
...cacheConfig
|
|
169
|
-
}).restore(globalThis?.__REDWOOD__APOLLO_STATE ?? {});
|
|
170
|
-
return /* @__PURE__ */ React.createElement(FetchConfigProvider, { useAuth }, /* @__PURE__ */ React.createElement(
|
|
171
|
-
ApolloProviderWithFetchConfig,
|
|
172
|
-
{
|
|
173
|
-
config: { cache, ...config },
|
|
174
|
-
useAuth,
|
|
175
|
-
logLevel
|
|
176
|
-
},
|
|
177
|
-
/* @__PURE__ */ React.createElement(
|
|
178
|
-
GraphQLHooksProvider,
|
|
179
|
-
{
|
|
180
|
-
useQuery,
|
|
181
|
-
useMutation,
|
|
182
|
-
useSubscription,
|
|
183
|
-
useBackgroundQuery,
|
|
184
|
-
useReadQuery,
|
|
185
|
-
useSuspenseQuery
|
|
186
|
-
},
|
|
187
|
-
children
|
|
188
|
-
)
|
|
189
|
-
));
|
|
190
|
-
};
|
|
8
|
+
import { useCreateApolloClient } from "./useCreateApolloClient.js";
|
|
9
|
+
const RedwoodApolloProvider = CedarApolloProvider;
|
|
191
10
|
export {
|
|
192
11
|
RedwoodApolloProvider,
|
|
193
12
|
fragmentRegistry,
|
|
194
13
|
registerFragment,
|
|
195
14
|
registerFragments,
|
|
196
|
-
useCache
|
|
15
|
+
useCache,
|
|
16
|
+
useCreateApolloClient
|
|
197
17
|
};
|
package/dist/apollo/links.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare function createHttpLink(uri: string, httpLinkConfig: HttpOptions | undefined, cookieHeader?: string | null): HttpLink;
|
|
1
|
+
import { ApolloLink, HttpLink } from '@apollo/client';
|
|
2
|
+
import { SetContextLink } from '@apollo/client/link/context';
|
|
3
|
+
export declare function createHttpLink(uri: string, httpLinkConfig: HttpLink.Options | undefined, cookieHeader?: string | null): HttpLink;
|
|
5
4
|
export declare function createUpdateDataLink(): ApolloLink;
|
|
6
5
|
export declare function createAuthApolloLink(authProviderType: string, headersFromFetchProvider: {
|
|
7
6
|
'auth-provider'?: string | undefined;
|
|
8
7
|
authorization?: string | undefined;
|
|
9
8
|
} | undefined): ApolloLink;
|
|
10
|
-
export declare function createTokenLink(getToken: () => Promise<string | null>):
|
|
9
|
+
export declare function createTokenLink(getToken: () => Promise<string | null>): SetContextLink;
|
|
11
10
|
export declare function createFinalLink({ userConfiguredLink, defaultLinks, }: {
|
|
12
11
|
userConfiguredLink?: ApolloLink | RedwoodApolloLinkFactory;
|
|
13
12
|
defaultLinks: RedwoodApolloLinks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/apollo/links.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/apollo/links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAI5D,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,QAAQ,CAAC,OAAO,GAAG,SAAS,EAC5C,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,YAc7B;AAeD,wBAAgB,oBAAoB,eAqBnC;AACD,wBAAgB,oBAAoB,CAClC,gBAAgB,EAAE,MAAM,EACxB,wBAAwB,EACpB;IACE,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACnC,GACD,SAAS,cA6Bd;AACD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,kBAMrE;AAED,wBAAgB,eAAe,CAAC,EAC9B,kBAAkB,EAClB,YAAY,GACb,EAAE;IACD,kBAAkB,CAAC,EAAE,UAAU,GAAG,wBAAwB,CAAA;IAC1D,YAAY,EAAE,kBAAkB,CAAA;CACjC,GAAG,UAAU,CAUb;AAID,MAAM,MAAM,iBAAiB,CAC3B,IAAI,SAAS,qBAAqB,EAClC,IAAI,SAAS,UAAU,GAAG,UAAU,IAClC;IACF,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,CAC7B,iBAAiB,CAAC,WAAW,CAAC,GAC9B,iBAAiB,CAAC,gBAAgB,CAAC,GACnC,iBAAiB,CAAC,kBAAkB,CAAC,GACrC,iBAAiB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAC1C,EAAE,CAAA;AAMH,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAA;AAC9C,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,IAAI,GAAG,KAAK,CAAA;AAC3E,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,kBAAkB,CAAC,CAAA;AAExE,MAAM,MAAM,wBAAwB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,UAAU,CAAA"}
|
package/dist/apollo/links.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { ApolloLink } from "@apollo/client/link/core/index.js";
|
|
4
|
-
import { HttpLink } from "@apollo/client/link/http/index.js";
|
|
1
|
+
import { ApolloLink, HttpLink } from "@apollo/client";
|
|
2
|
+
import { SetContextLink } from "@apollo/client/link/context";
|
|
5
3
|
import { print } from "graphql/language/printer.js";
|
|
4
|
+
import { Observable } from "rxjs";
|
|
6
5
|
function createHttpLink(uri, httpLinkConfig, cookieHeader) {
|
|
7
6
|
const headers = {};
|
|
8
7
|
if (cookieHeader) {
|
|
@@ -28,9 +27,9 @@ function enhanceError(operation, error) {
|
|
|
28
27
|
function createUpdateDataLink() {
|
|
29
28
|
return new ApolloLink((operation, forward) => {
|
|
30
29
|
return new Observable((observer) => {
|
|
31
|
-
forward(operation).subscribe({
|
|
30
|
+
const subscription = forward(operation).subscribe({
|
|
32
31
|
next(result) {
|
|
33
|
-
if (result.errors) {
|
|
32
|
+
if ("errors" in result && result.errors) {
|
|
34
33
|
result.errors.forEach((error) => {
|
|
35
34
|
enhanceError(operation, error);
|
|
36
35
|
});
|
|
@@ -42,6 +41,7 @@ function createUpdateDataLink() {
|
|
|
42
41
|
},
|
|
43
42
|
complete: observer.complete.bind(observer)
|
|
44
43
|
});
|
|
44
|
+
return () => subscription.unsubscribe();
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
}
|
|
@@ -67,7 +67,7 @@ function createAuthApolloLink(authProviderType, headersFromFetchProvider) {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
function createTokenLink(getToken) {
|
|
70
|
-
return
|
|
70
|
+
return new SetContextLink(async () => {
|
|
71
71
|
const token = await getToken();
|
|
72
72
|
return { token };
|
|
73
73
|
});
|
package/dist/apollo/sseLink.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import { ApolloLink } from '@apollo/client/link/core/core.cjs';
|
|
4
|
-
import { Observable } from '@apollo/client/utilities/utilities.cjs';
|
|
1
|
+
import type { HttpLink } from '@apollo/client';
|
|
2
|
+
import { ApolloLink } from '@apollo/client';
|
|
5
3
|
import type { DefinitionNode } from 'graphql';
|
|
6
4
|
import type { ClientOptions } from 'graphql-sse';
|
|
5
|
+
import { Observable } from 'rxjs';
|
|
7
6
|
interface SSELinkOptions extends Partial<ClientOptions> {
|
|
8
7
|
url: string;
|
|
9
8
|
auth: {
|
|
10
9
|
authProviderType: string;
|
|
11
10
|
tokenFn: () => Promise<null | string>;
|
|
12
11
|
};
|
|
13
|
-
httpLinkConfig?:
|
|
12
|
+
httpLinkConfig?: HttpLink.Options;
|
|
14
13
|
headers?: Record<string, string>;
|
|
15
14
|
}
|
|
16
15
|
declare const isSubscription: (definition: DefinitionNode) => boolean;
|
|
@@ -21,9 +20,7 @@ declare const isLiveQuery: (definition: DefinitionNode) => boolean;
|
|
|
21
20
|
declare class SSELink extends ApolloLink {
|
|
22
21
|
private client;
|
|
23
22
|
constructor(options: SSELinkOptions);
|
|
24
|
-
request(operation: Operation
|
|
25
|
-
query?: any;
|
|
26
|
-
}): Observable<FetchResult>;
|
|
23
|
+
request(operation: ApolloLink.Operation): Observable<ApolloLink.Result>;
|
|
27
24
|
}
|
|
28
25
|
export { SSELink, isSubscription, isLiveQuery };
|
|
29
26
|
//# sourceMappingURL=sseLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sseLink.d.ts","sourceRoot":"","sources":["../../src/apollo/sseLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"sseLink.d.ts","sourceRoot":"","sources":["../../src/apollo/sseLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,aAAa,EAA+B,MAAM,aAAa,CAAA;AAE7E,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACjC,UAAU,cAAe,SAAQ,OAAO,CAAC,aAAa,CAAC;IACrD,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAAA;KAAE,CAAA;IACzE,cAAc,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAA;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC;AAsDD,QAAA,MAAM,cAAc,GAAI,YAAY,cAAc,YAKjD,CAAA;AAID,QAAA,MAAM,WAAW,GAAI,YAAY,cAAc,YAS9C,CAAA;AAED;;GAEG;AACH,cAAM,OAAQ,SAAQ,UAAU;IAC9B,OAAO,CAAC,MAAM,CAAQ;gBAEV,OAAO,EAAE,cAAc;IA2B5B,OAAO,CACZ,SAAS,EAAE,UAAU,CAAC,SAAS,GAC9B,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC;CA6BjC;AAED,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,CAAA"}
|
package/dist/apollo/sseLink.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ApolloLink } from "@apollo/client
|
|
2
|
-
import { Observable } from "@apollo/client/utilities/utilities.cjs";
|
|
1
|
+
import { ApolloLink } from "@apollo/client";
|
|
3
2
|
import { Kind, OperationTypeNode, print } from "graphql";
|
|
4
3
|
import { createClient } from "graphql-sse";
|
|
4
|
+
import { Observable } from "rxjs";
|
|
5
5
|
const mapCredentialsHeader = (httpLinkCredentials) => {
|
|
6
6
|
if (!httpLinkCredentials) {
|
|
7
7
|
return void 0;
|
|
@@ -69,16 +69,13 @@ class SSELink extends ApolloLink {
|
|
|
69
69
|
}
|
|
70
70
|
request(operation) {
|
|
71
71
|
return new Observable((sink) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
query: print(operation.query)
|
|
80
|
-
};
|
|
81
|
-
}
|
|
72
|
+
const { operationName, variables, extensions } = operation;
|
|
73
|
+
const request = hasTrustedDocument(operation) ? { operationName, variables, extensions } : {
|
|
74
|
+
operationName,
|
|
75
|
+
variables,
|
|
76
|
+
extensions,
|
|
77
|
+
query: print(operation.query)
|
|
78
|
+
};
|
|
82
79
|
return this.client.subscribe(request, {
|
|
83
80
|
next: sink.next.bind(sink),
|
|
84
81
|
complete: sink.complete.bind(sink),
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ApolloClient as ApolloClientBase, HttpLink, InMemoryCacheConfig, setLogVerbosity } from '@apollo/client';
|
|
3
|
+
import { ApolloLink } from '@apollo/client';
|
|
3
4
|
import { InMemoryCache } from '@apollo/client-react-streaming';
|
|
4
5
|
import type { UseAuth } from '@cedarjs/auth';
|
|
5
|
-
import './typeOverride.js';
|
|
6
6
|
import type { RedwoodApolloLink, RedwoodApolloLinkFactory, RedwoodApolloLinkName, RedwoodApolloLinks } from './links.js';
|
|
7
7
|
export type ApolloClientCacheConfig = InMemoryCacheConfig;
|
|
8
8
|
export type { RedwoodApolloLink, RedwoodApolloLinkFactory, RedwoodApolloLinkName, RedwoodApolloLinks, };
|
|
9
|
-
export type GraphQLClientConfigProp = Omit<
|
|
9
|
+
export type GraphQLClientConfigProp = Omit<ApolloClientBase.Options, 'cache' | 'link'> & {
|
|
10
10
|
cache?: InMemoryCache;
|
|
11
11
|
/**
|
|
12
12
|
* Configuration for Apollo Client's `InMemoryCache`.
|
|
@@ -20,28 +20,28 @@ export type GraphQLClientConfigProp = Omit<ApolloClientOptions<unknown>, 'cache'
|
|
|
20
20
|
* For example, you can use this prop to set the credentials policy so that cookies can be sent to other domains:
|
|
21
21
|
*
|
|
22
22
|
* ```js
|
|
23
|
-
* <
|
|
23
|
+
* <CedarApolloProvider graphQLClientConfig={{
|
|
24
24
|
* httpLinkConfig: { credentials: 'include' }
|
|
25
25
|
* }}>
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
httpLinkConfig?:
|
|
28
|
+
httpLinkConfig?: HttpLink.Options;
|
|
29
29
|
/**
|
|
30
|
-
* Extend or overwrite `
|
|
30
|
+
* Extend or overwrite `CedarApolloProvider`'s Apollo Link.
|
|
31
31
|
*
|
|
32
|
-
* To overwrite
|
|
32
|
+
* To overwrite Cedar's Apollo Link, just provide your own `ApolloLink`.
|
|
33
33
|
*
|
|
34
|
-
* To extend
|
|
34
|
+
* To extend Cedar's Apollo Link, provide a function—it'll get passed an array of Cedar's Apollo Links
|
|
35
35
|
* which are objects with a name and link property:
|
|
36
36
|
*
|
|
37
37
|
* ```js
|
|
38
|
-
* const link = (
|
|
38
|
+
* const link = (cedarApolloLinks) => {
|
|
39
39
|
* const consoleLink = new ApolloLink((operation, forward) => {
|
|
40
40
|
* console.log(operation.operationName)
|
|
41
41
|
* return forward(operation)
|
|
42
42
|
* })
|
|
43
43
|
*
|
|
44
|
-
* return ApolloLink.from([consoleLink, ...
|
|
44
|
+
* return ApolloLink.from([consoleLink, ...cedarApolloLinks.map(({ link }) => link)])
|
|
45
45
|
* }
|
|
46
46
|
* ```
|
|
47
47
|
*
|
|
@@ -51,6 +51,16 @@ export type GraphQLClientConfigProp = Omit<ApolloClientOptions<unknown>, 'cache'
|
|
|
51
51
|
*/
|
|
52
52
|
link?: ApolloLink | RedwoodApolloLinkFactory;
|
|
53
53
|
};
|
|
54
|
+
export declare const CedarApolloProvider: React.FunctionComponent<{
|
|
55
|
+
graphQLClientConfig?: GraphQLClientConfigProp;
|
|
56
|
+
useAuth?: UseAuth;
|
|
57
|
+
logLevel?: ReturnType<typeof setLogVerbosity>;
|
|
58
|
+
children: React.ReactNode;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use `CedarApolloProvider` instead. `RedwoodApolloProvider` will
|
|
62
|
+
* be removed in a future release.
|
|
63
|
+
*/
|
|
54
64
|
export declare const RedwoodApolloProvider: React.FunctionComponent<{
|
|
55
65
|
graphQLClientConfig?: GraphQLClientConfigProp;
|
|
56
66
|
useAuth?: UseAuth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../../src/apollo/suspense.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../../src/apollo/suspense.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,QAAQ,EACR,mBAAmB,EACnB,eAAe,EAChB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,UAAU,EAEX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAEL,aAAa,EAEd,MAAM,gCAAgC,CAAA;AAGvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAa5C,OAAO,KAAK,EACV,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,YAAY,CAAA;AASnB,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAEzD,YAAY,EACV,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,GACnB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,gBAAgB,CAAC,OAAO,EACxB,OAAO,GAAG,MAAM,CACjB,GAAG;IACF,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,uBAAuB,CAAA;IACrC;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAA;IACjC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,CAAC,EAAE,UAAU,GAAG,wBAAwB,CAAA;CAC7C,CAAA;AAqHD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,iBAAiB,CAAC;IACxD,mBAAmB,CAAC,EAAE,uBAAuB,CAAA;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;IAC7C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAsCA,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB;0BAhDV,uBAAuB;cACnC,OAAO;eACN,UAAU,CAAC,OAAO,eAAe,CAAC;cACnC,KAAK,CAAC,SAAS;EA6C6B,CAAA"}
|
package/dist/apollo/suspense.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import React, { useContext } from "react";
|
|
3
|
-
import { setLogVerbosity as apolloSetLogVerbosity } from "@apollo/client/core/index.js";
|
|
4
3
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
useReadQuery,
|
|
10
|
-
useSuspenseQuery
|
|
11
|
-
} from "@apollo/client/react/hooks/index.js";
|
|
4
|
+
ApolloLink,
|
|
5
|
+
setLogVerbosity as apolloSetLogVerbosity
|
|
6
|
+
} from "@apollo/client";
|
|
7
|
+
import { SetContextLink } from "@apollo/client/link/context";
|
|
12
8
|
import {
|
|
13
9
|
ApolloClient,
|
|
14
10
|
InMemoryCache,
|
|
@@ -17,13 +13,13 @@ import {
|
|
|
17
13
|
import { buildManualDataTransport } from "@apollo/client-react-streaming/manual-transport";
|
|
18
14
|
import { useNoAuth } from "@cedarjs/auth";
|
|
19
15
|
import { ServerAuthContext } from "@cedarjs/auth/dist/AuthProvider/ServerAuthProvider.js";
|
|
20
|
-
import "./typeOverride.js";
|
|
21
16
|
import {
|
|
22
17
|
FetchConfigProvider,
|
|
23
18
|
useFetchConfig
|
|
24
19
|
} from "../components/FetchConfigProvider.js";
|
|
25
|
-
import { GraphQLHooksProvider } from "../components/GraphQLHooksProvider.js";
|
|
26
20
|
import { ServerHtmlContext } from "../components/ServerInject.js";
|
|
21
|
+
import { ApolloClientFactoryContext } from "./ApolloClientFactoryContext.js";
|
|
22
|
+
import { fragmentRegistry } from "./fragmentRegistry.js";
|
|
27
23
|
import {
|
|
28
24
|
createAuthApolloLink,
|
|
29
25
|
createFinalLink,
|
|
@@ -38,7 +34,7 @@ const WrappedApolloProvider = WrapApolloProvider(
|
|
|
38
34
|
}
|
|
39
35
|
})
|
|
40
36
|
);
|
|
41
|
-
const ApolloProviderWithFetchConfig = ({ config, children, logLevel, useAuth = useNoAuth }) => {
|
|
37
|
+
const ApolloProviderWithFetchConfig = ({ config, createCache, children, logLevel, useAuth = useNoAuth }) => {
|
|
42
38
|
apolloSetLogVerbosity(logLevel);
|
|
43
39
|
const { uri, headers } = useFetchConfig();
|
|
44
40
|
const { getToken, type: authProviderType } = useAuth();
|
|
@@ -75,39 +71,52 @@ const ApolloProviderWithFetchConfig = ({ config, children, logLevel, useAuth = u
|
|
|
75
71
|
...otherConfig
|
|
76
72
|
});
|
|
77
73
|
}
|
|
78
|
-
|
|
74
|
+
const createApolloClient = (options) => {
|
|
75
|
+
const extraHeaders = options?.headers;
|
|
76
|
+
const withExtraHeaders = new SetContextLink((prevContext) => ({
|
|
77
|
+
headers: { ...prevContext.headers, ...extraHeaders }
|
|
78
|
+
}));
|
|
79
|
+
return new ApolloClient({
|
|
80
|
+
...otherConfig,
|
|
81
|
+
cache: createCache(),
|
|
82
|
+
link: ApolloLink.from([
|
|
83
|
+
withExtraHeaders,
|
|
84
|
+
createFinalLink({
|
|
85
|
+
userConfiguredLink: userPassedLink,
|
|
86
|
+
defaultLinks: redwoodApolloLinks
|
|
87
|
+
})
|
|
88
|
+
])
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
return /* @__PURE__ */ React.createElement(ApolloClientFactoryContext.Provider, { value: createApolloClient }, /* @__PURE__ */ React.createElement(WrappedApolloProvider, { makeClient }, children));
|
|
79
92
|
};
|
|
80
|
-
const
|
|
93
|
+
const CedarApolloProvider = ({
|
|
81
94
|
graphQLClientConfig,
|
|
82
95
|
useAuth = useNoAuth,
|
|
83
96
|
logLevel = "debug",
|
|
84
97
|
children
|
|
85
98
|
}) => {
|
|
86
99
|
const { cacheConfig, ...config } = graphQLClientConfig ?? {};
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
const createCache = () => {
|
|
101
|
+
return new InMemoryCache({
|
|
102
|
+
fragments: fragmentRegistry,
|
|
103
|
+
...cacheConfig
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const cache = createCache().restore(globalThis?.__CEDAR__APOLLO_STATE ?? {});
|
|
90
107
|
return /* @__PURE__ */ React.createElement(FetchConfigProvider, { useAuth }, /* @__PURE__ */ React.createElement(
|
|
91
108
|
ApolloProviderWithFetchConfig,
|
|
92
109
|
{
|
|
93
110
|
config: { cache, ...config },
|
|
111
|
+
createCache,
|
|
94
112
|
useAuth,
|
|
95
113
|
logLevel
|
|
96
114
|
},
|
|
97
|
-
|
|
98
|
-
GraphQLHooksProvider,
|
|
99
|
-
{
|
|
100
|
-
useQuery,
|
|
101
|
-
useMutation,
|
|
102
|
-
useSubscription,
|
|
103
|
-
useSuspenseQuery,
|
|
104
|
-
useBackgroundQuery,
|
|
105
|
-
useReadQuery
|
|
106
|
-
},
|
|
107
|
-
children
|
|
108
|
-
)
|
|
115
|
+
children
|
|
109
116
|
));
|
|
110
117
|
};
|
|
118
|
+
const RedwoodApolloProvider = CedarApolloProvider;
|
|
111
119
|
export {
|
|
120
|
+
CedarApolloProvider,
|
|
112
121
|
RedwoodApolloProvider
|
|
113
122
|
};
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type { ApolloCache, Reference, StoreObject } from '@apollo/client';
|
|
2
|
-
import type { NormalizedCacheObject } from '@apollo/client/cache/inmemory/types.js';
|
|
3
|
-
import type { ApolloQueryResult } from '@apollo/client/core';
|
|
1
|
+
import type { ApolloCache, ApolloClient, NormalizedCacheObject, Reference, StoreObject } from '@apollo/client';
|
|
4
2
|
type useCacheType = {
|
|
5
|
-
cache: ApolloCache
|
|
3
|
+
cache: ApolloCache;
|
|
6
4
|
evict: (object: StoreObject | Reference) => boolean;
|
|
7
5
|
extract: (optimistic?: boolean) => NormalizedCacheObject;
|
|
8
6
|
identify: (object: StoreObject | Reference) => {
|
|
9
7
|
id: string | undefined;
|
|
10
8
|
};
|
|
11
9
|
modify: (object: StoreObject | Reference, fields: Record<string, any>) => boolean;
|
|
12
|
-
resetStore: () => Promise<
|
|
13
|
-
clearStore: () => Promise<
|
|
10
|
+
resetStore: () => Promise<ApolloClient.QueryResult<any>[] | null>;
|
|
11
|
+
clearStore: () => Promise<ApolloClient.QueryResult<any>[] | null>;
|
|
14
12
|
};
|
|
15
13
|
/**
|
|
16
14
|
* Apollo Client stores the results of your GraphQL queries in a local, normalized, in-memory cache.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCache.d.ts","sourceRoot":"","sources":["../../src/apollo/useCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useCache.d.ts","sourceRoot":"","sources":["../../src/apollo/useCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,SAAS,EACT,WAAW,EACZ,MAAM,gBAAgB,CAAA;AAGvB,KAAK,YAAY,GAAG;IAClB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,KAAK,OAAO,CAAA;IACnD,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,KAAK,qBAAqB,CAAA;IACxD,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,KAAK;QAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;IACzE,MAAM,EAAE,CACN,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KACxB,OAAO,CAAA;IACZ,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;IACjE,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;CAClE,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAO,YAmE3B,CAAA"}
|
package/dist/apollo/useCache.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CreateApolloClient } from './ApolloClientFactoryContext.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a factory that builds a new `ApolloClient` sharing
|
|
4
|
+
* `CedarApolloProvider`'s link chain, auth headers and `defaultOptions`, but
|
|
5
|
+
* with its own fresh `InMemoryCache` and, when given, extra headers merged
|
|
6
|
+
* into every operation.
|
|
7
|
+
*
|
|
8
|
+
* Must be called from a component rendered under `CedarApolloProvider`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useCreateApolloClient(): CreateApolloClient;
|
|
11
|
+
//# sourceMappingURL=useCreateApolloClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateApolloClient.d.ts","sourceRoot":"","sources":["../../src/apollo/useCreateApolloClient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AAGzE;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,IAAI,kBAAkB,CAU1D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ApolloClientFactoryContext } from "./ApolloClientFactoryContext.js";
|
|
3
|
+
function useCreateApolloClient() {
|
|
4
|
+
const createClient = React.useContext(ApolloClientFactoryContext);
|
|
5
|
+
if (!createClient) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"useCreateApolloClient must be used within a CedarApolloProvider"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return createClient;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
useCreateApolloClient
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
const require2 = createRequire(import.meta.url);
|
|
5
|
+
const cliPackageJsonFileUrl = pathToFileURL(
|
|
6
|
+
require2.resolve("@cedarjs/cli/package.json")
|
|
7
|
+
);
|
|
8
|
+
const requireFromCli = createRequire(cliPackageJsonFileUrl);
|
|
9
|
+
const bins = requireFromCli("./package.json")["bin"];
|
|
10
|
+
const cliEntryPointUrl = new URL(bins["cedar"], cliPackageJsonFileUrl);
|
|
11
|
+
if (process.env.PROJECT_CWD) {
|
|
12
|
+
process.chdir(process.env.PROJECT_CWD);
|
|
13
|
+
}
|
|
14
|
+
import(cliEntryPointUrl.toString());
|
package/dist/bins/cfw.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
const require2 = createRequire(import.meta.url);
|
|
5
|
+
const cliPackageJsonFileUrl = pathToFileURL(
|
|
6
|
+
require2.resolve("@cedarjs/cli/package.json")
|
|
7
|
+
);
|
|
8
|
+
const requireFromCli = createRequire(cliPackageJsonFileUrl);
|
|
9
|
+
const bins = requireFromCli("./package.json")["bin"];
|
|
10
|
+
const cliEntryPointUrl = new URL(bins["cfw"], cliPackageJsonFileUrl);
|
|
11
|
+
if (process.env.PROJECT_CWD) {
|
|
12
|
+
process.chdir(process.env.PROJECT_CWD);
|
|
13
|
+
}
|
|
14
|
+
import(cliEntryPointUrl.toString());
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
const require2 = createRequire(import.meta.url);
|
|
4
|
+
const requireFromCrossEnv = createRequire(
|
|
5
|
+
require2.resolve("cross-env/package.json")
|
|
6
|
+
);
|
|
7
|
+
const bins = requireFromCrossEnv("./package.json")["bin"];
|
|
8
|
+
requireFromCrossEnv(`./${bins["cross-env"]}`);
|
package/dist/bins/msw.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
const require2 = createRequire(import.meta.url);
|
|
4
|
+
const requireFromMSW = createRequire(require2.resolve("msw/package.json"));
|
|
5
|
+
const bins = requireFromMSW("./package.json")["bin"];
|
|
6
|
+
requireFromMSW(`./${bins["msw"]}`);
|