@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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ApolloClient } from '@apollo/client';
|
|
3
|
+
/**
|
|
4
|
+
* Options accepted by the client factory that `useCreateApolloClient`
|
|
5
|
+
* returns.
|
|
6
|
+
*/
|
|
7
|
+
export interface CreateApolloClientOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Extra headers merged into every operation's headers, alongside the ones
|
|
10
|
+
* `CedarApolloProvider`'s own link chain already sets (auth headers, the
|
|
11
|
+
* headers from `useFetchConfig`, and so on).
|
|
12
|
+
*/
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Builds a new `ApolloClient` that shares `CedarApolloProvider`'s link
|
|
17
|
+
* chain, `defaultOptions` and client config, but gets its own fresh cache
|
|
18
|
+
* and, when given, extra headers on every operation.
|
|
19
|
+
*/
|
|
20
|
+
export type CreateApolloClient = (options?: CreateApolloClientOptions) => ApolloClient;
|
|
21
|
+
/**
|
|
22
|
+
* Set by `ApolloProviderWithFetchConfig` so that `useCreateApolloClient` can
|
|
23
|
+
* build additional Apollo clients from the same configuration.
|
|
24
|
+
*/
|
|
25
|
+
export declare const ApolloClientFactoryContext: React.Context<CreateApolloClient | undefined>;
|
|
26
|
+
//# sourceMappingURL=ApolloClientFactoryContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApolloClientFactoryContext.d.ts","sourceRoot":"","sources":["../../src/apollo/ApolloClientFactoryContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,OAAO,CAAC,EAAE,yBAAyB,KAChC,YAAY,CAAA;AAEjB;;;GAGG;AACH,eAAO,MAAM,0BAA0B,+CAE3B,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Builds a fresh cache from the same cache configuration and fragment
|
|
11
|
+
* registry as `config.cache`. Used to give every client
|
|
12
|
+
* `useCreateApolloClient` creates its own cache.
|
|
13
|
+
*/
|
|
14
|
+
createCache: () => ApolloCache;
|
|
15
|
+
useAuth?: UseAuth;
|
|
16
|
+
logLevel: ReturnType<typeof setLogVerbosity>;
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export declare function ApolloProviderWithFetchConfig({ config, createCache, children, useAuth, logLevel, }: Props): React.JSX.Element;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=ApolloProviderWithFetchConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApolloProviderWithFetchConfig.d.ts","sourceRoot":"","sources":["../../src/apollo/ApolloProviderWithFetchConfig.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,WAAW,EAAgB,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAchF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAQ5C,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,CAAA;KACnB,CAAA;IACD;;;;OAIG;IACH,WAAW,EAAE,MAAM,WAAW,CAAA;IAC9B,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,WAAW,EACX,QAAQ,EACR,OAAmB,EACnB,QAAQ,GACT,EAAE,KAAK,qBAmMP"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
ApolloClient,
|
|
4
|
+
ApolloLink,
|
|
5
|
+
setLogVerbosity as apolloSetLogVerbosity,
|
|
6
|
+
split
|
|
7
|
+
} from "@apollo/client";
|
|
8
|
+
import { SetContextLink } from "@apollo/client/link/context";
|
|
9
|
+
import { PersistedQueryLink } from "@apollo/client/link/persisted-queries";
|
|
10
|
+
import { ApolloProvider } from "@apollo/client/react";
|
|
11
|
+
import { getMainDefinition } from "@apollo/client/utilities";
|
|
12
|
+
import { print } from "graphql/language/printer.js";
|
|
13
|
+
import { map } from "rxjs";
|
|
14
|
+
import { useNoAuth } from "@cedarjs/auth";
|
|
15
|
+
import { UploadHttpLink } from "../bundled/apollo-upload-client.js";
|
|
16
|
+
import { useFetchConfig } from "../components/FetchConfigProvider.js";
|
|
17
|
+
import { ApolloClientFactoryContext } from "./ApolloClientFactoryContext.js";
|
|
18
|
+
import { ErrorBoundary } from "./ErrorBoundary.js";
|
|
19
|
+
import * as SSELinkExports from "./sseLink.js";
|
|
20
|
+
const { SSELink, isSubscription, isLiveQuery } = SSELinkExports;
|
|
21
|
+
function ApolloProviderWithFetchConfig({
|
|
22
|
+
config,
|
|
23
|
+
createCache,
|
|
24
|
+
children,
|
|
25
|
+
useAuth = useNoAuth,
|
|
26
|
+
logLevel
|
|
27
|
+
}) {
|
|
28
|
+
apolloSetLogVerbosity(logLevel);
|
|
29
|
+
const { getToken, type: authProviderType } = useAuth();
|
|
30
|
+
const data = {
|
|
31
|
+
mostRecentRequest: void 0,
|
|
32
|
+
mostRecentResponse: void 0
|
|
33
|
+
};
|
|
34
|
+
const updateDataApolloLink = new ApolloLink((operation, forward) => {
|
|
35
|
+
const { operationName, query, variables } = operation;
|
|
36
|
+
data.mostRecentRequest = {};
|
|
37
|
+
data.mostRecentRequest.operationName = operationName;
|
|
38
|
+
data.mostRecentRequest.operationKind = query?.kind.toString();
|
|
39
|
+
data.mostRecentRequest.variables = variables;
|
|
40
|
+
data.mostRecentRequest.query = query && print(operation.query);
|
|
41
|
+
return forward(operation).pipe(
|
|
42
|
+
map((result) => {
|
|
43
|
+
data.mostRecentResponse = result;
|
|
44
|
+
return result;
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
const withToken = new SetContextLink(async () => {
|
|
49
|
+
const token = await getToken();
|
|
50
|
+
return { token };
|
|
51
|
+
});
|
|
52
|
+
const { headers, uri } = useFetchConfig();
|
|
53
|
+
const authMiddleware = new ApolloLink((operation, forward) => {
|
|
54
|
+
const { token } = operation.getContext();
|
|
55
|
+
const authHeaders = token ? {
|
|
56
|
+
"auth-provider": authProviderType,
|
|
57
|
+
authorization: `Bearer ${token}`
|
|
58
|
+
} : {};
|
|
59
|
+
operation.setContext(() => ({
|
|
60
|
+
headers: {
|
|
61
|
+
...operation.getContext().headers,
|
|
62
|
+
...headers,
|
|
63
|
+
// Duped auth headers, because we may remove the `FetchConfigProvider` at a later date.
|
|
64
|
+
...authHeaders
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
return forward(operation);
|
|
68
|
+
});
|
|
69
|
+
const { httpLinkConfig, link: cedarApolloLink, ...rest } = config ?? {};
|
|
70
|
+
const uploadLink = new UploadHttpLink({
|
|
71
|
+
uri,
|
|
72
|
+
...httpLinkConfig
|
|
73
|
+
});
|
|
74
|
+
const uploadOrSSELink = typeof SSELink !== "undefined" ? split(
|
|
75
|
+
({ query }) => {
|
|
76
|
+
const definition = getMainDefinition(query);
|
|
77
|
+
return isSubscription(definition) || isLiveQuery(definition);
|
|
78
|
+
},
|
|
79
|
+
new SSELink({
|
|
80
|
+
url: uri,
|
|
81
|
+
auth: { authProviderType, tokenFn: getToken },
|
|
82
|
+
httpLinkConfig,
|
|
83
|
+
headers
|
|
84
|
+
}),
|
|
85
|
+
uploadLink
|
|
86
|
+
) : uploadLink;
|
|
87
|
+
const terminatingLink = split(
|
|
88
|
+
({ query }) => {
|
|
89
|
+
const documentQuery = query;
|
|
90
|
+
return documentQuery?.["__meta__"]?.["hash"] !== void 0;
|
|
91
|
+
},
|
|
92
|
+
new PersistedQueryLink({
|
|
93
|
+
generateHash: (document) => {
|
|
94
|
+
const documentWithMeta = document;
|
|
95
|
+
return documentWithMeta.__meta__?.hash ?? "";
|
|
96
|
+
}
|
|
97
|
+
}).concat(uploadOrSSELink),
|
|
98
|
+
uploadOrSSELink
|
|
99
|
+
);
|
|
100
|
+
const cedarApolloLinks = [
|
|
101
|
+
{ name: "withToken", link: withToken },
|
|
102
|
+
{ name: "authMiddleware", link: authMiddleware },
|
|
103
|
+
{ name: "updateDataApolloLink", link: updateDataApolloLink },
|
|
104
|
+
{ name: "httpLink", link: terminatingLink }
|
|
105
|
+
];
|
|
106
|
+
let link = cedarApolloLink;
|
|
107
|
+
link ??= ApolloLink.from(cedarApolloLinks.map((l) => l.link));
|
|
108
|
+
if (typeof link === "function") {
|
|
109
|
+
link = link(cedarApolloLinks);
|
|
110
|
+
}
|
|
111
|
+
const defaultOptions = {
|
|
112
|
+
watchQuery: {
|
|
113
|
+
// The `fetchPolicy` we expect:
|
|
114
|
+
//
|
|
115
|
+
// > Apollo Client executes the full query against both the cache and
|
|
116
|
+
// > your GraphQL server.
|
|
117
|
+
// > The query automatically updates if the result of the server-side
|
|
118
|
+
// > query modifies cached fields.
|
|
119
|
+
//
|
|
120
|
+
// See https://www.apollographql.com/docs/react/data/queries/#cache-and-network.
|
|
121
|
+
fetchPolicy: "cache-and-network",
|
|
122
|
+
// So that Cells rerender when refetching.
|
|
123
|
+
// See https://www.apollographql.com/docs/react/data/queries/#inspecting-loading-states.
|
|
124
|
+
notifyOnNetworkStatusChange: true
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const client = new ApolloClient({
|
|
128
|
+
defaultOptions,
|
|
129
|
+
link,
|
|
130
|
+
...rest
|
|
131
|
+
});
|
|
132
|
+
const createApolloClient = (options) => {
|
|
133
|
+
const extraHeaders = options?.headers;
|
|
134
|
+
const withExtraHeaders = new SetContextLink((prevContext) => ({
|
|
135
|
+
headers: { ...prevContext.headers, ...extraHeaders }
|
|
136
|
+
}));
|
|
137
|
+
return new ApolloClient({
|
|
138
|
+
defaultOptions,
|
|
139
|
+
...rest,
|
|
140
|
+
cache: createCache(),
|
|
141
|
+
link: ApolloLink.from([withExtraHeaders, link])
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
const extendErrorAndRethrow = (error, _errorInfo) => {
|
|
145
|
+
error["mostRecentRequest"] = data.mostRecentRequest;
|
|
146
|
+
error["mostRecentResponse"] = data.mostRecentResponse;
|
|
147
|
+
throw error;
|
|
148
|
+
};
|
|
149
|
+
return /* @__PURE__ */ React.createElement(ApolloClientFactoryContext.Provider, { value: createApolloClient }, /* @__PURE__ */ React.createElement(ApolloProvider, { client }, /* @__PURE__ */ React.createElement(ErrorBoundary, { onError: extendErrorAndRethrow }, children)));
|
|
150
|
+
}
|
|
151
|
+
export {
|
|
152
|
+
ApolloProviderWithFetchConfig
|
|
153
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;AAGhF,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,qBAqCP"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { InMemoryCache } from "@apollo/client";
|
|
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 createCache = () => {
|
|
19
|
+
return new InMemoryCache({
|
|
20
|
+
fragments: fragmentRegistry,
|
|
21
|
+
possibleTypes: cacheConfig?.possibleTypes,
|
|
22
|
+
...cacheConfig
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const cache = createCache().restore(globalThis?.__CEDAR__APOLLO_STATE ?? {});
|
|
26
|
+
return /* @__PURE__ */ React.createElement(FetchConfigProvider, { useAuth }, /* @__PURE__ */ React.createElement(
|
|
27
|
+
ApolloProviderWithFetchConfig,
|
|
28
|
+
{
|
|
29
|
+
config: { cache, ...config },
|
|
30
|
+
createCache,
|
|
31
|
+
useAuth,
|
|
32
|
+
logLevel
|
|
33
|
+
},
|
|
34
|
+
children
|
|
35
|
+
));
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
CedarApolloProvider
|
|
39
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type ComponentDidCatch = React.ComponentLifecycle<any, any>['componentDidCatch'];
|
|
3
|
+
interface ErrorBoundaryProps {
|
|
4
|
+
error?: unknown;
|
|
5
|
+
onError: NonNullable<ComponentDidCatch>;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare class ErrorBoundary extends React.Component<ErrorBoundaryProps> {
|
|
9
|
+
componentDidCatch(...args: Parameters<NonNullable<ComponentDidCatch>>): void;
|
|
10
|
+
render(): React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=ErrorBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../src/apollo/ErrorBoundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,KAAK,iBAAiB,GAAG,KAAK,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,mBAAmB,CAAC,CAAA;AAEhF,UAAU,kBAAkB;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,WAAW,CAAC,iBAAiB,CAAC,CAAA;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED,qBAAa,aAAc,SAAQ,KAAK,CAAC,SAAS,CAAC,kBAAkB,CAAC;IACpE,iBAAiB,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAKrE,MAAM;CAGP"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ApolloCache, ApolloClient, ApolloLink, HttpLink, InMemoryCacheConfig } from '@apollo/client';
|
|
2
|
+
export type ApolloClientCacheConfig = InMemoryCacheConfig;
|
|
3
|
+
export type CedarApolloLinkName = 'withToken' | 'authMiddleware' | 'updateDataApolloLink' | 'httpLink';
|
|
4
|
+
export type CedarApolloLink<Name extends CedarApolloLinkName, Link extends ApolloLink = ApolloLink> = {
|
|
5
|
+
name: Name;
|
|
6
|
+
link: Link;
|
|
7
|
+
};
|
|
8
|
+
export type CedarApolloLinks = [
|
|
9
|
+
CedarApolloLink<'withToken'>,
|
|
10
|
+
CedarApolloLink<'authMiddleware'>,
|
|
11
|
+
CedarApolloLink<'updateDataApolloLink'>,
|
|
12
|
+
CedarApolloLink<'httpLink', ApolloLink | HttpLink>
|
|
13
|
+
];
|
|
14
|
+
export type CedarApolloLinkFactory = (links: CedarApolloLinks) => ApolloLink;
|
|
15
|
+
export type GraphQLClientConfigProp = Omit<ApolloClient.Options, 'cache' | 'link'> & {
|
|
16
|
+
cache?: ApolloCache;
|
|
17
|
+
/**
|
|
18
|
+
* Configuration for Apollo Client's `InMemoryCache`.
|
|
19
|
+
* See https://www.apollographql.com/docs/react/caching/cache-configuration/.
|
|
20
|
+
*/
|
|
21
|
+
cacheConfig?: ApolloClientCacheConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for the terminating `HttpLink`.
|
|
24
|
+
* See https://www.apollographql.com/docs/react/api/link/apollo-link-http/#httplink-constructor-options.
|
|
25
|
+
*
|
|
26
|
+
* For example, you can use this prop to set the credentials policy so that cookies can be sent to other domains:
|
|
27
|
+
*
|
|
28
|
+
* ```js
|
|
29
|
+
* <CedarApolloProvider graphQLClientConfig={{
|
|
30
|
+
* httpLinkConfig: { credentials: 'include' }
|
|
31
|
+
* }}>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
httpLinkConfig?: HttpLink.Options;
|
|
35
|
+
/**
|
|
36
|
+
* Extend or overwrite `CedarApolloProvider`'s Apollo Link.
|
|
37
|
+
*
|
|
38
|
+
* To overwrite Cedar's Apollo Link, just provide your own `ApolloLink`.
|
|
39
|
+
*
|
|
40
|
+
* To extend Cedar's Apollo Link, provide a function—it'll get passed an array of Cedar's Apollo Links
|
|
41
|
+
* which are objects with a name and link property:
|
|
42
|
+
*
|
|
43
|
+
* ```js
|
|
44
|
+
* const link = (cedarApolloLinks) => {
|
|
45
|
+
* const consoleLink = new ApolloLink((operation, forward) => {
|
|
46
|
+
* console.log(operation.operationName)
|
|
47
|
+
* return forward(operation)
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
50
|
+
* return ApolloLink.from([consoleLink, ...cedarApolloLinks.map(({ link }) => link)])
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* If you do this, there's a few things you should keep in mind:
|
|
55
|
+
* - your function should return a single link (e.g., using `ApolloLink.from`; see https://www.apollographql.com/docs/react/api/link/introduction/#additive-composition)
|
|
56
|
+
* - the `HttpLink` should come last (https://www.apollographql.com/docs/react/api/link/introduction/#the-terminating-link)
|
|
57
|
+
*/
|
|
58
|
+
link?: ApolloLink | CedarApolloLinkFactory;
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=apolloLinkTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apolloLinkTypes.d.ts","sourceRoot":"","sources":["../../src/apollo/apolloLinkTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,mBAAmB,EACpB,MAAM,gBAAgB,CAAA;AAEvB,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAEzD,MAAM,MAAM,mBAAmB,GAC7B,WAAW,GAAG,gBAAgB,GAAG,sBAAsB,GAAG,UAAU,CAAA;AAEtE,MAAM,MAAM,eAAe,CACzB,IAAI,SAAS,mBAAmB,EAChC,IAAI,SAAS,UAAU,GAAG,UAAU,IAClC;IACF,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,eAAe,CAAC,WAAW,CAAC;IAC5B,eAAe,CAAC,gBAAgB,CAAC;IACjC,eAAe,CAAC,sBAAsB,CAAC;IACvC,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,CAAC;CACnD,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,gBAAgB,KAAK,UAAU,CAAA;AAE5E,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,YAAY,CAAC,OAAO,EACpB,OAAO,GAAG,MAAM,CACjB,GAAG;IACF,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB;;;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,sBAAsB,CAAA;CAC3C,CAAA"}
|
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
1
|
+
import type { FragmentRegistryAPI } from '@apollo/client/cache';
|
|
2
|
+
import { useFragment as useApolloFragment } from '@apollo/client/react';
|
|
3
3
|
import type { DocumentNode } from 'graphql';
|
|
4
|
+
export interface FragmentHookOptions {
|
|
5
|
+
fragment: DocumentNode;
|
|
6
|
+
fragmentName?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The object to read the fragment data for. Usually a cache reference like
|
|
9
|
+
* `{ __typename: 'User', id: 1 }`, but any object that Apollo Client can
|
|
10
|
+
* identify works.
|
|
11
|
+
*/
|
|
12
|
+
from: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export interface FragmentHookResult<TData = any> {
|
|
15
|
+
/**
|
|
16
|
+
* The fragment data read from Apollo Client's cache, or `undefined` if the
|
|
17
|
+
* cache doesn't (yet) contain complete data for the fragment.
|
|
18
|
+
*/
|
|
19
|
+
data: TData | undefined;
|
|
20
|
+
complete: boolean;
|
|
21
|
+
}
|
|
4
22
|
export type FragmentIdentifier = string | number;
|
|
5
23
|
export type CacheKey = {
|
|
6
24
|
__typename: string;
|
|
@@ -10,8 +28,15 @@ export type RegisterFragmentResult = {
|
|
|
10
28
|
fragment: DocumentNode;
|
|
11
29
|
typename: string;
|
|
12
30
|
getCacheKey: (id: FragmentIdentifier) => CacheKey;
|
|
13
|
-
useRegisteredFragment: <TData = any>(id: FragmentIdentifier) =>
|
|
31
|
+
useRegisteredFragment: <TData = any>(id: FragmentIdentifier) => useApolloFragment.Result<TData>;
|
|
14
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Read fragment data from Apollo Client's cache without firing a network
|
|
35
|
+
* request. Used by fragment Cells (Cells that export `FRAGMENT` instead of
|
|
36
|
+
* `QUERY`). Incomplete reads surface `data: undefined` so that fragment Cells
|
|
37
|
+
* fall back to the data snapshot passed via their data prop.
|
|
38
|
+
*/
|
|
39
|
+
export declare function useFragment<TData = any>(options: FragmentHookOptions): FragmentHookResult<TData>;
|
|
15
40
|
/**
|
|
16
41
|
* Creates a fragment registry for Apollo Client's InMemoryCache so that they
|
|
17
42
|
* can be referred to by name in any query or InMemoryCache operation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragmentRegistry.d.ts","sourceRoot":"","sources":["../../src/apollo/fragmentRegistry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"fragmentRegistry.d.ts","sourceRoot":"","sources":["../../src/apollo/fragmentRegistry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAE/D,OAAO,EAEL,WAAW,IAAI,iBAAiB,EACjC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,YAAY,EAA0B,MAAM,SAAS,CAAA;AAGnE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B;AAED,MAAM,WAAW,kBAAkB,CAAC,KAAK,GAAG,GAAG;IAC7C;;;OAGG;IACH,IAAI,EAAE,KAAK,GAAG,SAAS,CAAA;IACvB,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,CAAA;AAEhD,MAAM,MAAM,QAAQ,GAAG;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,EAAE,EAAE,kBAAkB,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,YAAY,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,CAAC,EAAE,EAAE,kBAAkB,KAAK,QAAQ,CAAA;IACjD,qBAAqB,EAAE,CAAC,KAAK,GAAG,GAAG,EACjC,EAAE,EAAE,kBAAkB,KACnB,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;CACrC,CAAA;AA4ED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,GAAG,GAAG,EACrC,OAAO,EAAE,mBAAmB,GAC3B,kBAAkB,CAAC,KAAK,CAAC,CA6B3B;AAED;;;;;;;IAOI;AACJ,eAAO,MAAM,gBAAgB,EAAE,mBAA8C,CAAA;AAE7E;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,YAAY,EAAE,6BAE1D,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,YAAY,KACrB,sBAqBF,CAAA"}
|
|
@@ -1,17 +1,61 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { createFragmentRegistry } from "@apollo/client/cache";
|
|
2
|
+
import {
|
|
3
|
+
useApolloClient,
|
|
4
|
+
useFragment as useApolloFragment
|
|
5
|
+
} from "@apollo/client/react";
|
|
6
|
+
import { Kind } from "graphql";
|
|
7
|
+
const getFragmentDefinition = (fragment) => {
|
|
8
|
+
const definition = fragment.definitions.find(
|
|
9
|
+
(def) => def.kind === Kind.FRAGMENT_DEFINITION
|
|
10
|
+
);
|
|
11
|
+
if (!definition) {
|
|
12
|
+
throw new Error("The passed document contains no fragment definition");
|
|
13
|
+
}
|
|
14
|
+
return definition;
|
|
15
|
+
};
|
|
4
16
|
const getTypenameFromFragment = (fragment) => {
|
|
5
|
-
|
|
6
|
-
|
|
17
|
+
return getFragmentDefinition(fragment).typeCondition.name.value;
|
|
18
|
+
};
|
|
19
|
+
const getSingleFragmentName = (fragment) => {
|
|
20
|
+
const definitions = fragment.definitions.filter(
|
|
21
|
+
(def) => def.kind === Kind.FRAGMENT_DEFINITION
|
|
22
|
+
);
|
|
23
|
+
return definitions.length === 1 ? definitions[0].name.value : void 0;
|
|
7
24
|
};
|
|
8
25
|
const useRegisteredFragmentHook = (fragment, id) => {
|
|
9
26
|
const from = { __typename: getTypenameFromFragment(fragment), id };
|
|
10
|
-
return
|
|
27
|
+
return useApolloFragment({
|
|
11
28
|
fragment,
|
|
29
|
+
// The cache's fragment registry adds the definitions of any spread
|
|
30
|
+
// fragments to the document, so Apollo Client can't infer the fragment
|
|
31
|
+
// name from the document alone
|
|
32
|
+
fragmentName: getFragmentDefinition(fragment).name.value,
|
|
12
33
|
from
|
|
13
34
|
});
|
|
14
35
|
};
|
|
36
|
+
const UNIDENTIFIABLE_FRAGMENT_REF = "CedarUnidentifiableFragmentRef:_";
|
|
37
|
+
function useFragment(options) {
|
|
38
|
+
const client = useApolloClient();
|
|
39
|
+
const { from, ...restOptions } = options;
|
|
40
|
+
const cacheId = client.cache.identify(from);
|
|
41
|
+
const result = useApolloFragment({
|
|
42
|
+
...restOptions,
|
|
43
|
+
// The cache's fragment registry adds the definitions of any spread
|
|
44
|
+
// fragments to the document, so Apollo Client can't infer the fragment
|
|
45
|
+
// name from the document alone. When the passed document has more than
|
|
46
|
+
// one fragment definition of its own we pass `undefined` and let Apollo
|
|
47
|
+
// Client surface its "must provide fragmentName" error
|
|
48
|
+
fragmentName: restOptions.fragmentName ?? getSingleFragmentName(options.fragment),
|
|
49
|
+
// We identify the object ourselves (above) because passing an
|
|
50
|
+
// unidentifiable object to `useFragment` logs a warning and returns a
|
|
51
|
+
// useless `{ data: {}, complete: true }` result
|
|
52
|
+
from: cacheId ?? UNIDENTIFIABLE_FRAGMENT_REF
|
|
53
|
+
});
|
|
54
|
+
if (cacheId !== void 0 && result.complete) {
|
|
55
|
+
return { data: result.data, complete: true };
|
|
56
|
+
}
|
|
57
|
+
return { data: void 0, complete: false };
|
|
58
|
+
}
|
|
15
59
|
const fragmentRegistry = createFragmentRegistry();
|
|
16
60
|
const registerFragments = (fragments) => {
|
|
17
61
|
return fragments.map(registerFragment);
|
|
@@ -35,5 +79,6 @@ const registerFragment = (fragment) => {
|
|
|
35
79
|
export {
|
|
36
80
|
fragmentRegistry,
|
|
37
81
|
registerFragment,
|
|
38
|
-
registerFragments
|
|
82
|
+
registerFragments,
|
|
83
|
+
useFragment
|
|
39
84
|
};
|
package/dist/apollo/index.d.ts
CHANGED
|
@@ -1,76 +1,60 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import './typeOverride.js';
|
|
1
|
+
import type { ApolloLink } from '@apollo/client';
|
|
2
|
+
import type { CreateApolloClientOptions } from './ApolloClientFactoryContext.js';
|
|
3
|
+
import { CedarApolloProvider } from './CedarApolloProvider.js';
|
|
4
|
+
import type { ApolloClientCacheConfig as CedarApolloClientCacheConfig, CedarApolloLink, CedarApolloLinkFactory, CedarApolloLinkName, CedarApolloLinks, GraphQLClientConfigProp as CedarGraphQLClientConfigProp } from './CedarApolloProvider.js';
|
|
6
5
|
import { fragmentRegistry, registerFragment, registerFragments } from './fragmentRegistry.js';
|
|
7
6
|
import { useCache } from './useCache.js';
|
|
7
|
+
import { useCreateApolloClient } from './useCreateApolloClient.js';
|
|
8
8
|
export type { CacheKey, FragmentIdentifier, RegisterFragmentResult, } from './fragmentRegistry.js';
|
|
9
|
+
export type { CreateApolloClientOptions };
|
|
9
10
|
export { useCache };
|
|
11
|
+
export { useCreateApolloClient };
|
|
10
12
|
export { fragmentRegistry, registerFragment, registerFragments };
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
* return ApolloLink.from([consoleLink, ...redwoodApolloLinks.map(({ link }) => link)])
|
|
60
|
-
* }
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* If you do this, there's a few things you should keep in mind:
|
|
64
|
-
* - your function should return a single link (e.g., using `ApolloLink.from`; see https://www.apollographql.com/docs/react/api/link/introduction/#additive-composition)
|
|
65
|
-
* - the `HttpLink` should come last (https://www.apollographql.com/docs/react/api/link/introduction/#the-terminating-link)
|
|
66
|
-
*/
|
|
67
|
-
link?: ApolloLink | RedwoodApolloLinkFactory;
|
|
68
|
-
};
|
|
69
|
-
export declare const RedwoodApolloProvider: React.FunctionComponent<{
|
|
70
|
-
graphQLClientConfig?: GraphQLClientConfigProp;
|
|
71
|
-
fragments?: DocumentNode[];
|
|
72
|
-
useAuth?: UseAuth;
|
|
73
|
-
logLevel?: ReturnType<typeof setLogVerbosity>;
|
|
74
|
-
children: React.ReactNode;
|
|
75
|
-
}>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Import from `@cedarjs/web/apollo/CedarApolloProvider` instead.
|
|
15
|
+
* This re-export will be removed in a future release.
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* import type { ApolloClientCacheConfig } from '@cedarjs/web/apollo/CedarApolloProvider'
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type ApolloClientCacheConfig = CedarApolloClientCacheConfig;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Import from `@cedarjs/web/apollo/CedarApolloProvider` instead.
|
|
24
|
+
* This re-export will be removed in a future release.
|
|
25
|
+
*
|
|
26
|
+
* ```js
|
|
27
|
+
* import type { GraphQLClientConfigProp } from '@cedarjs/web/apollo/CedarApolloProvider'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type GraphQLClientConfigProp = CedarGraphQLClientConfigProp;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use `CedarApolloLinkName` instead. `RedwoodApolloLinkName` will
|
|
33
|
+
* be removed in a future release.
|
|
34
|
+
*/
|
|
35
|
+
export type RedwoodApolloLinkName = CedarApolloLinkName;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use `CedarApolloLink` instead. `RedwoodApolloLink` will be
|
|
38
|
+
* removed in a future release.
|
|
39
|
+
*/
|
|
40
|
+
export type RedwoodApolloLink<Name extends CedarApolloLinkName, Link extends ApolloLink = ApolloLink> = CedarApolloLink<Name, Link>;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use `CedarApolloLinks` instead. `RedwoodApolloLinks` will be
|
|
43
|
+
* removed in a future release.
|
|
44
|
+
*/
|
|
45
|
+
export type RedwoodApolloLinks = CedarApolloLinks;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use `CedarApolloLinkFactory` instead. `RedwoodApolloLinkFactory`
|
|
48
|
+
* will be removed in a future release.
|
|
49
|
+
*/
|
|
50
|
+
export type RedwoodApolloLinkFactory = CedarApolloLinkFactory;
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated Use `CedarApolloProvider` instead. `RedwoodApolloProvider` will
|
|
53
|
+
* be removed in a future release.
|
|
54
|
+
*
|
|
55
|
+
* ```js
|
|
56
|
+
* import { CedarApolloProvider } from '@cedarjs/web/apollo/CedarApolloProvider'
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const RedwoodApolloProvider: typeof CedarApolloProvider;
|
|
76
60
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apollo/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apollo/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAA;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,KAAK,EACV,uBAAuB,IAAI,4BAA4B,EACvD,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,IAAI,4BAA4B,EACxD,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAElE,YAAY,EACV,QAAQ,EACR,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,uBAAuB,CAAA;AAE9B,YAAY,EAAE,yBAAyB,EAAE,CAAA;AAEzC,OAAO,EAAE,QAAQ,EAAE,CAAA;AAEnB,OAAO,EAAE,qBAAqB,EAAE,CAAA;AAEhC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAA;AAEhE;;;;;;;GAOG;AACH,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,CAAA;AAElE;;;;;;;GAOG;AACH,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,CAAA;AAElE;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,CAAA;AAEvD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAC3B,IAAI,SAAS,mBAAmB,EAChC,IAAI,SAAS,UAAU,GAAG,UAAU,IAClC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AAE/B;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,gBAAgB,CAAA;AAEjD;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,CAAA;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,4BAAsB,CAAA"}
|