@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Cedar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Web
|
|
2
|
+
|
|
3
|
+
<!-- toc -->
|
|
4
|
+
|
|
5
|
+
- [Purpose and Vision](#Purpose-and-Vision)
|
|
6
|
+
- [Package Lead](#Package-Lead)
|
|
7
|
+
- [Roadmap](#Roadmap)
|
|
8
|
+
- [Contributing](#Contributing)
|
|
9
|
+
- [FAQ](#FAQ)
|
|
10
|
+
|
|
11
|
+
## Purpose and Vision
|
|
12
|
+
|
|
13
|
+
Summarize the project's values, purpose, and aspirational vision.
|
|
14
|
+
|
|
15
|
+
## Package Lead
|
|
16
|
+
|
|
17
|
+
Identify the decision maker and/or go-to for questions.
|
|
18
|
+
|
|
19
|
+
## Roadmap
|
|
20
|
+
|
|
21
|
+
Similar to Purpose and Vision, but more concrete, comprising near-term priorities and long-term goals.
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
Explains how to contribute by addressing the following three points:
|
|
26
|
+
|
|
27
|
+
1. Core technologies a contributor should be a familiar with.
|
|
28
|
+
2. How this package fits into the Redwood Framework, if it depends on other Redwood packages, etc.
|
|
29
|
+
3. The structure of the package and/or an explanation of its contents.
|
|
30
|
+
|
|
31
|
+
## FAQ
|
|
32
|
+
|
|
33
|
+
Answers to frequently asked questions.
|
package/apollo/index.js
ADDED
|
@@ -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,39 @@
|
|
|
1
|
+
import * as apolloClient from "@apollo/client";
|
|
2
|
+
import { createFragmentRegistry } from "@apollo/client/cache/cache.cjs";
|
|
3
|
+
import { getFragmentDefinitions } from "@apollo/client/utilities/utilities.cjs";
|
|
4
|
+
const getTypenameFromFragment = (fragment) => {
|
|
5
|
+
const [definition] = getFragmentDefinitions(fragment);
|
|
6
|
+
return definition.typeCondition.name.value;
|
|
7
|
+
};
|
|
8
|
+
const useRegisteredFragmentHook = (fragment, id) => {
|
|
9
|
+
const from = { __typename: getTypenameFromFragment(fragment), id };
|
|
10
|
+
return apolloClient.useFragment({
|
|
11
|
+
fragment,
|
|
12
|
+
from
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const fragmentRegistry = createFragmentRegistry();
|
|
16
|
+
const registerFragments = (fragments) => {
|
|
17
|
+
return fragments.map(registerFragment);
|
|
18
|
+
};
|
|
19
|
+
const registerFragment = (fragment) => {
|
|
20
|
+
fragmentRegistry.register(fragment);
|
|
21
|
+
const typename = getTypenameFromFragment(fragment);
|
|
22
|
+
const getCacheKey = (id) => {
|
|
23
|
+
return { __typename: typename, id };
|
|
24
|
+
};
|
|
25
|
+
const useRegisteredFragment = (id) => {
|
|
26
|
+
return useRegisteredFragmentHook(fragment, id);
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
fragment,
|
|
30
|
+
typename,
|
|
31
|
+
getCacheKey,
|
|
32
|
+
useRegisteredFragment
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
fragmentRegistry,
|
|
37
|
+
registerFragment,
|
|
38
|
+
registerFragments
|
|
39
|
+
};
|
|
@@ -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"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
ApolloProvider,
|
|
4
|
+
ApolloClient,
|
|
5
|
+
InMemoryCache,
|
|
6
|
+
split,
|
|
7
|
+
ApolloLink
|
|
8
|
+
} from "@apollo/client";
|
|
9
|
+
import { setLogVerbosity as apolloSetLogVerbosity } from "@apollo/client/core/core.cjs";
|
|
10
|
+
import { setContext } from "@apollo/client/link/context/context.cjs";
|
|
11
|
+
import { createPersistedQueryLink } from "@apollo/client/link/persisted-queries/persisted-queries.cjs";
|
|
12
|
+
import {
|
|
13
|
+
useQuery,
|
|
14
|
+
useMutation,
|
|
15
|
+
useSubscription,
|
|
16
|
+
useBackgroundQuery,
|
|
17
|
+
useReadQuery,
|
|
18
|
+
useSuspenseQuery
|
|
19
|
+
} from "@apollo/client/react/hooks/hooks.cjs";
|
|
20
|
+
import { getMainDefinition } from "@apollo/client/utilities/utilities.cjs";
|
|
21
|
+
import { print } from "graphql/language/printer.js";
|
|
22
|
+
import { useNoAuth } from "@cedarjs/auth";
|
|
23
|
+
import "./typeOverride.js";
|
|
24
|
+
import { createUploadLink } from "../bundled/apollo-upload-client.js";
|
|
25
|
+
import {
|
|
26
|
+
FetchConfigProvider,
|
|
27
|
+
useFetchConfig
|
|
28
|
+
} from "../components/FetchConfigProvider.js";
|
|
29
|
+
import { GraphQLHooksProvider } from "../components/GraphQLHooksProvider.js";
|
|
30
|
+
import {
|
|
31
|
+
fragmentRegistry,
|
|
32
|
+
registerFragment,
|
|
33
|
+
registerFragments
|
|
34
|
+
} from "./fragmentRegistry.js";
|
|
35
|
+
import * as SSELinkExports from "./sseLink.js";
|
|
36
|
+
import { useCache } from "./useCache.js";
|
|
37
|
+
const { SSELink, isSubscription, isLiveQuery } = SSELinkExports;
|
|
38
|
+
const ApolloProviderWithFetchConfig = ({ config, children, useAuth = useNoAuth, logLevel }) => {
|
|
39
|
+
apolloSetLogVerbosity(logLevel);
|
|
40
|
+
const { getToken, type: authProviderType } = useAuth();
|
|
41
|
+
const data = {
|
|
42
|
+
mostRecentRequest: void 0,
|
|
43
|
+
mostRecentResponse: void 0
|
|
44
|
+
};
|
|
45
|
+
const updateDataApolloLink = new ApolloLink((operation, forward) => {
|
|
46
|
+
const { operationName, query, variables } = operation;
|
|
47
|
+
data.mostRecentRequest = {};
|
|
48
|
+
data.mostRecentRequest.operationName = operationName;
|
|
49
|
+
data.mostRecentRequest.operationKind = query?.kind.toString();
|
|
50
|
+
data.mostRecentRequest.variables = variables;
|
|
51
|
+
data.mostRecentRequest.query = query && print(operation.query);
|
|
52
|
+
return forward(operation).map((result) => {
|
|
53
|
+
data.mostRecentResponse = result;
|
|
54
|
+
return result;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
const withToken = setContext(async () => {
|
|
58
|
+
const token = await getToken();
|
|
59
|
+
return { token };
|
|
60
|
+
});
|
|
61
|
+
const { headers, uri } = useFetchConfig();
|
|
62
|
+
const authMiddleware = new ApolloLink((operation, forward) => {
|
|
63
|
+
const { token } = operation.getContext();
|
|
64
|
+
const authHeaders = token ? {
|
|
65
|
+
"auth-provider": authProviderType,
|
|
66
|
+
authorization: `Bearer ${token}`
|
|
67
|
+
} : {};
|
|
68
|
+
operation.setContext(() => ({
|
|
69
|
+
headers: {
|
|
70
|
+
...operation.getContext().headers,
|
|
71
|
+
...headers,
|
|
72
|
+
// Duped auth headers, because we may remove the `FetchConfigProvider` at a later date.
|
|
73
|
+
...authHeaders
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
return forward(operation);
|
|
77
|
+
});
|
|
78
|
+
const { httpLinkConfig, link: redwoodApolloLink, ...rest } = config ?? {};
|
|
79
|
+
const uploadLink = createUploadLink({
|
|
80
|
+
uri,
|
|
81
|
+
...httpLinkConfig
|
|
82
|
+
// The upload link types don't match the ApolloLink types, even though it comes from Apollo
|
|
83
|
+
// because they use ESM imports and we're using the default ones.
|
|
84
|
+
});
|
|
85
|
+
const uploadOrSSELink = typeof SSELink !== "undefined" ? split(
|
|
86
|
+
({ query }) => {
|
|
87
|
+
const definition = getMainDefinition(query);
|
|
88
|
+
return isSubscription(definition) || isLiveQuery(definition);
|
|
89
|
+
},
|
|
90
|
+
new SSELink({
|
|
91
|
+
url: uri,
|
|
92
|
+
auth: { authProviderType, tokenFn: getToken },
|
|
93
|
+
httpLinkConfig,
|
|
94
|
+
headers
|
|
95
|
+
}),
|
|
96
|
+
uploadLink
|
|
97
|
+
) : uploadLink;
|
|
98
|
+
const terminatingLink = split(
|
|
99
|
+
({ query }) => {
|
|
100
|
+
const documentQuery = query;
|
|
101
|
+
return documentQuery?.["__meta__"]?.["hash"] !== void 0;
|
|
102
|
+
},
|
|
103
|
+
createPersistedQueryLink({
|
|
104
|
+
generateHash: (document) => document["__meta__"]["hash"]
|
|
105
|
+
}).concat(uploadOrSSELink),
|
|
106
|
+
uploadOrSSELink
|
|
107
|
+
);
|
|
108
|
+
const redwoodApolloLinks = [
|
|
109
|
+
{ name: "withToken", link: withToken },
|
|
110
|
+
{ name: "authMiddleware", link: authMiddleware },
|
|
111
|
+
{ name: "updateDataApolloLink", link: updateDataApolloLink },
|
|
112
|
+
{ name: "httpLink", link: terminatingLink }
|
|
113
|
+
];
|
|
114
|
+
let link = redwoodApolloLink;
|
|
115
|
+
link ??= ApolloLink.from(redwoodApolloLinks.map((l) => l.link));
|
|
116
|
+
if (typeof link === "function") {
|
|
117
|
+
link = link(redwoodApolloLinks);
|
|
118
|
+
}
|
|
119
|
+
const client = new ApolloClient({
|
|
120
|
+
// Default options for every Cell. Better to specify them here than in `beforeQuery` where it's too easy to overwrite them.
|
|
121
|
+
// See https://www.apollographql.com/docs/react/api/core/ApolloClient/#example-defaultoptions-object.
|
|
122
|
+
defaultOptions: {
|
|
123
|
+
watchQuery: {
|
|
124
|
+
// The `fetchPolicy` we expect:
|
|
125
|
+
//
|
|
126
|
+
// > Apollo Client executes the full query against both the cache and your GraphQL server.
|
|
127
|
+
// > The query automatically updates if the result of the server-side query modifies cached fields.
|
|
128
|
+
//
|
|
129
|
+
// See https://www.apollographql.com/docs/react/data/queries/#cache-and-network.
|
|
130
|
+
fetchPolicy: "cache-and-network",
|
|
131
|
+
// So that Cells rerender when refetching.
|
|
132
|
+
// See https://www.apollographql.com/docs/react/data/queries/#inspecting-loading-states.
|
|
133
|
+
notifyOnNetworkStatusChange: true
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
link,
|
|
137
|
+
...rest
|
|
138
|
+
});
|
|
139
|
+
const extendErrorAndRethrow = (error, _errorInfo) => {
|
|
140
|
+
error["mostRecentRequest"] = data.mostRecentRequest;
|
|
141
|
+
error["mostRecentResponse"] = data.mostRecentResponse;
|
|
142
|
+
throw error;
|
|
143
|
+
};
|
|
144
|
+
return /* @__PURE__ */ React.createElement(ApolloProvider, { client }, /* @__PURE__ */ React.createElement(ErrorBoundary, { onError: extendErrorAndRethrow }, children));
|
|
145
|
+
};
|
|
146
|
+
class ErrorBoundary extends React.Component {
|
|
147
|
+
componentDidCatch(...args) {
|
|
148
|
+
this.setState({});
|
|
149
|
+
this.props.onError(...args);
|
|
150
|
+
}
|
|
151
|
+
render() {
|
|
152
|
+
return this.props.children;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const RedwoodApolloProvider = ({
|
|
156
|
+
graphQLClientConfig,
|
|
157
|
+
fragments,
|
|
158
|
+
useAuth = useNoAuth,
|
|
159
|
+
logLevel = "debug",
|
|
160
|
+
children
|
|
161
|
+
}) => {
|
|
162
|
+
const { cacheConfig, ...config } = graphQLClientConfig ?? {};
|
|
163
|
+
if (fragments) {
|
|
164
|
+
fragmentRegistry.register(...fragments);
|
|
165
|
+
}
|
|
166
|
+
const cache = new InMemoryCache({
|
|
167
|
+
fragments: fragmentRegistry,
|
|
168
|
+
possibleTypes: cacheConfig?.possibleTypes,
|
|
169
|
+
...cacheConfig
|
|
170
|
+
}).restore(globalThis?.__REDWOOD__APOLLO_STATE ?? {});
|
|
171
|
+
return /* @__PURE__ */ React.createElement(FetchConfigProvider, { useAuth }, /* @__PURE__ */ React.createElement(
|
|
172
|
+
ApolloProviderWithFetchConfig,
|
|
173
|
+
{
|
|
174
|
+
config: { cache, ...config },
|
|
175
|
+
useAuth,
|
|
176
|
+
logLevel
|
|
177
|
+
},
|
|
178
|
+
/* @__PURE__ */ React.createElement(
|
|
179
|
+
GraphQLHooksProvider,
|
|
180
|
+
{
|
|
181
|
+
useQuery,
|
|
182
|
+
useMutation,
|
|
183
|
+
useSubscription,
|
|
184
|
+
useBackgroundQuery,
|
|
185
|
+
useReadQuery,
|
|
186
|
+
useSuspenseQuery
|
|
187
|
+
},
|
|
188
|
+
children
|
|
189
|
+
)
|
|
190
|
+
));
|
|
191
|
+
};
|
|
192
|
+
export {
|
|
193
|
+
RedwoodApolloProvider,
|
|
194
|
+
fragmentRegistry,
|
|
195
|
+
registerFragment,
|
|
196
|
+
registerFragments,
|
|
197
|
+
useCache
|
|
198
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HttpOptions } from '@apollo/client';
|
|
2
|
+
import { ApolloLink } from '@apollo/client/link/core/index.js';
|
|
3
|
+
import { HttpLink } from '@apollo/client/link/http/index.js';
|
|
4
|
+
export declare function createHttpLink(uri: string, httpLinkConfig: HttpOptions | undefined, cookieHeader?: string | null): HttpLink;
|
|
5
|
+
export declare function createUpdateDataLink(): ApolloLink;
|
|
6
|
+
export declare function createAuthApolloLink(authProviderType: string, headersFromFetchProvider: {
|
|
7
|
+
'auth-provider'?: string | undefined;
|
|
8
|
+
authorization?: string | undefined;
|
|
9
|
+
} | undefined): ApolloLink;
|
|
10
|
+
export declare function createTokenLink(getToken: () => Promise<string | null>): ApolloLink;
|
|
11
|
+
export declare function createFinalLink({ userConfiguredLink, defaultLinks, }: {
|
|
12
|
+
userConfiguredLink?: ApolloLink | RedwoodApolloLinkFactory;
|
|
13
|
+
defaultLinks: RedwoodApolloLinks;
|
|
14
|
+
}): ApolloLink;
|
|
15
|
+
export type RedwoodApolloLink<Name extends RedwoodApolloLinkName, Link extends ApolloLink = ApolloLink> = {
|
|
16
|
+
name: Name;
|
|
17
|
+
link: Link;
|
|
18
|
+
};
|
|
19
|
+
export type RedwoodApolloLinks = (RedwoodApolloLink<'withToken'> | RedwoodApolloLink<'authMiddleware'> | RedwoodApolloLink<'enhanceErrorLink'> | RedwoodApolloLink<'httpLink', HttpLink>)[];
|
|
20
|
+
type DummyLink<T extends string> = {
|
|
21
|
+
name: T;
|
|
22
|
+
};
|
|
23
|
+
type InferredLinkName<T> = T extends DummyLink<infer Name>[] ? Name : never;
|
|
24
|
+
export type RedwoodApolloLinkName = InferredLinkName<RedwoodApolloLinks>;
|
|
25
|
+
export type RedwoodApolloLinkFactory = (links: RedwoodApolloLinks) => ApolloLink;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/apollo/links.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,gBAAgB,CAAA;AAG5D,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAA;AAG5D,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,WAAW,GAAG,SAAS,EACvC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,YAc7B;AAeD,wBAAgB,oBAAoB,eAmBnC;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,cAMrE;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"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Observable } from "@apollo/client/core/index.js";
|
|
2
|
+
import { setContext } from "@apollo/client/link/context/index.js";
|
|
3
|
+
import { ApolloLink } from "@apollo/client/link/core/index.js";
|
|
4
|
+
import { HttpLink } from "@apollo/client/link/http/index.js";
|
|
5
|
+
import { print } from "graphql/language/printer.js";
|
|
6
|
+
function createHttpLink(uri, httpLinkConfig, cookieHeader) {
|
|
7
|
+
const headers = {};
|
|
8
|
+
if (cookieHeader) {
|
|
9
|
+
headers.cookie = cookieHeader;
|
|
10
|
+
}
|
|
11
|
+
return new HttpLink({
|
|
12
|
+
uri,
|
|
13
|
+
credentials: "include",
|
|
14
|
+
...httpLinkConfig,
|
|
15
|
+
headers
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function enhanceError(operation, error) {
|
|
19
|
+
const { operationName, query, variables } = operation;
|
|
20
|
+
error.__RedwoodEnhancedError = {
|
|
21
|
+
operationName,
|
|
22
|
+
operationKind: query?.kind.toString(),
|
|
23
|
+
variables,
|
|
24
|
+
query: query && print(query)
|
|
25
|
+
};
|
|
26
|
+
return error;
|
|
27
|
+
}
|
|
28
|
+
function createUpdateDataLink() {
|
|
29
|
+
return new ApolloLink((operation, forward) => {
|
|
30
|
+
return new Observable((observer) => {
|
|
31
|
+
forward(operation).subscribe({
|
|
32
|
+
next(result) {
|
|
33
|
+
if (result.errors) {
|
|
34
|
+
result.errors.forEach((error) => {
|
|
35
|
+
enhanceError(operation, error);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
observer.next(result);
|
|
39
|
+
},
|
|
40
|
+
error(error) {
|
|
41
|
+
observer.error(enhanceError(operation, error));
|
|
42
|
+
},
|
|
43
|
+
complete: observer.complete.bind(observer)
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function createAuthApolloLink(authProviderType, headersFromFetchProvider) {
|
|
49
|
+
return new ApolloLink((operation, forward) => {
|
|
50
|
+
const { token } = operation.getContext();
|
|
51
|
+
const authHeaders = token ? {
|
|
52
|
+
"auth-provider": authProviderType,
|
|
53
|
+
authorization: `Bearer ${token}`
|
|
54
|
+
} : {};
|
|
55
|
+
if (!token) {
|
|
56
|
+
delete headersFromFetchProvider?.["auth-provider"];
|
|
57
|
+
}
|
|
58
|
+
operation.setContext(() => ({
|
|
59
|
+
headers: {
|
|
60
|
+
...operation.getContext().headers,
|
|
61
|
+
...headersFromFetchProvider,
|
|
62
|
+
// Duped auth headers, because we may remove the `FetchConfigProvider` at a later date.
|
|
63
|
+
...authHeaders
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
return forward(operation);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function createTokenLink(getToken) {
|
|
70
|
+
return setContext(async () => {
|
|
71
|
+
const token = await getToken();
|
|
72
|
+
return { token };
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function createFinalLink({
|
|
76
|
+
userConfiguredLink,
|
|
77
|
+
defaultLinks
|
|
78
|
+
}) {
|
|
79
|
+
if (userConfiguredLink) {
|
|
80
|
+
if (typeof userConfiguredLink === "function") {
|
|
81
|
+
return userConfiguredLink(defaultLinks);
|
|
82
|
+
} else {
|
|
83
|
+
return userConfiguredLink;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return ApolloLink.from(defaultLinks.map((l) => l.link));
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
createAuthApolloLink,
|
|
90
|
+
createFinalLink,
|
|
91
|
+
createHttpLink,
|
|
92
|
+
createTokenLink,
|
|
93
|
+
createUpdateDataLink
|
|
94
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HttpOptions } from '@apollo/client';
|
|
2
|
+
import type { Operation, FetchResult } from '@apollo/client/core';
|
|
3
|
+
import { ApolloLink } from '@apollo/client/link/core/core.cjs';
|
|
4
|
+
import { Observable } from '@apollo/client/utilities/utilities.cjs';
|
|
5
|
+
import type { DefinitionNode } from 'graphql';
|
|
6
|
+
import type { ClientOptions } from 'graphql-sse';
|
|
7
|
+
interface SSELinkOptions extends Partial<ClientOptions> {
|
|
8
|
+
url: string;
|
|
9
|
+
auth: {
|
|
10
|
+
authProviderType: string;
|
|
11
|
+
tokenFn: () => Promise<null | string>;
|
|
12
|
+
};
|
|
13
|
+
httpLinkConfig?: HttpOptions;
|
|
14
|
+
headers?: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
declare const isSubscription: (definition: DefinitionNode) => boolean;
|
|
17
|
+
declare const isLiveQuery: (definition: DefinitionNode) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* GraphQL over Server-Sent Events (SSE) spec link for Apollo Client
|
|
20
|
+
*/
|
|
21
|
+
declare class SSELink extends ApolloLink {
|
|
22
|
+
private client;
|
|
23
|
+
constructor(options: SSELinkOptions);
|
|
24
|
+
request(operation: Operation & {
|
|
25
|
+
query?: any;
|
|
26
|
+
}): Observable<FetchResult>;
|
|
27
|
+
}
|
|
28
|
+
export { SSELink, isSubscription, isLiveQuery };
|
|
29
|
+
//# sourceMappingURL=sseLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sseLink.d.ts","sourceRoot":"","sources":["../../src/apollo/sseLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,aAAa,EAA+B,MAAM,aAAa,CAAA;AAE7E,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,WAAW,CAAA;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC;AAsDD,QAAA,MAAM,cAAc,eAAgB,cAAc,YAKjD,CAAA;AAID,QAAA,MAAM,WAAW,eAAgB,cAAc,YAS9C,CAAA;AAED;;GAEG;AACH,cAAM,OAAQ,SAAQ,UAAU;IAC9B,OAAO,CAAC,MAAM,CAAQ;gBAEV,OAAO,EAAE,cAAc;IA2B5B,OAAO,CACZ,SAAS,EAAE,SAAS,GAAG;QAAE,KAAK,CAAC,EAAE,GAAG,CAAA;KAAE,GACrC,UAAU,CAAC,WAAW,CAAC;CAuB3B;AAED,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,CAAA"}
|