@cedarjs/web 0.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/LICENSE +21 -0
- package/README.md +33 -0
- package/apollo/index.js +2 -0
- package/apollo/package.json +4 -0
- package/dist/apollo/fragmentRegistry.d.ts +43 -0
- package/dist/apollo/fragmentRegistry.d.ts.map +1 -0
- package/dist/apollo/fragmentRegistry.js +39 -0
- package/dist/apollo/index.d.ts +77 -0
- package/dist/apollo/index.d.ts.map +1 -0
- package/dist/apollo/index.js +198 -0
- package/dist/apollo/links.d.ts +27 -0
- package/dist/apollo/links.d.ts.map +1 -0
- package/dist/apollo/links.js +94 -0
- package/dist/apollo/sseLink.d.ts +29 -0
- package/dist/apollo/sseLink.d.ts.map +1 -0
- package/dist/apollo/sseLink.js +94 -0
- package/dist/apollo/suspense.d.ts +59 -0
- package/dist/apollo/suspense.d.ts.map +1 -0
- package/dist/apollo/suspense.js +113 -0
- package/dist/apollo/typeOverride.d.ts +21 -0
- package/dist/apollo/typeOverride.d.ts.map +1 -0
- package/dist/apollo/typeOverride.js +0 -0
- package/dist/apollo/useCache.d.ts +22 -0
- package/dist/apollo/useCache.d.ts.map +1 -0
- package/dist/apollo/useCache.js +25 -0
- package/dist/bins/cross-env.d.ts +3 -0
- package/dist/bins/cross-env.d.ts.map +1 -0
- package/dist/bins/msw.d.ts +3 -0
- package/dist/bins/msw.d.ts.map +1 -0
- package/dist/bins/redwood.d.ts +9 -0
- package/dist/bins/redwood.d.ts.map +1 -0
- package/dist/bins/rwfw.d.ts +3 -0
- package/dist/bins/rwfw.d.ts.map +1 -0
- package/dist/bins/storybook.d.ts +3 -0
- package/dist/bins/storybook.d.ts.map +1 -0
- package/dist/bins/tsc.d.ts +3 -0
- package/dist/bins/tsc.d.ts.map +1 -0
- package/dist/bundled/apollo-upload-client.d.ts +3 -0
- package/dist/bundled/apollo-upload-client.d.ts.map +1 -0
- package/dist/bundled/apollo-upload-client.js +4 -0
- 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 +77 -0
- package/dist/cjs/apollo/index.d.ts.map +1 -0
- package/dist/cjs/apollo/index.js +216 -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/cjs/apollo/suspense.d.ts +59 -0
- 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/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/rwfw.d.ts +3 -0
- package/dist/cjs/bins/rwfw.d.ts.map +1 -0
- package/dist/cjs/bins/rwfw.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 +2474 -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 +436 -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 +69 -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 +95 -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 +58 -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/entry/index.js +39 -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 +24 -0
- package/dist/cjs/graphql.d.ts.map +1 -0
- package/dist/cjs/graphql.js +36 -0
- package/dist/cjs/index.d.ts +20 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +80 -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/DevFatalErrorPage.d.ts +21 -0
- package/dist/components/DevFatalErrorPage.d.ts.map +1 -0
- package/dist/components/DevFatalErrorPage.js +402 -0
- package/dist/components/FatalErrorBoundary.d.ts +24 -0
- package/dist/components/FatalErrorBoundary.d.ts.map +1 -0
- package/dist/components/FatalErrorBoundary.js +29 -0
- package/dist/components/FetchConfigProvider.d.ts +25 -0
- package/dist/components/FetchConfigProvider.d.ts.map +1 -0
- package/dist/components/FetchConfigProvider.js +43 -0
- 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/MetaTags.d.ts +52 -0
- package/dist/components/MetaTags.d.ts.map +1 -0
- package/dist/components/MetaTags.js +35 -0
- package/dist/components/Metadata.d.ts +9 -0
- package/dist/components/Metadata.d.ts.map +1 -0
- package/dist/components/Metadata.js +61 -0
- package/dist/components/PortalHead.d.ts +4 -0
- package/dist/components/PortalHead.d.ts.map +1 -0
- package/dist/components/PortalHead.js +29 -0
- package/dist/components/RedwoodProvider.d.ts +9 -0
- package/dist/components/RedwoodProvider.d.ts.map +1 -0
- package/dist/components/RedwoodProvider.js +24 -0
- package/dist/components/ServerInject.d.ts +26 -0
- package/dist/components/ServerInject.d.ts.map +1 -0
- package/dist/components/ServerInject.js +37 -0
- package/dist/components/cell/CellCacheContext.d.ts +20 -0
- package/dist/components/cell/CellCacheContext.d.ts.map +1 -0
- package/dist/components/cell/CellCacheContext.js +18 -0
- package/dist/components/cell/CellErrorBoundary.d.ts +25 -0
- package/dist/components/cell/CellErrorBoundary.d.ts.map +1 -0
- package/dist/components/cell/CellErrorBoundary.js +32 -0
- package/dist/components/cell/cellTypes.d.ts +152 -0
- package/dist/components/cell/cellTypes.d.ts.map +1 -0
- package/dist/components/cell/cellTypes.js +0 -0
- package/dist/components/cell/createCell.d.ts +10 -0
- package/dist/components/cell/createCell.d.ts.map +1 -0
- package/dist/components/cell/createCell.js +131 -0
- package/dist/components/cell/createCell.test.js +328 -0
- package/dist/components/cell/createServerCell.d.ts +15 -0
- package/dist/components/cell/createServerCell.d.ts.map +1 -0
- package/dist/components/cell/createServerCell.js +57 -0
- package/dist/components/cell/createSuspendingCell.d.ts +11 -0
- package/dist/components/cell/createSuspendingCell.d.ts.map +1 -0
- package/dist/components/cell/createSuspendingCell.js +118 -0
- package/dist/components/cell/createSuspendingCell.test.js +92 -0
- package/dist/components/cell/isCellEmpty.d.ts +41 -0
- package/dist/components/cell/isCellEmpty.d.ts.map +1 -0
- package/dist/components/cell/isCellEmpty.js +11 -0
- package/dist/components/htmlTags.d.ts +52 -0
- package/dist/components/htmlTags.d.ts.map +1 -0
- package/dist/components/htmlTags.js +53 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +5 -0
- package/dist/entry/index.d.ts +1 -0
- package/dist/entry/index.js +16 -0
- package/dist/global.web-auto-imports.d.ts +30 -0
- package/dist/global.web-auto-imports.d.ts.map +1 -0
- package/dist/global.web-auto-imports.js +0 -0
- package/dist/graphql.d.ts +24 -0
- package/dist/graphql.d.ts.map +1 -0
- package/dist/graphql.js +12 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/package.json +1 -0
- package/dist/routeHooks.types.d.ts +12 -0
- package/dist/routeHooks.types.d.ts.map +1 -0
- package/dist/routeHooks.types.js +0 -0
- package/dist/server/MiddlewareRequest.d.ts +28 -0
- package/dist/server/MiddlewareRequest.d.ts.map +1 -0
- package/dist/server/MiddlewareRequest.js +46 -0
- package/dist/server/MiddlewareResponse.d.ts +44 -0
- package/dist/server/MiddlewareResponse.d.ts.map +1 -0
- package/dist/server/MiddlewareResponse.js +95 -0
- package/dist/server/middleware.d.ts +17 -0
- package/dist/server/middleware.d.ts.map +1 -0
- package/dist/server/middleware.js +2 -0
- package/dist/server/request.d.ts +2 -0
- package/dist/server/request.d.ts.map +1 -0
- package/dist/server/request.js +12 -0
- package/dist/streamUtils/useDocumentReady.d.ts +11 -0
- package/dist/streamUtils/useDocumentReady.d.ts.map +1 -0
- package/dist/streamUtils/useDocumentReady.js +17 -0
- package/dist/toast/index.d.ts +3 -0
- package/dist/toast/index.d.ts.map +1 -0
- package/dist/toast/index.js +5 -0
- package/package.json +193 -0
- package/src/entry/index.jsx +29 -0
- package/toast/index.js +2 -0
- package/toast/package.json +4 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ApolloLink } from "@apollo/client/link/core/core.cjs";
|
|
2
|
+
import { Observable } from "@apollo/client/utilities/utilities.cjs";
|
|
3
|
+
import { Kind, OperationTypeNode, print } from "graphql";
|
|
4
|
+
import { createClient } from "graphql-sse";
|
|
5
|
+
const mapCredentialsHeader = (httpLinkCredentials) => {
|
|
6
|
+
if (!httpLinkCredentials) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
switch (httpLinkCredentials) {
|
|
10
|
+
case "omit":
|
|
11
|
+
case "same-origin":
|
|
12
|
+
case "include":
|
|
13
|
+
return httpLinkCredentials;
|
|
14
|
+
default:
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const mapReferrerPolicyHeader = (referrerPolicy) => {
|
|
19
|
+
if (!referrerPolicy) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
switch (referrerPolicy) {
|
|
23
|
+
case "no-referrer":
|
|
24
|
+
case "no-referrer-when-downgrade":
|
|
25
|
+
case "same-origin":
|
|
26
|
+
case "origin":
|
|
27
|
+
case "strict-origin":
|
|
28
|
+
case "origin-when-cross-origin":
|
|
29
|
+
case "strict-origin-when-cross-origin":
|
|
30
|
+
case "unsafe-url":
|
|
31
|
+
return referrerPolicy;
|
|
32
|
+
default:
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const hasTrustedDocument = (operation) => {
|
|
37
|
+
return operation.extensions?.persistedQuery?.sha256Hash;
|
|
38
|
+
};
|
|
39
|
+
const isSubscription = (definition) => {
|
|
40
|
+
return definition.kind === Kind.OPERATION_DEFINITION && definition.operation === OperationTypeNode.SUBSCRIPTION;
|
|
41
|
+
};
|
|
42
|
+
const isLiveQuery = (definition) => {
|
|
43
|
+
if (definition.kind !== Kind.OPERATION_DEFINITION || definition.operation !== OperationTypeNode.QUERY) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return !!definition.directives?.find((d) => d.name.value === "live");
|
|
47
|
+
};
|
|
48
|
+
class SSELink extends ApolloLink {
|
|
49
|
+
client;
|
|
50
|
+
constructor(options) {
|
|
51
|
+
super();
|
|
52
|
+
const { url, auth, headers, httpLinkConfig } = options;
|
|
53
|
+
const { credentials, referrer, referrerPolicy, ...customHeaders } = httpLinkConfig?.headers || {};
|
|
54
|
+
this.client = createClient({
|
|
55
|
+
url,
|
|
56
|
+
headers: async () => {
|
|
57
|
+
const token = await auth.tokenFn();
|
|
58
|
+
return {
|
|
59
|
+
...token && { Authorization: `Bearer ${token}` },
|
|
60
|
+
...token && { "auth-provider": auth.authProviderType },
|
|
61
|
+
...headers,
|
|
62
|
+
...customHeaders
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
credentials: mapCredentialsHeader(credentials),
|
|
66
|
+
referrer,
|
|
67
|
+
referrerPolicy: mapReferrerPolicyHeader(referrerPolicy)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
request(operation) {
|
|
71
|
+
return new Observable((sink) => {
|
|
72
|
+
let request;
|
|
73
|
+
if (hasTrustedDocument(operation)) {
|
|
74
|
+
delete operation.query;
|
|
75
|
+
request = { ...operation };
|
|
76
|
+
} else {
|
|
77
|
+
request = {
|
|
78
|
+
...operation,
|
|
79
|
+
query: print(operation.query)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return this.client.subscribe(request, {
|
|
83
|
+
next: sink.next.bind(sink),
|
|
84
|
+
complete: sink.complete.bind(sink),
|
|
85
|
+
error: sink.error.bind(sink)
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
SSELink,
|
|
92
|
+
isLiveQuery,
|
|
93
|
+
isSubscription
|
|
94
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ApolloCache, ApolloClientOptions, ApolloLink, HttpOptions, InMemoryCacheConfig, setLogVerbosity } from '@apollo/client';
|
|
3
|
+
import type { UseAuth } from '@cedarjs/auth';
|
|
4
|
+
import './typeOverride.js';
|
|
5
|
+
import type { RedwoodApolloLink, RedwoodApolloLinkFactory, RedwoodApolloLinkName, RedwoodApolloLinks } from './links.js';
|
|
6
|
+
export type ApolloClientCacheConfig = InMemoryCacheConfig;
|
|
7
|
+
export type { RedwoodApolloLink, RedwoodApolloLinkFactory, RedwoodApolloLinkName, RedwoodApolloLinks, };
|
|
8
|
+
export type GraphQLClientConfigProp = Omit<ApolloClientOptions<unknown>, 'cache' | 'link'> & {
|
|
9
|
+
cache?: ApolloCache<unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for Apollo Client's `InMemoryCache`.
|
|
12
|
+
* See https://www.apollographql.com/docs/react/caching/cache-configuration/.
|
|
13
|
+
*/
|
|
14
|
+
cacheConfig?: ApolloClientCacheConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for the terminating `HttpLink`.
|
|
17
|
+
* See https://www.apollographql.com/docs/react/api/link/apollo-link-http/#httplink-constructor-options.
|
|
18
|
+
*
|
|
19
|
+
* For example, you can use this prop to set the credentials policy so that cookies can be sent to other domains:
|
|
20
|
+
*
|
|
21
|
+
* ```js
|
|
22
|
+
* <RedwoodApolloProvider graphQLClientConfig={{
|
|
23
|
+
* httpLinkConfig: { credentials: 'include' }
|
|
24
|
+
* }}>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
httpLinkConfig?: HttpOptions;
|
|
28
|
+
/**
|
|
29
|
+
* Extend or overwrite `RedwoodApolloProvider`'s Apollo Link.
|
|
30
|
+
*
|
|
31
|
+
* To overwrite Redwood's Apollo Link, just provide your own `ApolloLink`.
|
|
32
|
+
*
|
|
33
|
+
* To extend Redwood's Apollo Link, provide a function—it'll get passed an array of Redwood's Apollo Links
|
|
34
|
+
* which are objects with a name and link property:
|
|
35
|
+
*
|
|
36
|
+
* ```js
|
|
37
|
+
* const link = (redwoodApolloLinks) => {
|
|
38
|
+
* const consoleLink = new ApolloLink((operation, forward) => {
|
|
39
|
+
* console.log(operation.operationName)
|
|
40
|
+
* return forward(operation)
|
|
41
|
+
* })
|
|
42
|
+
*
|
|
43
|
+
* return ApolloLink.from([consoleLink, ...redwoodApolloLinks.map(({ link }) => link)])
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* If you do this, there's a few things you should keep in mind:
|
|
48
|
+
* - your function should return a single link (e.g., using `ApolloLink.from`; see https://www.apollographql.com/docs/react/api/link/introduction/#additive-composition)
|
|
49
|
+
* - the `HttpLink` should come last (https://www.apollographql.com/docs/react/api/link/introduction/#the-terminating-link)
|
|
50
|
+
*/
|
|
51
|
+
link?: ApolloLink | RedwoodApolloLinkFactory;
|
|
52
|
+
};
|
|
53
|
+
export declare const RedwoodApolloProvider: React.FunctionComponent<{
|
|
54
|
+
graphQLClientConfig?: GraphQLClientConfigProp;
|
|
55
|
+
useAuth?: UseAuth;
|
|
56
|
+
logLevel?: ReturnType<typeof setLogVerbosity>;
|
|
57
|
+
children: React.ReactNode;
|
|
58
|
+
}>;
|
|
59
|
+
//# sourceMappingURL=suspense.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../../src/apollo/suspense.tsx"],"names":[],"mappings":"AASA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,eAAe,EAChB,MAAM,gBAAgB,CAAA;AAiBvB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAG5C,OAAO,mBAAmB,CAAA;AAS1B,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,mBAAmB,CAAC,OAAO,CAAC,EAC5B,OAAO,GAAG,MAAM,CACjB,GAAG;IACF,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,uBAAuB,CAAA;IACrC;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,WAAW,CAAA;IAC5B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,CAAC,EAAE,UAAU,GAAG,wBAAwB,CAAA;CAC7C,CAAA;AAkFD,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAC1D,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,CAoCA,CAAA"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { useContext } from "react";
|
|
3
|
+
import { setLogVerbosity as apolloSetLogVerbosity } from "@apollo/client/core/index.js";
|
|
4
|
+
import {
|
|
5
|
+
useMutation,
|
|
6
|
+
useSubscription,
|
|
7
|
+
useBackgroundQuery,
|
|
8
|
+
useQuery,
|
|
9
|
+
useReadQuery,
|
|
10
|
+
useSuspenseQuery
|
|
11
|
+
} from "@apollo/client/react/hooks/index.js";
|
|
12
|
+
import {
|
|
13
|
+
ApolloClient,
|
|
14
|
+
InMemoryCache,
|
|
15
|
+
WrapApolloProvider
|
|
16
|
+
} from "@apollo/client-react-streaming";
|
|
17
|
+
import { buildManualDataTransport } from "@apollo/client-react-streaming/manual-transport";
|
|
18
|
+
import { useNoAuth } from "@cedarjs/auth";
|
|
19
|
+
import { ServerAuthContext } from "@cedarjs/auth/dist/AuthProvider/ServerAuthProvider.js";
|
|
20
|
+
import "./typeOverride.js";
|
|
21
|
+
import {
|
|
22
|
+
FetchConfigProvider,
|
|
23
|
+
useFetchConfig
|
|
24
|
+
} from "../components/FetchConfigProvider.js";
|
|
25
|
+
import { GraphQLHooksProvider } from "../components/GraphQLHooksProvider.js";
|
|
26
|
+
import { ServerHtmlContext } from "../components/ServerInject.js";
|
|
27
|
+
import {
|
|
28
|
+
createAuthApolloLink,
|
|
29
|
+
createFinalLink,
|
|
30
|
+
createHttpLink,
|
|
31
|
+
createTokenLink,
|
|
32
|
+
createUpdateDataLink
|
|
33
|
+
} from "./links.js";
|
|
34
|
+
const WrappedApolloProvider = WrapApolloProvider(
|
|
35
|
+
buildManualDataTransport({
|
|
36
|
+
useInsertHtml() {
|
|
37
|
+
return React.useContext(ServerHtmlContext);
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
const ApolloProviderWithFetchConfig = ({ config, children, logLevel, useAuth = useNoAuth }) => {
|
|
42
|
+
apolloSetLogVerbosity(logLevel);
|
|
43
|
+
const { uri, headers } = useFetchConfig();
|
|
44
|
+
const { getToken, type: authProviderType } = useAuth();
|
|
45
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
46
|
+
const serverAuthState = useContext(ServerAuthContext);
|
|
47
|
+
const getGraphqlUrl = () => {
|
|
48
|
+
return typeof window === "undefined" ? RWJS_ENV.RWJS_EXP_SSR_GRAPHQL_ENDPOINT : uri;
|
|
49
|
+
};
|
|
50
|
+
const { httpLinkConfig, link: userPassedLink, ...otherConfig } = config ?? {};
|
|
51
|
+
const redwoodApolloLinks = [
|
|
52
|
+
// @MARK REMOVE: We will not need these for cookie based auth ~~~~
|
|
53
|
+
{ name: "withToken", link: createTokenLink(getToken) },
|
|
54
|
+
{
|
|
55
|
+
name: "authMiddleware",
|
|
56
|
+
link: createAuthApolloLink(authProviderType, headers)
|
|
57
|
+
},
|
|
58
|
+
// ~~~~ @END REMOVE ~~~~
|
|
59
|
+
isDev && { name: "enhanceErrorLink", link: createUpdateDataLink() },
|
|
60
|
+
{
|
|
61
|
+
name: "httpLink",
|
|
62
|
+
link: createHttpLink(
|
|
63
|
+
getGraphqlUrl(),
|
|
64
|
+
httpLinkConfig,
|
|
65
|
+
serverAuthState?.cookieHeader
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
].filter((link) => !!link);
|
|
69
|
+
function makeClient() {
|
|
70
|
+
return new ApolloClient({
|
|
71
|
+
link: createFinalLink({
|
|
72
|
+
userConfiguredLink: userPassedLink,
|
|
73
|
+
defaultLinks: redwoodApolloLinks
|
|
74
|
+
}),
|
|
75
|
+
...otherConfig
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return /* @__PURE__ */ React.createElement(WrappedApolloProvider, { makeClient }, children);
|
|
79
|
+
};
|
|
80
|
+
const RedwoodApolloProvider = ({
|
|
81
|
+
graphQLClientConfig,
|
|
82
|
+
useAuth = useNoAuth,
|
|
83
|
+
logLevel = "debug",
|
|
84
|
+
children
|
|
85
|
+
}) => {
|
|
86
|
+
const { cacheConfig, ...config } = graphQLClientConfig ?? {};
|
|
87
|
+
const cache = new InMemoryCache(cacheConfig).restore(
|
|
88
|
+
globalThis?.__REDWOOD__APOLLO_STATE ?? {}
|
|
89
|
+
);
|
|
90
|
+
return /* @__PURE__ */ React.createElement(FetchConfigProvider, { useAuth }, /* @__PURE__ */ React.createElement(
|
|
91
|
+
ApolloProviderWithFetchConfig,
|
|
92
|
+
{
|
|
93
|
+
config: { cache, ...config },
|
|
94
|
+
useAuth,
|
|
95
|
+
logLevel
|
|
96
|
+
},
|
|
97
|
+
/* @__PURE__ */ React.createElement(
|
|
98
|
+
GraphQLHooksProvider,
|
|
99
|
+
{
|
|
100
|
+
useQuery,
|
|
101
|
+
useMutation,
|
|
102
|
+
useSubscription,
|
|
103
|
+
useSuspenseQuery,
|
|
104
|
+
useBackgroundQuery,
|
|
105
|
+
useReadQuery
|
|
106
|
+
},
|
|
107
|
+
children
|
|
108
|
+
)
|
|
109
|
+
));
|
|
110
|
+
};
|
|
111
|
+
export {
|
|
112
|
+
RedwoodApolloProvider
|
|
113
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { QueryHookOptions, QueryResult, MutationHookOptions, MutationTuple, OperationVariables, SubscriptionHookOptions, SubscriptionResult, UseSuspenseQueryResult, SuspenseQueryHookOptions } from '@apollo/client';
|
|
2
|
+
declare global {
|
|
3
|
+
interface QueryOperationResult<TData = any, TVariables extends OperationVariables = OperationVariables> extends QueryResult<TData, TVariables> {
|
|
4
|
+
}
|
|
5
|
+
interface MutationOperationResult<TData, TVariables> extends MutationTuple<TData, TVariables> {
|
|
6
|
+
}
|
|
7
|
+
interface SubscriptionOperationResult<TData = any, TVariables extends OperationVariables = OperationVariables> extends SubscriptionResult<TData, TVariables> {
|
|
8
|
+
}
|
|
9
|
+
interface GraphQLQueryHookOptions<TData, TVariables extends OperationVariables> extends QueryHookOptions<TData, TVariables> {
|
|
10
|
+
}
|
|
11
|
+
interface GraphQLMutationHookOptions<TData, TVariables> extends MutationHookOptions<TData, TVariables> {
|
|
12
|
+
}
|
|
13
|
+
interface GraphQLSubscriptionHookOptions<TData, TVariables extends OperationVariables> extends SubscriptionHookOptions<TData, TVariables> {
|
|
14
|
+
}
|
|
15
|
+
interface SuspenseQueryOperationResult<TData = any, TVariables extends OperationVariables = OperationVariables> extends UseSuspenseQueryResult<TData, TVariables> {
|
|
16
|
+
}
|
|
17
|
+
interface GraphQLSuspenseQueryHookOptions<TData, TVariables extends OperationVariables> extends SuspenseQueryHookOptions<TData, TVariables> {
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=typeOverride.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeOverride.d.ts","sourceRoot":"","sources":["../../src/apollo/typeOverride.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,oBAAoB,CAC5B,KAAK,GAAG,GAAG,EACX,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,CAC1D,SAAQ,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC;KAAG;IAG3C,UAAU,uBAAuB,CAAC,KAAK,EAAE,UAAU,CACjD,SAAQ,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC;KAAG;IAG7C,UAAU,2BAA2B,CACnC,KAAK,GAAG,GAAG,EACX,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,CAC1D,SAAQ,kBAAkB,CAAC,KAAK,EAAE,UAAU,CAAC;KAAG;IAGlD,UAAU,uBAAuB,CAC/B,KAAK,EACL,UAAU,SAAS,kBAAkB,CACrC,SAAQ,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC;KAAG;IAGhD,UAAU,0BAA0B,CAAC,KAAK,EAAE,UAAU,CACpD,SAAQ,mBAAmB,CAAC,KAAK,EAAE,UAAU,CAAC;KAAG;IAGnD,UAAU,8BAA8B,CACtC,KAAK,EACL,UAAU,SAAS,kBAAkB,CACrC,SAAQ,uBAAuB,CAAC,KAAK,EAAE,UAAU,CAAC;KAAG;IAGvD,UAAU,4BAA4B,CACpC,KAAK,GAAG,GAAG,EACX,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,CAC1D,SAAQ,sBAAsB,CAAC,KAAK,EAAE,UAAU,CAAC;KAAG;IAGtD,UAAU,+BAA+B,CACvC,KAAK,EACL,UAAU,SAAS,kBAAkB,CACrC,SAAQ,wBAAwB,CAAC,KAAK,EAAE,UAAU,CAAC;KAAG;CACzD;AAED,OAAO,EAAE,CAAA"}
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
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';
|
|
4
|
+
type useCacheType = {
|
|
5
|
+
cache: ApolloCache<object>;
|
|
6
|
+
evict: (object: StoreObject | Reference) => boolean;
|
|
7
|
+
extract: (optimistic?: boolean) => NormalizedCacheObject;
|
|
8
|
+
identify: (object: StoreObject | Reference) => {
|
|
9
|
+
id: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
modify: (object: StoreObject | Reference, fields: Record<string, any>) => boolean;
|
|
12
|
+
resetStore: () => Promise<ApolloQueryResult<any>[] | null>;
|
|
13
|
+
clearStore: () => Promise<ApolloQueryResult<any>[] | null>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Apollo Client stores the results of your GraphQL queries in a local, normalized, in-memory cache.
|
|
17
|
+
*
|
|
18
|
+
* useCache is a custom hook that returns the cache object and some useful methods to interact with the cache.
|
|
19
|
+
*/
|
|
20
|
+
export declare const useCache: () => useCacheType;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=useCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCache.d.ts","sourceRoot":"","sources":["../../src/apollo/useCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AACnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAG5D,KAAK,YAAY,GAAG;IAClB,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC1B,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,iBAAiB,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;IAC1D,UAAU,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;CAC3D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAO,YAmE3B,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useApolloClient } from "@apollo/client/react/hooks/hooks.cjs";
|
|
2
|
+
const useCache = () => {
|
|
3
|
+
const client = useApolloClient();
|
|
4
|
+
const cache = client.cache;
|
|
5
|
+
const extract = (optimistic = false) => cache.extract(optimistic);
|
|
6
|
+
const identify = (object) => {
|
|
7
|
+
return { id: cache.identify(object) };
|
|
8
|
+
};
|
|
9
|
+
const modify = (object, fields) => {
|
|
10
|
+
return cache.modify({ ...identify(object), fields });
|
|
11
|
+
};
|
|
12
|
+
const evict = (object) => {
|
|
13
|
+
return cache.evict(identify(object));
|
|
14
|
+
};
|
|
15
|
+
const resetStore = () => {
|
|
16
|
+
return client.resetStore();
|
|
17
|
+
};
|
|
18
|
+
const clearStore = () => {
|
|
19
|
+
return client.clearStore();
|
|
20
|
+
};
|
|
21
|
+
return { cache, evict, extract, identify, modify, resetStore, clearStore };
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
useCache
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-env.d.ts","sourceRoot":"","sources":["../../src/bins/cross-env.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msw.d.ts","sourceRoot":"","sources":["../../src/bins/msw.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* This file lets users run the Cedar CLI commands inside the /web directory
|
|
4
|
+
* in their projects.
|
|
5
|
+
* This works because of the "bin" field in the @cedarjs/web package.json file
|
|
6
|
+
* that points to this file.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=redwood.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redwood.d.ts","sourceRoot":"","sources":["../../src/bins/redwood.ts"],"names":[],"mappings":";AAEA;;;;;GAKG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rwfw.d.ts","sourceRoot":"","sources":["../../src/bins/rwfw.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storybook.d.ts","sourceRoot":"","sources":["../../src/bins/storybook.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsc.d.ts","sourceRoot":"","sources":["../../src/bins/tsc.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-upload-client.d.ts","sourceRoot":"","sources":["../../src/bundled/apollo-upload-client.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,2CAA2C,CAAA;AAExE,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { UseFragmentResult } from '@apollo/client';
|
|
2
|
+
import type { FragmentRegistryAPI } from '@apollo/client/cache/index.js';
|
|
3
|
+
import type { DocumentNode } from 'graphql';
|
|
4
|
+
export type FragmentIdentifier = string | number;
|
|
5
|
+
export type CacheKey = {
|
|
6
|
+
__typename: string;
|
|
7
|
+
id: FragmentIdentifier;
|
|
8
|
+
};
|
|
9
|
+
export type RegisterFragmentResult = {
|
|
10
|
+
fragment: DocumentNode;
|
|
11
|
+
typename: string;
|
|
12
|
+
getCacheKey: (id: FragmentIdentifier) => CacheKey;
|
|
13
|
+
useRegisteredFragment: <TData = any>(id: FragmentIdentifier) => UseFragmentResult<TData>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Creates a fragment registry for Apollo Client's InMemoryCache so that they
|
|
17
|
+
* can be referred to by name in any query or InMemoryCache operation
|
|
18
|
+
* (such as cache.readFragment, cache.readQuery and cache.watch)
|
|
19
|
+
* without needing to interpolate their declaration.
|
|
20
|
+
*
|
|
21
|
+
* @see https://www.apollographql.com/docs/react/data/fragments/#registering-named-fragments-using-createfragmentregistry
|
|
22
|
+
**/
|
|
23
|
+
export declare const fragmentRegistry: FragmentRegistryAPI;
|
|
24
|
+
/**
|
|
25
|
+
* Registers a list of fragments with the fragment registry.
|
|
26
|
+
*/
|
|
27
|
+
export declare const registerFragments: (fragments: DocumentNode[]) => RegisterFragmentResult[];
|
|
28
|
+
/**
|
|
29
|
+
* Registers a fragment with the fragment registry.
|
|
30
|
+
*
|
|
31
|
+
* It returns a set of utilities for working with the fragment, including:
|
|
32
|
+
* - the fragment itself
|
|
33
|
+
* - the typename of the fragment
|
|
34
|
+
* - a function to get the cache key for a given id
|
|
35
|
+
* - a hook to use the registered fragment in a component by id
|
|
36
|
+
* that returns cached data for the fragment
|
|
37
|
+
*
|
|
38
|
+
* Note: one does not need to use the hook, cacheKey to use the fragment in queries.
|
|
39
|
+
*
|
|
40
|
+
* @see https://www.apollographql.com/docs/react/data/fragments/#registering-named-fragments-using-createfragmentregistry
|
|
41
|
+
*/
|
|
42
|
+
export declare const registerFragment: (fragment: DocumentNode) => RegisterFragmentResult;
|
|
43
|
+
//# sourceMappingURL=fragmentRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragmentRegistry.d.ts","sourceRoot":"","sources":["../../../src/apollo/fragmentRegistry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAExE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,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,KAAK,CAAC,CAAA;CAC9B,CAAA;AAqCD;;;;;;;IAOI;AACJ,eAAO,MAAM,gBAAgB,EAAE,mBAA8C,CAAA;AAE7E;;GAEG;AACH,eAAO,MAAM,iBAAiB,cAAe,YAAY,EAAE,6BAE1D,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,aACjB,YAAY,KACrB,sBAqBF,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var fragmentRegistry_exports = {};
|
|
30
|
+
__export(fragmentRegistry_exports, {
|
|
31
|
+
fragmentRegistry: () => fragmentRegistry,
|
|
32
|
+
registerFragment: () => registerFragment,
|
|
33
|
+
registerFragments: () => registerFragments
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(fragmentRegistry_exports);
|
|
36
|
+
var apolloClient = __toESM(require("@apollo/client"), 1);
|
|
37
|
+
var import_cache = require("@apollo/client/cache/cache.cjs");
|
|
38
|
+
var import_utilities = require("@apollo/client/utilities/utilities.cjs");
|
|
39
|
+
const getTypenameFromFragment = (fragment) => {
|
|
40
|
+
const [definition] = (0, import_utilities.getFragmentDefinitions)(fragment);
|
|
41
|
+
return definition.typeCondition.name.value;
|
|
42
|
+
};
|
|
43
|
+
const useRegisteredFragmentHook = (fragment, id) => {
|
|
44
|
+
const from = { __typename: getTypenameFromFragment(fragment), id };
|
|
45
|
+
return apolloClient.useFragment({
|
|
46
|
+
fragment,
|
|
47
|
+
from
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const fragmentRegistry = (0, import_cache.createFragmentRegistry)();
|
|
51
|
+
const registerFragments = (fragments) => {
|
|
52
|
+
return fragments.map(registerFragment);
|
|
53
|
+
};
|
|
54
|
+
const registerFragment = (fragment) => {
|
|
55
|
+
fragmentRegistry.register(fragment);
|
|
56
|
+
const typename = getTypenameFromFragment(fragment);
|
|
57
|
+
const getCacheKey = (id) => {
|
|
58
|
+
return { __typename: typename, id };
|
|
59
|
+
};
|
|
60
|
+
const useRegisteredFragment = (id) => {
|
|
61
|
+
return useRegisteredFragmentHook(fragment, id);
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
fragment,
|
|
65
|
+
typename,
|
|
66
|
+
getCacheKey,
|
|
67
|
+
useRegisteredFragment
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
fragmentRegistry,
|
|
73
|
+
registerFragment,
|
|
74
|
+
registerFragments
|
|
75
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ApolloClientOptions, setLogVerbosity, ApolloCache, InMemoryCacheConfig, HttpOptions, DocumentNode } from '@apollo/client';
|
|
3
|
+
import { ApolloLink } from '@apollo/client';
|
|
4
|
+
import type { HttpLink } from '@apollo/client/link/http/http.cjs';
|
|
5
|
+
import type { UseAuth } from '@cedarjs/auth';
|
|
6
|
+
import './typeOverride.js';
|
|
7
|
+
import { fragmentRegistry, registerFragment, registerFragments } from './fragmentRegistry.js';
|
|
8
|
+
import { useCache } from './useCache.js';
|
|
9
|
+
export type { CacheKey, FragmentIdentifier, RegisterFragmentResult, } from './fragmentRegistry.js';
|
|
10
|
+
export { useCache };
|
|
11
|
+
export { fragmentRegistry, registerFragment, registerFragments };
|
|
12
|
+
export type ApolloClientCacheConfig = InMemoryCacheConfig;
|
|
13
|
+
export type RedwoodApolloLinkName = 'withToken' | 'authMiddleware' | 'updateDataApolloLink' | 'httpLink';
|
|
14
|
+
export type RedwoodApolloLink<Name extends RedwoodApolloLinkName, Link extends ApolloLink = ApolloLink> = {
|
|
15
|
+
name: Name;
|
|
16
|
+
link: Link;
|
|
17
|
+
};
|
|
18
|
+
export type RedwoodApolloLinks = [
|
|
19
|
+
RedwoodApolloLink<'withToken'>,
|
|
20
|
+
RedwoodApolloLink<'authMiddleware'>,
|
|
21
|
+
RedwoodApolloLink<'updateDataApolloLink'>,
|
|
22
|
+
RedwoodApolloLink<'httpLink', ApolloLink | HttpLink>
|
|
23
|
+
];
|
|
24
|
+
export type RedwoodApolloLinkFactory = (links: RedwoodApolloLinks) => ApolloLink;
|
|
25
|
+
export type GraphQLClientConfigProp = Omit<ApolloClientOptions<unknown>, 'cache' | 'link'> & {
|
|
26
|
+
cache?: ApolloCache<unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Configuration for Apollo Client's `InMemoryCache`.
|
|
29
|
+
* See https://www.apollographql.com/docs/react/caching/cache-configuration/.
|
|
30
|
+
*/
|
|
31
|
+
cacheConfig?: ApolloClientCacheConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for the terminating `HttpLink`.
|
|
34
|
+
* See https://www.apollographql.com/docs/react/api/link/apollo-link-http/#httplink-constructor-options.
|
|
35
|
+
*
|
|
36
|
+
* For example, you can use this prop to set the credentials policy so that cookies can be sent to other domains:
|
|
37
|
+
*
|
|
38
|
+
* ```js
|
|
39
|
+
* <RedwoodApolloProvider graphQLClientConfig={{
|
|
40
|
+
* httpLinkConfig: { credentials: 'include' }
|
|
41
|
+
* }}>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
httpLinkConfig?: HttpOptions;
|
|
45
|
+
/**
|
|
46
|
+
* Extend or overwrite `RedwoodApolloProvider`'s Apollo Link.
|
|
47
|
+
*
|
|
48
|
+
* To overwrite Redwood's Apollo Link, just provide your own `ApolloLink`.
|
|
49
|
+
*
|
|
50
|
+
* To extend Redwood's Apollo Link, provide a function—it'll get passed an array of Redwood's Apollo Links
|
|
51
|
+
* which are objects with a name and link property:
|
|
52
|
+
*
|
|
53
|
+
* ```js
|
|
54
|
+
* const link = (redwoodApolloLinks) => {
|
|
55
|
+
* const consoleLink = new ApolloLink((operation, forward) => {
|
|
56
|
+
* console.log(operation.operationName)
|
|
57
|
+
* return forward(operation)
|
|
58
|
+
* })
|
|
59
|
+
*
|
|
60
|
+
* return ApolloLink.from([consoleLink, ...redwoodApolloLinks.map(({ link }) => link)])
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* If you do this, there's a few things you should keep in mind:
|
|
65
|
+
* - your function should return a single link (e.g., using `ApolloLink.from`; see https://www.apollographql.com/docs/react/api/link/introduction/#additive-composition)
|
|
66
|
+
* - the `HttpLink` should come last (https://www.apollographql.com/docs/react/api/link/introduction/#the-terminating-link)
|
|
67
|
+
*/
|
|
68
|
+
link?: ApolloLink | RedwoodApolloLinkFactory;
|
|
69
|
+
};
|
|
70
|
+
export declare const RedwoodApolloProvider: React.FunctionComponent<{
|
|
71
|
+
graphQLClientConfig?: GraphQLClientConfigProp;
|
|
72
|
+
fragments?: DocumentNode[];
|
|
73
|
+
useAuth?: UseAuth;
|
|
74
|
+
logLevel?: ReturnType<typeof setLogVerbosity>;
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
}>;
|
|
77
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/apollo/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,YAAY,EACb,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAKL,UAAU,EACX,MAAM,gBAAgB,CAAA;AAGvB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAA;AAajE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAG5C,OAAO,mBAAmB,CAAA;AAQ1B,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAKxC,YAAY,EACV,QAAQ,EACR,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,QAAQ,EAAE,CAAA;AAEnB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAA;AAEhE,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAEzD,MAAM,MAAM,qBAAqB,GAC7B,WAAW,GACX,gBAAgB,GAChB,sBAAsB,GACtB,UAAU,CAAA;AAEd,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;IAC/B,iBAAiB,CAAC,WAAW,CAAC;IAC9B,iBAAiB,CAAC,gBAAgB,CAAC;IACnC,iBAAiB,CAAC,sBAAsB,CAAC;IACzC,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,CAAC;CACrD,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,UAAU,CAAA;AAEhF,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,mBAAmB,CAAC,OAAO,CAAC,EAC5B,OAAO,GAAG,MAAM,CACjB,GAAG;IACF,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,uBAAuB,CAAA;IACrC;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,WAAW,CAAA;IAC5B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,CAAC,EAAE,UAAU,GAAG,wBAAwB,CAAA;CAC7C,CAAA;AAqND,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAC1D,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,CA2CA,CAAA"}
|