@cedarjs/web 7.0.0-rc.128 → 7.0.1-next.305
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 +9 -3
- package/dist/apollo/ApolloProviderWithFetchConfig.d.ts.map +1 -1
- package/dist/apollo/ApolloProviderWithFetchConfig.js +60 -37
- package/dist/apollo/CedarApolloProvider.d.ts +1 -0
- package/dist/apollo/CedarApolloProvider.d.ts.map +1 -1
- package/dist/apollo/CedarApolloProvider.js +13 -6
- package/dist/apollo/apolloLinkTypes.d.ts +9 -4
- package/dist/apollo/apolloLinkTypes.d.ts.map +1 -1
- package/dist/apollo/fragmentRegistry.d.ts +3 -3
- package/dist/apollo/fragmentRegistry.d.ts.map +1 -1
- package/dist/apollo/fragmentRegistry.js +35 -8
- 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/links.d.ts +6 -5
- package/dist/apollo/links.d.ts.map +1 -1
- package/dist/apollo/links.js +14 -9
- package/dist/apollo/parsedScalars.d.ts +36 -0
- package/dist/apollo/parsedScalars.d.ts.map +1 -0
- package/dist/apollo/parsedScalars.js +75 -0
- package/dist/apollo/sseLink.d.ts +5 -8
- package/dist/apollo/sseLink.d.ts.map +1 -1
- package/dist/apollo/sseLink.js +9 -12
- package/dist/apollo/suspense.d.ts +5 -3
- package/dist/apollo/suspense.d.ts.map +1 -1
- package/dist/apollo/suspense.js +35 -7
- package/dist/apollo/typeOverrides.d.ts +8 -0
- package/dist/apollo/typeOverrides.d.ts.map +1 -0
- package/dist/apollo/typeOverrides.js +0 -0
- package/dist/apollo/useCache.d.ts +4 -6
- package/dist/apollo/useCache.d.ts.map +1 -1
- package/dist/apollo/useCache.js +1 -1
- package/dist/apollo/useCreateApolloClient.d.ts +11 -0
- package/dist/apollo/useCreateApolloClient.d.ts.map +1 -0
- package/dist/apollo/useCreateApolloClient.js +14 -0
- package/dist/bundled/apollo-upload-client.d.ts +2 -2
- package/dist/bundled/apollo-upload-client.d.ts.map +1 -1
- package/dist/bundled/apollo-upload-client.js +1562 -1734
- package/dist/components/DevFatalErrorPage.d.ts +3 -3
- package/dist/components/DevFatalErrorPage.d.ts.map +1 -1
- package/dist/components/DevFatalErrorPage.js +66 -49
- package/dist/components/FatalErrorBoundary.d.ts +1 -1
- package/dist/components/cell/CellErrorBoundary.d.ts +3 -3
- package/dist/components/cell/CellErrorBoundary.d.ts.map +1 -1
- package/dist/components/cell/cellTypes.d.ts +51 -18
- package/dist/components/cell/cellTypes.d.ts.map +1 -1
- package/dist/components/cell/createCell.d.ts +2 -1
- package/dist/components/cell/createCell.d.ts.map +1 -1
- package/dist/components/cell/createCell.js +65 -60
- package/dist/components/cell/createFragmentCell.d.ts +2 -1
- package/dist/components/cell/createFragmentCell.d.ts.map +1 -1
- package/dist/components/cell/createFragmentCell.js +4 -2
- package/dist/components/cell/createServerCell.d.ts +3 -2
- package/dist/components/cell/createServerCell.d.ts.map +1 -1
- package/dist/components/cell/createServerCell.js +4 -2
- package/dist/components/cell/createSuspendingCell.d.ts +2 -1
- package/dist/components/cell/createSuspendingCell.d.ts.map +1 -1
- package/dist/components/cell/createSuspendingCell.js +37 -34
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -5
- package/package.json +20 -26
- package/apollo/index.js +0 -1
- package/apollo/package.json +0 -5
- package/toast/index.js +0 -1
- package/toast/package.json +0 -5
|
@@ -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"}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { InMemoryCache, setLogVerbosity } from '@apollo/client';
|
|
3
3
|
import type { UseAuth } from '@cedarjs/auth';
|
|
4
4
|
import type { GraphQLClientConfigProp } from './apolloLinkTypes.js';
|
|
5
5
|
interface Props {
|
|
6
6
|
config: Omit<GraphQLClientConfigProp, 'cacheConfig' | 'cache'> & {
|
|
7
|
-
cache:
|
|
7
|
+
cache: InMemoryCache;
|
|
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: () => InMemoryCache;
|
|
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;
|
|
1
|
+
{"version":3,"file":"ApolloProviderWithFetchConfig.d.ts","sourceRoot":"","sources":["../../src/apollo/ApolloProviderWithFetchConfig.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAEV,aAAa,EACb,eAAe,EAChB,MAAM,gBAAgB,CAAA;AAcvB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAQ5C,OAAO,KAAK,EAEV,uBAAuB,EACxB,MAAM,sBAAsB,CAAA;AAqC7B,UAAU,KAAK;IACb,MAAM,EAAE,IAAI,CAAC,uBAAuB,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG;QAC/D,KAAK,EAAE,aAAa,CAAA;KACrB,CAAA;IACD;;;;OAIG;IACH,WAAW,EAAE,MAAM,aAAa,CAAA;IAChC,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,qBAsMP"}
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import {
|
|
3
3
|
ApolloClient,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
4
|
+
ApolloLink,
|
|
5
|
+
setLogVerbosity as apolloSetLogVerbosity,
|
|
6
|
+
split
|
|
7
|
+
} from "@apollo/client";
|
|
8
|
+
import { SetContextLink } from "@apollo/client/link/context";
|
|
9
|
+
import { PersistedQueryLink } from "@apollo/client/link/persisted-queries";
|
|
10
|
+
import { ApolloProvider } from "@apollo/client/react";
|
|
11
|
+
import { getMainDefinition } from "@apollo/client/utilities";
|
|
11
12
|
import { print } from "graphql/language/printer.js";
|
|
13
|
+
import { map } from "rxjs";
|
|
12
14
|
import { useNoAuth } from "@cedarjs/auth";
|
|
13
|
-
import {
|
|
15
|
+
import { UploadHttpLink } from "../bundled/apollo-upload-client.js";
|
|
14
16
|
import { useFetchConfig } from "../components/FetchConfigProvider.js";
|
|
17
|
+
import { ApolloClientFactoryContext } from "./ApolloClientFactoryContext.js";
|
|
15
18
|
import { ErrorBoundary } from "./ErrorBoundary.js";
|
|
19
|
+
import { getOperationKind } from "./links.js";
|
|
16
20
|
import * as SSELinkExports from "./sseLink.js";
|
|
17
21
|
const { SSELink, isSubscription, isLiveQuery } = SSELinkExports;
|
|
18
22
|
function ApolloProviderWithFetchConfig({
|
|
19
23
|
config,
|
|
24
|
+
createCache,
|
|
20
25
|
children,
|
|
21
26
|
useAuth = useNoAuth,
|
|
22
27
|
logLevel
|
|
@@ -31,15 +36,20 @@ function ApolloProviderWithFetchConfig({
|
|
|
31
36
|
const { operationName, query, variables } = operation;
|
|
32
37
|
data.mostRecentRequest = {};
|
|
33
38
|
data.mostRecentRequest.operationName = operationName;
|
|
34
|
-
data.mostRecentRequest.operationKind =
|
|
39
|
+
data.mostRecentRequest.operationKind = getOperationKind(
|
|
40
|
+
query,
|
|
41
|
+
operationName
|
|
42
|
+
);
|
|
35
43
|
data.mostRecentRequest.variables = variables;
|
|
36
44
|
data.mostRecentRequest.query = query && print(operation.query);
|
|
37
|
-
return forward(operation).
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
return forward(operation).pipe(
|
|
46
|
+
map((result) => {
|
|
47
|
+
data.mostRecentResponse = result;
|
|
48
|
+
return result;
|
|
49
|
+
})
|
|
50
|
+
);
|
|
41
51
|
});
|
|
42
|
-
const withToken =
|
|
52
|
+
const withToken = new SetContextLink(async () => {
|
|
43
53
|
const token = await getToken();
|
|
44
54
|
return { token };
|
|
45
55
|
});
|
|
@@ -61,7 +71,7 @@ function ApolloProviderWithFetchConfig({
|
|
|
61
71
|
return forward(operation);
|
|
62
72
|
});
|
|
63
73
|
const { httpLinkConfig, link: cedarApolloLink, ...rest } = config ?? {};
|
|
64
|
-
const uploadLink =
|
|
74
|
+
const uploadLink = new UploadHttpLink({
|
|
65
75
|
uri,
|
|
66
76
|
...httpLinkConfig
|
|
67
77
|
});
|
|
@@ -83,8 +93,11 @@ function ApolloProviderWithFetchConfig({
|
|
|
83
93
|
const documentQuery = query;
|
|
84
94
|
return documentQuery?.["__meta__"]?.["hash"] !== void 0;
|
|
85
95
|
},
|
|
86
|
-
|
|
87
|
-
generateHash: (document) =>
|
|
96
|
+
new PersistedQueryLink({
|
|
97
|
+
generateHash: (document) => {
|
|
98
|
+
const documentWithMeta = document;
|
|
99
|
+
return documentWithMeta.__meta__?.hash ?? "";
|
|
100
|
+
}
|
|
88
101
|
}).concat(uploadOrSSELink),
|
|
89
102
|
uploadOrSSELink
|
|
90
103
|
);
|
|
@@ -99,35 +112,45 @@ function ApolloProviderWithFetchConfig({
|
|
|
99
112
|
if (typeof link === "function") {
|
|
100
113
|
link = link(cedarApolloLinks);
|
|
101
114
|
}
|
|
115
|
+
const defaultOptions = {
|
|
116
|
+
watchQuery: {
|
|
117
|
+
// The `fetchPolicy` we expect:
|
|
118
|
+
//
|
|
119
|
+
// > Apollo Client executes the full query against both the cache and
|
|
120
|
+
// > your GraphQL server.
|
|
121
|
+
// > The query automatically updates if the result of the server-side
|
|
122
|
+
// > query modifies cached fields.
|
|
123
|
+
//
|
|
124
|
+
// See https://www.apollographql.com/docs/react/data/queries/#cache-and-network.
|
|
125
|
+
fetchPolicy: "cache-and-network",
|
|
126
|
+
// So that Cells rerender when refetching.
|
|
127
|
+
// See https://www.apollographql.com/docs/react/data/queries/#inspecting-loading-states.
|
|
128
|
+
notifyOnNetworkStatusChange: true
|
|
129
|
+
}
|
|
130
|
+
};
|
|
102
131
|
const client = new ApolloClient({
|
|
103
|
-
|
|
104
|
-
// `beforeQuery` where it's too easy to overwrite them.
|
|
105
|
-
// See https://www.apollographql.com/docs/react/api/core/ApolloClient/#example-defaultoptions-object.
|
|
106
|
-
defaultOptions: {
|
|
107
|
-
watchQuery: {
|
|
108
|
-
// The `fetchPolicy` we expect:
|
|
109
|
-
//
|
|
110
|
-
// > Apollo Client executes the full query against both the cache and
|
|
111
|
-
// > your GraphQL server.
|
|
112
|
-
// > The query automatically updates if the result of the server-side
|
|
113
|
-
// > query modifies cached fields.
|
|
114
|
-
//
|
|
115
|
-
// See https://www.apollographql.com/docs/react/data/queries/#cache-and-network.
|
|
116
|
-
fetchPolicy: "cache-and-network",
|
|
117
|
-
// So that Cells rerender when refetching.
|
|
118
|
-
// See https://www.apollographql.com/docs/react/data/queries/#inspecting-loading-states.
|
|
119
|
-
notifyOnNetworkStatusChange: true
|
|
120
|
-
}
|
|
121
|
-
},
|
|
132
|
+
defaultOptions,
|
|
122
133
|
link,
|
|
123
134
|
...rest
|
|
124
135
|
});
|
|
136
|
+
const createApolloClient = (options) => {
|
|
137
|
+
const extraHeaders = options?.headers;
|
|
138
|
+
const withExtraHeaders = new SetContextLink((prevContext) => ({
|
|
139
|
+
headers: { ...prevContext.headers, ...extraHeaders }
|
|
140
|
+
}));
|
|
141
|
+
return new ApolloClient({
|
|
142
|
+
defaultOptions,
|
|
143
|
+
...rest,
|
|
144
|
+
cache: createCache(),
|
|
145
|
+
link: ApolloLink.from([withExtraHeaders, link])
|
|
146
|
+
});
|
|
147
|
+
};
|
|
125
148
|
const extendErrorAndRethrow = (error, _errorInfo) => {
|
|
126
149
|
error["mostRecentRequest"] = data.mostRecentRequest;
|
|
127
150
|
error["mostRecentResponse"] = data.mostRecentResponse;
|
|
128
151
|
throw error;
|
|
129
152
|
};
|
|
130
|
-
return /* @__PURE__ */ React.createElement(ApolloProvider, { client }, /* @__PURE__ */ React.createElement(ErrorBoundary, { onError: extendErrorAndRethrow }, children));
|
|
153
|
+
return /* @__PURE__ */ React.createElement(ApolloClientFactoryContext.Provider, { value: createApolloClient }, /* @__PURE__ */ React.createElement(ApolloProvider, { client }, /* @__PURE__ */ React.createElement(ErrorBoundary, { onError: extendErrorAndRethrow }, children)));
|
|
131
154
|
}
|
|
132
155
|
export {
|
|
133
156
|
ApolloProviderWithFetchConfig
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import type { DocumentNode, setLogVerbosity } from '@apollo/client';
|
|
3
3
|
import type { UseAuth } from '@cedarjs/auth';
|
|
4
4
|
import type { GraphQLClientConfigProp } from './apolloLinkTypes.js';
|
|
5
|
+
import './typeOverrides.js';
|
|
5
6
|
export type { ApolloClientCacheConfig, CedarApolloLink, CedarApolloLinkFactory, CedarApolloLinkName, CedarApolloLinks, GraphQLClientConfigProp, } from './apolloLinkTypes.js';
|
|
6
7
|
interface Props {
|
|
7
8
|
graphQLClientConfig?: GraphQLClientConfigProp;
|
|
@@ -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,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAGnE,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,
|
|
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;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAK5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAInE,OAAO,oBAAoB,CAAA;AAE3B,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,qBAsCP"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { InMemoryCache } from "@apollo/client
|
|
2
|
+
import { InMemoryCache } from "@apollo/client";
|
|
3
3
|
import { useNoAuth } from "@cedarjs/auth";
|
|
4
4
|
import { FetchConfigProvider } from "../components/FetchConfigProvider.js";
|
|
5
5
|
import { ApolloProviderWithFetchConfig } from "./ApolloProviderWithFetchConfig.js";
|
|
6
6
|
import { fragmentRegistry } from "./fragmentRegistry.js";
|
|
7
|
+
import { withParsedScalars } from "./parsedScalars.js";
|
|
8
|
+
import "./typeOverrides.js";
|
|
7
9
|
function CedarApolloProvider({
|
|
8
10
|
graphQLClientConfig,
|
|
9
11
|
fragments,
|
|
@@ -15,15 +17,20 @@ function CedarApolloProvider({
|
|
|
15
17
|
if (fragments) {
|
|
16
18
|
fragmentRegistry.register(...fragments);
|
|
17
19
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const createCache = () => {
|
|
21
|
+
return new InMemoryCache({
|
|
22
|
+
fragments: fragmentRegistry,
|
|
23
|
+
// Includes possibleTypes, along with every other option the caller set
|
|
24
|
+
// in cacheConfig
|
|
25
|
+
...withParsedScalars(cacheConfig)
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const cache = createCache().restore(globalThis?.__CEDAR__APOLLO_STATE ?? {});
|
|
23
29
|
return /* @__PURE__ */ React.createElement(FetchConfigProvider, { useAuth }, /* @__PURE__ */ React.createElement(
|
|
24
30
|
ApolloProviderWithFetchConfig,
|
|
25
31
|
{
|
|
26
32
|
config: { cache, ...config },
|
|
33
|
+
createCache,
|
|
27
34
|
useAuth,
|
|
28
35
|
logLevel
|
|
29
36
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApolloClient, ApolloLink, HttpLink, InMemoryCache, InMemoryCacheConfig } from '@apollo/client';
|
|
2
2
|
export type ApolloClientCacheConfig = InMemoryCacheConfig;
|
|
3
3
|
export type CedarApolloLinkName = 'withToken' | 'authMiddleware' | 'updateDataApolloLink' | 'httpLink';
|
|
4
4
|
export type CedarApolloLink<Name extends CedarApolloLinkName, Link extends ApolloLink = ApolloLink> = {
|
|
@@ -12,8 +12,13 @@ export type CedarApolloLinks = [
|
|
|
12
12
|
CedarApolloLink<'httpLink', ApolloLink | HttpLink>
|
|
13
13
|
];
|
|
14
14
|
export type CedarApolloLinkFactory = (links: CedarApolloLinks) => ApolloLink;
|
|
15
|
-
export type GraphQLClientConfigProp = Omit<
|
|
16
|
-
|
|
15
|
+
export type GraphQLClientConfigProp = Omit<ApolloClient.Options, 'cache' | 'link'> & {
|
|
16
|
+
/**
|
|
17
|
+
* Replace the `InMemoryCache` that `CedarApolloProvider` creates with one
|
|
18
|
+
* of your own. Apollo Client is told (via `TypeOverrides`) that its cache
|
|
19
|
+
* is always an `InMemoryCache`, so a cache passed here has to be one too.
|
|
20
|
+
*/
|
|
21
|
+
cache?: InMemoryCache;
|
|
17
22
|
/**
|
|
18
23
|
* Configuration for Apollo Client's `InMemoryCache`.
|
|
19
24
|
* See https://www.apollographql.com/docs/react/caching/cache-configuration/.
|
|
@@ -31,7 +36,7 @@ export type GraphQLClientConfigProp = Omit<ApolloClientOptions<unknown>, 'cache'
|
|
|
31
36
|
* }}>
|
|
32
37
|
* ```
|
|
33
38
|
*/
|
|
34
|
-
httpLinkConfig?:
|
|
39
|
+
httpLinkConfig?: HttpLink.Options;
|
|
35
40
|
/**
|
|
36
41
|
* Extend or overwrite `CedarApolloProvider`'s Apollo Link.
|
|
37
42
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apolloLinkTypes.d.ts","sourceRoot":"","sources":["../../src/apollo/apolloLinkTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"apolloLinkTypes.d.ts","sourceRoot":"","sources":["../../src/apollo/apolloLinkTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,aAAa,EACb,mBAAmB,EACpB,MAAM,gBAAgB,CAAA;AAEvB,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAEzD,MAAM,MAAM,mBAAmB,GAC7B,WAAW,GAAG,gBAAgB,GAAG,sBAAsB,GAAG,UAAU,CAAA;AAEtE,MAAM,MAAM,eAAe,CACzB,IAAI,SAAS,mBAAmB,EAChC,IAAI,SAAS,UAAU,GAAG,UAAU,IAClC;IACF,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,eAAe,CAAC,WAAW,CAAC;IAC5B,eAAe,CAAC,gBAAgB,CAAC;IACjC,eAAe,CAAC,sBAAsB,CAAC;IACvC,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,CAAC;CACnD,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,gBAAgB,KAAK,UAAU,CAAA;AAE5E,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,YAAY,CAAC,OAAO,EACpB,OAAO,GAAG,MAAM,CACjB,GAAG;IACF;;;;OAIG;IACH,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,sBAAsB,CAAA;CAC3C,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
1
|
+
import type { FragmentRegistryAPI } from '@apollo/client/cache';
|
|
2
|
+
import { useFragment as useApolloFragment } from '@apollo/client/react';
|
|
3
3
|
import type { DocumentNode } from 'graphql';
|
|
4
4
|
export interface FragmentHookOptions {
|
|
5
5
|
fragment: DocumentNode;
|
|
@@ -28,7 +28,7 @@ export type RegisterFragmentResult = {
|
|
|
28
28
|
fragment: DocumentNode;
|
|
29
29
|
typename: string;
|
|
30
30
|
getCacheKey: (id: FragmentIdentifier) => CacheKey;
|
|
31
|
-
useRegisteredFragment: <TData = any>(id: FragmentIdentifier) =>
|
|
31
|
+
useRegisteredFragment: <TData = any>(id: FragmentIdentifier) => useApolloFragment.Result<TData>;
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
34
|
* Read fragment data from Apollo Client's cache without firing a network
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragmentRegistry.d.ts","sourceRoot":"","sources":["../../src/apollo/fragmentRegistry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"fragmentRegistry.d.ts","sourceRoot":"","sources":["../../src/apollo/fragmentRegistry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAE/D,OAAO,EAEL,WAAW,IAAI,iBAAiB,EACjC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,YAAY,EAA0B,MAAM,SAAS,CAAA;AAGnE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B;AAED,MAAM,WAAW,kBAAkB,CAAC,KAAK,GAAG,GAAG;IAC7C;;;OAGG;IACH,IAAI,EAAE,KAAK,GAAG,SAAS,CAAA;IACvB,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,CAAA;AAEhD,MAAM,MAAM,QAAQ,GAAG;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,EAAE,EAAE,kBAAkB,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,YAAY,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,CAAC,EAAE,EAAE,kBAAkB,KAAK,QAAQ,CAAA;IACjD,qBAAqB,EAAE,CAAC,KAAK,GAAG,GAAG,EACjC,EAAE,EAAE,kBAAkB,KACnB,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;CACrC,CAAA;AA4ED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,GAAG,GAAG,EACrC,OAAO,EAAE,mBAAmB,GAC3B,kBAAkB,CAAC,KAAK,CAAC,CA6B3B;AAED;;;;;;;IAOI;AACJ,eAAO,MAAM,gBAAgB,EAAE,mBAA8C,CAAA;AAE7E;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,YAAY,EAAE,6BAE1D,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,YAAY,KACrB,sBAqBF,CAAA"}
|
|
@@ -1,24 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { createFragmentRegistry } from "@apollo/client/cache";
|
|
2
|
+
import {
|
|
3
|
+
useApolloClient,
|
|
4
|
+
useFragment as useApolloFragment
|
|
5
|
+
} from "@apollo/client/react";
|
|
6
|
+
import { Kind } from "graphql";
|
|
7
|
+
const getFragmentDefinition = (fragment) => {
|
|
8
|
+
const definition = fragment.definitions.find(
|
|
9
|
+
(def) => def.kind === Kind.FRAGMENT_DEFINITION
|
|
10
|
+
);
|
|
11
|
+
if (!definition) {
|
|
12
|
+
throw new Error("The passed document contains no fragment definition");
|
|
13
|
+
}
|
|
14
|
+
return definition;
|
|
15
|
+
};
|
|
4
16
|
const getTypenameFromFragment = (fragment) => {
|
|
5
|
-
|
|
6
|
-
|
|
17
|
+
return getFragmentDefinition(fragment).typeCondition.name.value;
|
|
18
|
+
};
|
|
19
|
+
const getSingleFragmentName = (fragment) => {
|
|
20
|
+
const definitions = fragment.definitions.filter(
|
|
21
|
+
(def) => def.kind === Kind.FRAGMENT_DEFINITION
|
|
22
|
+
);
|
|
23
|
+
return definitions.length === 1 ? definitions[0].name.value : void 0;
|
|
7
24
|
};
|
|
8
25
|
const useRegisteredFragmentHook = (fragment, id) => {
|
|
9
26
|
const from = { __typename: getTypenameFromFragment(fragment), id };
|
|
10
|
-
return
|
|
27
|
+
return useApolloFragment({
|
|
11
28
|
fragment,
|
|
29
|
+
// The cache's fragment registry adds the definitions of any spread
|
|
30
|
+
// fragments to the document, so Apollo Client can't infer the fragment
|
|
31
|
+
// name from the document alone
|
|
32
|
+
fragmentName: getFragmentDefinition(fragment).name.value,
|
|
12
33
|
from
|
|
13
34
|
});
|
|
14
35
|
};
|
|
15
36
|
const UNIDENTIFIABLE_FRAGMENT_REF = "CedarUnidentifiableFragmentRef:_";
|
|
16
37
|
function useFragment(options) {
|
|
17
|
-
const client =
|
|
38
|
+
const client = useApolloClient();
|
|
18
39
|
const { from, ...restOptions } = options;
|
|
19
40
|
const cacheId = client.cache.identify(from);
|
|
20
|
-
const result =
|
|
41
|
+
const result = useApolloFragment({
|
|
21
42
|
...restOptions,
|
|
43
|
+
// The cache's fragment registry adds the definitions of any spread
|
|
44
|
+
// fragments to the document, so Apollo Client can't infer the fragment
|
|
45
|
+
// name from the document alone. When the passed document has more than
|
|
46
|
+
// one fragment definition of its own we pass `undefined` and let Apollo
|
|
47
|
+
// Client surface its "must provide fragmentName" error
|
|
48
|
+
fragmentName: restOptions.fragmentName ?? getSingleFragmentName(options.fragment),
|
|
22
49
|
// We identify the object ourselves (above) because passing an
|
|
23
50
|
// unidentifiable object to `useFragment` logs a warning and returns a
|
|
24
51
|
// useless `{ data: {}, complete: true }` result
|
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
|
};
|
package/dist/apollo/links.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export declare function
|
|
1
|
+
import { ApolloLink, HttpLink } from '@apollo/client';
|
|
2
|
+
import { SetContextLink } from '@apollo/client/link/context';
|
|
3
|
+
import type { DocumentNode, OperationTypeNode } from 'graphql';
|
|
4
|
+
export declare function getOperationKind(query: DocumentNode, operationName?: string): OperationTypeNode | undefined;
|
|
5
|
+
export declare function createHttpLink(uri: string, httpLinkConfig: HttpLink.Options | undefined, cookieHeader?: string | null): HttpLink;
|
|
5
6
|
export declare function createUpdateDataLink(): ApolloLink;
|
|
6
7
|
export declare function createAuthApolloLink(authProviderType: string, headersFromFetchProvider: {
|
|
7
8
|
'auth-provider'?: string | undefined;
|
|
8
9
|
authorization?: string | undefined;
|
|
9
10
|
} | undefined): ApolloLink;
|
|
10
|
-
export declare function createTokenLink(getToken: () => Promise<string | null>):
|
|
11
|
+
export declare function createTokenLink(getToken: () => Promise<string | null>): SetContextLink;
|
|
11
12
|
export declare function createFinalLink({ userConfiguredLink, defaultLinks, }: {
|
|
12
13
|
userConfiguredLink?: ApolloLink | RedwoodApolloLinkFactory;
|
|
13
14
|
defaultLinks: RedwoodApolloLinks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/apollo/links.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/apollo/links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAK9D,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,YAAY,EACnB,aAAa,CAAC,EAAE,MAAM,GACrB,iBAAiB,GAAG,SAAS,CAE/B;AAED,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,QAAQ,CAAC,OAAO,GAAG,SAAS,EAC5C,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,YAc7B;AAeD,wBAAgB,oBAAoB,eAqBnC;AACD,wBAAgB,oBAAoB,CAClC,gBAAgB,EAAE,MAAM,EACxB,wBAAwB,EACpB;IACE,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACnC,GACD,SAAS,cA6Bd;AACD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,kBAMrE;AAED,wBAAgB,eAAe,CAAC,EAC9B,kBAAkB,EAClB,YAAY,GACb,EAAE;IACD,kBAAkB,CAAC,EAAE,UAAU,GAAG,wBAAwB,CAAA;IAC1D,YAAY,EAAE,kBAAkB,CAAA;CACjC,GAAG,UAAU,CAUb;AAID,MAAM,MAAM,iBAAiB,CAC3B,IAAI,SAAS,qBAAqB,EAClC,IAAI,SAAS,UAAU,GAAG,UAAU,IAClC;IACF,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,CAC7B,iBAAiB,CAAC,WAAW,CAAC,GAC9B,iBAAiB,CAAC,gBAAgB,CAAC,GACnC,iBAAiB,CAAC,kBAAkB,CAAC,GACrC,iBAAiB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAC1C,EAAE,CAAA;AAMH,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAA;AAC9C,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,IAAI,GAAG,KAAK,CAAA;AAC3E,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,kBAAkB,CAAC,CAAA;AAExE,MAAM,MAAM,wBAAwB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,UAAU,CAAA"}
|
package/dist/apollo/links.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { HttpLink } from "@apollo/client/link/http/index.js";
|
|
1
|
+
import { ApolloLink, HttpLink } from "@apollo/client";
|
|
2
|
+
import { SetContextLink } from "@apollo/client/link/context";
|
|
3
|
+
import { getOperationAST } from "graphql";
|
|
5
4
|
import { print } from "graphql/language/printer.js";
|
|
5
|
+
import { Observable } from "rxjs";
|
|
6
|
+
function getOperationKind(query, operationName) {
|
|
7
|
+
return getOperationAST(query, operationName)?.operation;
|
|
8
|
+
}
|
|
6
9
|
function createHttpLink(uri, httpLinkConfig, cookieHeader) {
|
|
7
10
|
const headers = {};
|
|
8
11
|
if (cookieHeader) {
|
|
@@ -19,7 +22,7 @@ function enhanceError(operation, error) {
|
|
|
19
22
|
const { operationName, query, variables } = operation;
|
|
20
23
|
error.__RedwoodEnhancedError = {
|
|
21
24
|
operationName,
|
|
22
|
-
operationKind: query
|
|
25
|
+
operationKind: getOperationKind(query, operationName),
|
|
23
26
|
variables,
|
|
24
27
|
query: query && print(query)
|
|
25
28
|
};
|
|
@@ -28,9 +31,9 @@ function enhanceError(operation, error) {
|
|
|
28
31
|
function createUpdateDataLink() {
|
|
29
32
|
return new ApolloLink((operation, forward) => {
|
|
30
33
|
return new Observable((observer) => {
|
|
31
|
-
forward(operation).subscribe({
|
|
34
|
+
const subscription = forward(operation).subscribe({
|
|
32
35
|
next(result) {
|
|
33
|
-
if (result.errors) {
|
|
36
|
+
if ("errors" in result && result.errors) {
|
|
34
37
|
result.errors.forEach((error) => {
|
|
35
38
|
enhanceError(operation, error);
|
|
36
39
|
});
|
|
@@ -42,6 +45,7 @@ function createUpdateDataLink() {
|
|
|
42
45
|
},
|
|
43
46
|
complete: observer.complete.bind(observer)
|
|
44
47
|
});
|
|
48
|
+
return () => subscription.unsubscribe();
|
|
45
49
|
});
|
|
46
50
|
});
|
|
47
51
|
}
|
|
@@ -67,7 +71,7 @@ function createAuthApolloLink(authProviderType, headersFromFetchProvider) {
|
|
|
67
71
|
});
|
|
68
72
|
}
|
|
69
73
|
function createTokenLink(getToken) {
|
|
70
|
-
return
|
|
74
|
+
return new SetContextLink(async () => {
|
|
71
75
|
const token = await getToken();
|
|
72
76
|
return { token };
|
|
73
77
|
});
|
|
@@ -90,5 +94,6 @@ export {
|
|
|
90
94
|
createFinalLink,
|
|
91
95
|
createHttpLink,
|
|
92
96
|
createTokenLink,
|
|
93
|
-
createUpdateDataLink
|
|
97
|
+
createUpdateDataLink,
|
|
98
|
+
getOperationKind
|
|
94
99
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { InMemoryCacheConfig } from '@apollo/client';
|
|
2
|
+
/**
|
|
3
|
+
* The cache config that `vite-plugin-cedar-parsed-scalars` builds from the
|
|
4
|
+
* project's GraphQL schema and the `graphql.parsedScalars` setting in
|
|
5
|
+
* `cedar.toml`, and puts on `globalThis.__CEDAR__PARSED_SCALARS`.
|
|
6
|
+
*/
|
|
7
|
+
export interface ParsedScalarsCacheConfig {
|
|
8
|
+
/**
|
|
9
|
+
* The scalars to parse, and the type each is parsed into
|
|
10
|
+
*/
|
|
11
|
+
scalars: Record<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* The fields that hold a parsed scalar
|
|
14
|
+
*/
|
|
15
|
+
typePolicies: Record<string, {
|
|
16
|
+
fields: Record<string, {
|
|
17
|
+
scalar: string;
|
|
18
|
+
}>;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* The input objects that hold a parsed scalar, directly or through another
|
|
22
|
+
* input object
|
|
23
|
+
*/
|
|
24
|
+
inputObjects: Record<string, {
|
|
25
|
+
fields: Record<string, string>;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Adds the scalars in `graphql.parsedScalars` to the cache config, so that
|
|
30
|
+
* Apollo Client's cache parses them when it reads a response and serializes
|
|
31
|
+
* them in a query's variables. Anything the app configured for the same
|
|
32
|
+
* scalar, field or input object takes precedence. Returns the config as it is
|
|
33
|
+
* when no scalar is parsed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function withParsedScalars(cacheConfig?: InMemoryCacheConfig): InMemoryCacheConfig | undefined;
|
|
36
|
+
//# sourceMappingURL=parsedScalars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsedScalars.d.ts","sourceRoot":"","sources":["../../src/apollo/parsedScalars.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAgB,MAAM,gBAAgB,CAAA;AAEvE;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC,CAAA;IAC5E;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAA;CACjE;AAmFD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,CAAC,EAAE,mBAAmB,GAChC,mBAAmB,GAAG,SAAS,CAmDjC"}
|