@cedarjs/web 7.0.0-canary.3091 → 7.0.0-canary.3093
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 +7 -1
- package/dist/apollo/ApolloProviderWithFetchConfig.d.ts.map +1 -1
- package/dist/apollo/ApolloProviderWithFetchConfig.js +32 -20
- package/dist/apollo/CedarApolloProvider.d.ts.map +1 -1
- package/dist/apollo/CedarApolloProvider.js +9 -5
- package/dist/apollo/index.d.ts +4 -0
- package/dist/apollo/index.d.ts.map +1 -1
- package/dist/apollo/index.js +3 -1
- package/dist/apollo/suspense.d.ts +2 -1
- package/dist/apollo/suspense.d.ts.map +1 -1
- package/dist/apollo/suspense.js +33 -7
- 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/package.json +6 -6
|
@@ -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"}
|
|
@@ -6,10 +6,16 @@ interface Props {
|
|
|
6
6
|
config: Omit<GraphQLClientConfigProp, 'cacheConfig' | 'cache'> & {
|
|
7
7
|
cache: ApolloCache;
|
|
8
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;
|
|
9
15
|
useAuth?: UseAuth;
|
|
10
16
|
logLevel: ReturnType<typeof setLogVerbosity>;
|
|
11
17
|
children: React.ReactNode;
|
|
12
18
|
}
|
|
13
|
-
export declare function ApolloProviderWithFetchConfig({ config, children, useAuth, logLevel, }: Props): React.JSX.Element;
|
|
19
|
+
export declare function ApolloProviderWithFetchConfig({ config, createCache, children, useAuth, logLevel, }: Props): React.JSX.Element;
|
|
14
20
|
export {};
|
|
15
21
|
//# sourceMappingURL=ApolloProviderWithFetchConfig.d.ts.map
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -14,11 +14,13 @@ import { map } from "rxjs";
|
|
|
14
14
|
import { useNoAuth } from "@cedarjs/auth";
|
|
15
15
|
import { UploadHttpLink } from "../bundled/apollo-upload-client.js";
|
|
16
16
|
import { useFetchConfig } from "../components/FetchConfigProvider.js";
|
|
17
|
+
import { ApolloClientFactoryContext } from "./ApolloClientFactoryContext.js";
|
|
17
18
|
import { ErrorBoundary } from "./ErrorBoundary.js";
|
|
18
19
|
import * as SSELinkExports from "./sseLink.js";
|
|
19
20
|
const { SSELink, isSubscription, isLiveQuery } = SSELinkExports;
|
|
20
21
|
function ApolloProviderWithFetchConfig({
|
|
21
22
|
config,
|
|
23
|
+
createCache,
|
|
22
24
|
children,
|
|
23
25
|
useAuth = useNoAuth,
|
|
24
26
|
logLevel
|
|
@@ -106,35 +108,45 @@ function ApolloProviderWithFetchConfig({
|
|
|
106
108
|
if (typeof link === "function") {
|
|
107
109
|
link = link(cedarApolloLinks);
|
|
108
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
|
+
};
|
|
109
127
|
const client = new ApolloClient({
|
|
110
|
-
|
|
111
|
-
// `beforeQuery` where it's too easy to overwrite them.
|
|
112
|
-
// See https://www.apollographql.com/docs/react/api/core/ApolloClient/#example-defaultoptions-object.
|
|
113
|
-
defaultOptions: {
|
|
114
|
-
watchQuery: {
|
|
115
|
-
// The `fetchPolicy` we expect:
|
|
116
|
-
//
|
|
117
|
-
// > Apollo Client executes the full query against both the cache and
|
|
118
|
-
// > your GraphQL server.
|
|
119
|
-
// > The query automatically updates if the result of the server-side
|
|
120
|
-
// > query modifies cached fields.
|
|
121
|
-
//
|
|
122
|
-
// See https://www.apollographql.com/docs/react/data/queries/#cache-and-network.
|
|
123
|
-
fetchPolicy: "cache-and-network",
|
|
124
|
-
// So that Cells rerender when refetching.
|
|
125
|
-
// See https://www.apollographql.com/docs/react/data/queries/#inspecting-loading-states.
|
|
126
|
-
notifyOnNetworkStatusChange: true
|
|
127
|
-
}
|
|
128
|
-
},
|
|
128
|
+
defaultOptions,
|
|
129
129
|
link,
|
|
130
130
|
...rest
|
|
131
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
|
+
};
|
|
132
144
|
const extendErrorAndRethrow = (error, _errorInfo) => {
|
|
133
145
|
error["mostRecentRequest"] = data.mostRecentRequest;
|
|
134
146
|
error["mostRecentResponse"] = data.mostRecentResponse;
|
|
135
147
|
throw error;
|
|
136
148
|
};
|
|
137
|
-
return /* @__PURE__ */ React.createElement(ApolloProvider, { client }, /* @__PURE__ */ React.createElement(ErrorBoundary, { onError: extendErrorAndRethrow }, children));
|
|
149
|
+
return /* @__PURE__ */ React.createElement(ApolloClientFactoryContext.Provider, { value: createApolloClient }, /* @__PURE__ */ React.createElement(ApolloProvider, { client }, /* @__PURE__ */ React.createElement(ErrorBoundary, { onError: extendErrorAndRethrow }, children)));
|
|
138
150
|
}
|
|
139
151
|
export {
|
|
140
152
|
ApolloProviderWithFetchConfig
|
|
@@ -1 +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,
|
|
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"}
|
|
@@ -15,15 +15,19 @@ function CedarApolloProvider({
|
|
|
15
15
|
if (fragments) {
|
|
16
16
|
fragmentRegistry.register(...fragments);
|
|
17
17
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 ?? {});
|
|
23
26
|
return /* @__PURE__ */ React.createElement(FetchConfigProvider, { useAuth }, /* @__PURE__ */ React.createElement(
|
|
24
27
|
ApolloProviderWithFetchConfig,
|
|
25
28
|
{
|
|
26
29
|
config: { cache, ...config },
|
|
30
|
+
createCache,
|
|
27
31
|
useAuth,
|
|
28
32
|
logLevel
|
|
29
33
|
},
|
package/dist/apollo/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { ApolloLink } from '@apollo/client';
|
|
2
|
+
import type { CreateApolloClientOptions } from './ApolloClientFactoryContext.js';
|
|
2
3
|
import { CedarApolloProvider } from './CedarApolloProvider.js';
|
|
3
4
|
import type { ApolloClientCacheConfig as CedarApolloClientCacheConfig, CedarApolloLink, CedarApolloLinkFactory, CedarApolloLinkName, CedarApolloLinks, GraphQLClientConfigProp as CedarGraphQLClientConfigProp } from './CedarApolloProvider.js';
|
|
4
5
|
import { fragmentRegistry, registerFragment, registerFragments } from './fragmentRegistry.js';
|
|
5
6
|
import { useCache } from './useCache.js';
|
|
7
|
+
import { useCreateApolloClient } from './useCreateApolloClient.js';
|
|
6
8
|
export type { CacheKey, FragmentIdentifier, RegisterFragmentResult, } from './fragmentRegistry.js';
|
|
9
|
+
export type { CreateApolloClientOptions };
|
|
7
10
|
export { useCache };
|
|
11
|
+
export { useCreateApolloClient };
|
|
8
12
|
export { fragmentRegistry, registerFragment, registerFragments };
|
|
9
13
|
/**
|
|
10
14
|
* @deprecated Import from `@cedarjs/web/apollo/CedarApolloProvider` instead.
|
|
@@ -1 +1 @@
|
|
|
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,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;
|
|
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"}
|
package/dist/apollo/index.js
CHANGED
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
registerFragments
|
|
6
6
|
} from "./fragmentRegistry.js";
|
|
7
7
|
import { useCache } from "./useCache.js";
|
|
8
|
+
import { useCreateApolloClient } from "./useCreateApolloClient.js";
|
|
8
9
|
const RedwoodApolloProvider = CedarApolloProvider;
|
|
9
10
|
export {
|
|
10
11
|
RedwoodApolloProvider,
|
|
11
12
|
fragmentRegistry,
|
|
12
13
|
registerFragment,
|
|
13
14
|
registerFragments,
|
|
14
|
-
useCache
|
|
15
|
+
useCache,
|
|
16
|
+
useCreateApolloClient
|
|
15
17
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { ApolloClient as ApolloClientBase,
|
|
2
|
+
import type { ApolloClient as ApolloClientBase, HttpLink, InMemoryCacheConfig, setLogVerbosity } from '@apollo/client';
|
|
3
|
+
import { ApolloLink } from '@apollo/client';
|
|
3
4
|
import { InMemoryCache } from '@apollo/client-react-streaming';
|
|
4
5
|
import type { UseAuth } from '@cedarjs/auth';
|
|
5
6
|
import type { RedwoodApolloLink, RedwoodApolloLinkFactory, RedwoodApolloLinkName, RedwoodApolloLinks } from './links.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../../src/apollo/suspense.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,
|
|
1
|
+
{"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../../src/apollo/suspense.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,QAAQ,EACR,mBAAmB,EACnB,eAAe,EAChB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,UAAU,EAEX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAEL,aAAa,EAEd,MAAM,gCAAgC,CAAA;AAGvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAa5C,OAAO,KAAK,EACV,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,YAAY,CAAA;AASnB,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAEzD,YAAY,EACV,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,GACnB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,gBAAgB,CAAC,OAAO,EACxB,OAAO,GAAG,MAAM,CACjB,GAAG;IACF,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,uBAAuB,CAAA;IACrC;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAA;IACjC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,CAAC,EAAE,UAAU,GAAG,wBAAwB,CAAA;CAC7C,CAAA;AAqHD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,iBAAiB,CAAC;IACxD,mBAAmB,CAAC,EAAE,uBAAuB,CAAA;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;IAC7C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAsCA,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB;0BAhDV,uBAAuB;cACnC,OAAO;eACN,UAAU,CAAC,OAAO,eAAe,CAAC;cACnC,KAAK,CAAC,SAAS;EA6C6B,CAAA"}
|
package/dist/apollo/suspense.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import React, { useContext } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ApolloLink,
|
|
5
|
+
setLogVerbosity as apolloSetLogVerbosity
|
|
6
|
+
} from "@apollo/client";
|
|
7
|
+
import { SetContextLink } from "@apollo/client/link/context";
|
|
4
8
|
import {
|
|
5
9
|
ApolloClient,
|
|
6
10
|
InMemoryCache,
|
|
@@ -14,6 +18,7 @@ import {
|
|
|
14
18
|
useFetchConfig
|
|
15
19
|
} from "../components/FetchConfigProvider.js";
|
|
16
20
|
import { ServerHtmlContext } from "../components/ServerInject.js";
|
|
21
|
+
import { ApolloClientFactoryContext } from "./ApolloClientFactoryContext.js";
|
|
17
22
|
import { fragmentRegistry } from "./fragmentRegistry.js";
|
|
18
23
|
import {
|
|
19
24
|
createAuthApolloLink,
|
|
@@ -29,7 +34,7 @@ const WrappedApolloProvider = WrapApolloProvider(
|
|
|
29
34
|
}
|
|
30
35
|
})
|
|
31
36
|
);
|
|
32
|
-
const ApolloProviderWithFetchConfig = ({ config, children, logLevel, useAuth = useNoAuth }) => {
|
|
37
|
+
const ApolloProviderWithFetchConfig = ({ config, createCache, children, logLevel, useAuth = useNoAuth }) => {
|
|
33
38
|
apolloSetLogVerbosity(logLevel);
|
|
34
39
|
const { uri, headers } = useFetchConfig();
|
|
35
40
|
const { getToken, type: authProviderType } = useAuth();
|
|
@@ -66,7 +71,24 @@ const ApolloProviderWithFetchConfig = ({ config, children, logLevel, useAuth = u
|
|
|
66
71
|
...otherConfig
|
|
67
72
|
});
|
|
68
73
|
}
|
|
69
|
-
|
|
74
|
+
const createApolloClient = (options) => {
|
|
75
|
+
const extraHeaders = options?.headers;
|
|
76
|
+
const withExtraHeaders = new SetContextLink((prevContext) => ({
|
|
77
|
+
headers: { ...prevContext.headers, ...extraHeaders }
|
|
78
|
+
}));
|
|
79
|
+
return new ApolloClient({
|
|
80
|
+
...otherConfig,
|
|
81
|
+
cache: createCache(),
|
|
82
|
+
link: ApolloLink.from([
|
|
83
|
+
withExtraHeaders,
|
|
84
|
+
createFinalLink({
|
|
85
|
+
userConfiguredLink: userPassedLink,
|
|
86
|
+
defaultLinks: redwoodApolloLinks
|
|
87
|
+
})
|
|
88
|
+
])
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
return /* @__PURE__ */ React.createElement(ApolloClientFactoryContext.Provider, { value: createApolloClient }, /* @__PURE__ */ React.createElement(WrappedApolloProvider, { makeClient }, children));
|
|
70
92
|
};
|
|
71
93
|
const CedarApolloProvider = ({
|
|
72
94
|
graphQLClientConfig,
|
|
@@ -75,14 +97,18 @@ const CedarApolloProvider = ({
|
|
|
75
97
|
children
|
|
76
98
|
}) => {
|
|
77
99
|
const { cacheConfig, ...config } = graphQLClientConfig ?? {};
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
100
|
+
const createCache = () => {
|
|
101
|
+
return new InMemoryCache({
|
|
102
|
+
fragments: fragmentRegistry,
|
|
103
|
+
...cacheConfig
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const cache = createCache().restore(globalThis?.__CEDAR__APOLLO_STATE ?? {});
|
|
82
107
|
return /* @__PURE__ */ React.createElement(FetchConfigProvider, { useAuth }, /* @__PURE__ */ React.createElement(
|
|
83
108
|
ApolloProviderWithFetchConfig,
|
|
84
109
|
{
|
|
85
110
|
config: { cache, ...config },
|
|
111
|
+
createCache,
|
|
86
112
|
useAuth,
|
|
87
113
|
logLevel
|
|
88
114
|
},
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CreateApolloClient } from './ApolloClientFactoryContext.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a factory that builds a new `ApolloClient` sharing
|
|
4
|
+
* `CedarApolloProvider`'s link chain, auth headers and `defaultOptions`, but
|
|
5
|
+
* with its own fresh `InMemoryCache` and, when given, extra headers merged
|
|
6
|
+
* into every operation.
|
|
7
|
+
*
|
|
8
|
+
* Must be called from a component rendered under `CedarApolloProvider`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useCreateApolloClient(): CreateApolloClient;
|
|
11
|
+
//# sourceMappingURL=useCreateApolloClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateApolloClient.d.ts","sourceRoot":"","sources":["../../src/apollo/useCreateApolloClient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AAGzE;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,IAAI,kBAAkB,CAU1D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ApolloClientFactoryContext } from "./ApolloClientFactoryContext.js";
|
|
3
|
+
function useCreateApolloClient() {
|
|
4
|
+
const createClient = React.useContext(ApolloClientFactoryContext);
|
|
5
|
+
if (!createClient) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"useCreateApolloClient must be used within a CedarApolloProvider"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return createClient;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
useCreateApolloClient
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/web",
|
|
3
|
-
"version": "7.0.0-canary.
|
|
3
|
+
"version": "7.0.0-canary.3093",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@apollo/client": "4.2.12",
|
|
82
|
-
"@cedarjs/server-store": "7.0.0-canary.
|
|
82
|
+
"@cedarjs/server-store": "7.0.0-canary.3093",
|
|
83
83
|
"@dr.pogodin/react-helmet": "2.0.4",
|
|
84
84
|
"@whatwg-node/fetch": "0.10.13",
|
|
85
85
|
"apollo-upload-client": "19.0.0",
|
|
@@ -95,9 +95,9 @@
|
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@apollo/client-react-streaming": "0.14.5",
|
|
97
97
|
"@arethetypeswrong/cli": "0.18.5",
|
|
98
|
-
"@cedarjs/auth": "7.0.0-canary.
|
|
99
|
-
"@cedarjs/framework-tools": "7.0.0-canary.
|
|
100
|
-
"@cedarjs/internal": "7.0.0-canary.
|
|
98
|
+
"@cedarjs/auth": "7.0.0-canary.3093",
|
|
99
|
+
"@cedarjs/framework-tools": "7.0.0-canary.3093",
|
|
100
|
+
"@cedarjs/internal": "7.0.0-canary.3093",
|
|
101
101
|
"@testing-library/dom": "10.4.1",
|
|
102
102
|
"@testing-library/jest-dom": "6.9.1",
|
|
103
103
|
"@testing-library/react": "16.3.3",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"vitest": "4.1.11"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
|
-
"@cedarjs/auth": "7.0.0-canary.
|
|
117
|
+
"@cedarjs/auth": "7.0.0-canary.3093",
|
|
118
118
|
"react": "19.2.8",
|
|
119
119
|
"react-dom": "19.2.8"
|
|
120
120
|
},
|