houdini-react 1.2.6 → 1.2.8
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/build/plugin/config.d.ts +2 -2
- package/build/plugin/index.d.ts +12 -1
- package/build/plugin-cjs/index.js +58817 -1974
- package/build/plugin-esm/index.js +58815 -1973
- package/build/runtime/index.d.ts +2 -1
- package/build/runtime/routing/components/Router.d.ts +5 -1
- package/build/runtime/routing/components/index.d.ts +1 -1
- package/build/runtime/routing/lib/types.d.ts +0 -1
- package/build/runtime-cjs/hooks/useDocumentHandle.js +11 -6
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +4 -2
- package/build/runtime-cjs/hooks/useMutation.js +3 -1
- package/build/runtime-cjs/index.d.ts +2 -1
- package/build/runtime-cjs/index.js +4 -2
- package/build/runtime-cjs/routing/components/Router.d.ts +5 -1
- package/build/runtime-cjs/routing/components/Router.js +34 -5
- package/build/runtime-cjs/routing/components/index.d.ts +1 -1
- package/build/runtime-cjs/routing/components/index.js +2 -0
- package/build/runtime-cjs/routing/lib/types.d.ts +0 -1
- package/build/runtime-esm/hooks/useDocumentHandle.js +11 -6
- package/build/runtime-esm/hooks/useDocumentSubscription.js +4 -2
- package/build/runtime-esm/hooks/useMutation.js +3 -1
- package/build/runtime-esm/index.d.ts +2 -1
- package/build/runtime-esm/index.js +4 -2
- package/build/runtime-esm/routing/components/Router.d.ts +5 -1
- package/build/runtime-esm/routing/components/Router.js +31 -4
- package/build/runtime-esm/routing/components/index.d.ts +1 -1
- package/build/runtime-esm/routing/components/index.js +2 -1
- package/build/runtime-esm/routing/lib/types.d.ts +0 -1
- package/build/server/compat.d.ts +7 -0
- package/build/server/index.d.ts +17 -0
- package/build/server/session.d.ts +3 -0
- package/build/server-cjs/index.js +166712 -0
- package/build/server-cjs/package.json +1 -0
- package/build/server-esm/index.js +166703 -0
- package/build/server-esm/package.json +1 -0
- package/package.json +20 -5
package/build/runtime/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { PendingCache } from './routing/components/Router';
|
|
|
7
7
|
import { SuspenseCache } from './routing/lib/cache';
|
|
8
8
|
export * from './hooks';
|
|
9
9
|
export * from './routing';
|
|
10
|
-
export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, }: {
|
|
10
|
+
export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, session, }: {
|
|
11
11
|
intialURL: string;
|
|
12
12
|
cache: Cache;
|
|
13
13
|
loaded_queries?: Record<string, {
|
|
@@ -15,6 +15,7 @@ export declare function Router({ cache, intialURL, artifact_cache, component_cac
|
|
|
15
15
|
variables: GraphQLVariables;
|
|
16
16
|
}>;
|
|
17
17
|
loaded_artifacts?: Record<string, QueryArtifact>;
|
|
18
|
+
session?: App.Session;
|
|
18
19
|
} & RouterCache): JSX.Element;
|
|
19
20
|
type RouterCache = {
|
|
20
21
|
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
@@ -21,7 +21,7 @@ export declare function Router({ manifest, intialURL, loaded_queries, loaded_art
|
|
|
21
21
|
loaded_artifacts?: Record<string, QueryArtifact>;
|
|
22
22
|
}): JSX.Element;
|
|
23
23
|
export declare function useNavigationContext(): NavigationContext;
|
|
24
|
-
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, }: {
|
|
24
|
+
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, session: ssrSession, }: {
|
|
25
25
|
children: React.ReactElement;
|
|
26
26
|
client: HoudiniClient;
|
|
27
27
|
cache: Cache;
|
|
@@ -30,6 +30,7 @@ export declare function RouterContextProvider({ children, client, cache, artifac
|
|
|
30
30
|
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
31
31
|
pending_cache: PendingCache;
|
|
32
32
|
last_variables: LRUCache<GraphQLVariables>;
|
|
33
|
+
session?: App.Session;
|
|
33
34
|
}): JSX.Element;
|
|
34
35
|
type RouterContext = {
|
|
35
36
|
client: HoudiniClient;
|
|
@@ -39,6 +40,7 @@ type RouterContext = {
|
|
|
39
40
|
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
40
41
|
pending_cache: PendingCache;
|
|
41
42
|
last_variables: LRUCache<GraphQLVariables>;
|
|
43
|
+
session: App.Session;
|
|
42
44
|
};
|
|
43
45
|
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
44
46
|
resolve: () => void;
|
|
@@ -47,6 +49,8 @@ export type PendingCache = SuspenseCache<Promise<void> & {
|
|
|
47
49
|
export declare const useRouterContext: () => RouterContext;
|
|
48
50
|
export declare function useClient(): HoudiniClient;
|
|
49
51
|
export declare function useCache(): Cache;
|
|
52
|
+
export declare function updateLocalSession(session: App.Session): void;
|
|
53
|
+
export declare function useSession(): App.Session;
|
|
50
54
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
51
55
|
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
|
|
52
56
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Link } from './Link';
|
|
2
|
-
export { Router, RouterContextProvider, useClient } from './Router';
|
|
2
|
+
export { Router, RouterContextProvider, useClient, updateLocalSession } from './Router';
|
|
@@ -31,6 +31,7 @@ var import_pageInfo = require("$houdini/runtime/lib/pageInfo");
|
|
|
31
31
|
var import_pagination = require("$houdini/runtime/lib/pagination");
|
|
32
32
|
var import_types = require("$houdini/runtime/lib/types");
|
|
33
33
|
var import_react = __toESM(require("react"));
|
|
34
|
+
var import_Router = require("../routing/components/Router");
|
|
34
35
|
function useDocumentHandle({
|
|
35
36
|
artifact,
|
|
36
37
|
observer,
|
|
@@ -38,6 +39,7 @@ function useDocumentHandle({
|
|
|
38
39
|
}) {
|
|
39
40
|
const [forwardPending, setForwardPending] = import_react.default.useState(false);
|
|
40
41
|
const [backwardPending, setBackwardPending] = import_react.default.useState(false);
|
|
42
|
+
const session = (0, import_Router.useSession)();
|
|
41
43
|
return import_react.default.useMemo(() => {
|
|
42
44
|
const wrapLoad = (setLoading, fn) => {
|
|
43
45
|
return async (value) => {
|
|
@@ -47,7 +49,10 @@ function useDocumentHandle({
|
|
|
47
49
|
return result;
|
|
48
50
|
};
|
|
49
51
|
};
|
|
50
|
-
const fetchQuery = (args) => observer.send(
|
|
52
|
+
const fetchQuery = (args) => observer.send({
|
|
53
|
+
...args,
|
|
54
|
+
session
|
|
55
|
+
});
|
|
51
56
|
if (artifact.kind !== import_types.ArtifactKind.Query || !artifact.refetch?.paginated) {
|
|
52
57
|
return {
|
|
53
58
|
data: storeValue.data,
|
|
@@ -55,7 +60,6 @@ function useDocumentHandle({
|
|
|
55
60
|
partial: storeValue.partial
|
|
56
61
|
};
|
|
57
62
|
}
|
|
58
|
-
const getSession = async () => ({});
|
|
59
63
|
if (artifact.refetch.method === "cursor") {
|
|
60
64
|
const handlers = (0, import_pagination.cursorHandlers)({
|
|
61
65
|
artifact,
|
|
@@ -69,10 +73,11 @@ function useDocumentHandle({
|
|
|
69
73
|
disableSubscriptions: true,
|
|
70
74
|
applyUpdates: updates,
|
|
71
75
|
...args?.cacheParams
|
|
72
|
-
}
|
|
76
|
+
},
|
|
77
|
+
session
|
|
73
78
|
});
|
|
74
79
|
},
|
|
75
|
-
getSession
|
|
80
|
+
getSession: async () => session
|
|
76
81
|
});
|
|
77
82
|
return {
|
|
78
83
|
data: storeValue.data,
|
|
@@ -102,7 +107,7 @@ function useDocumentHandle({
|
|
|
102
107
|
}
|
|
103
108
|
});
|
|
104
109
|
},
|
|
105
|
-
getSession: async () =>
|
|
110
|
+
getSession: async () => session
|
|
106
111
|
});
|
|
107
112
|
return {
|
|
108
113
|
data: storeValue.data,
|
|
@@ -118,7 +123,7 @@ function useDocumentHandle({
|
|
|
118
123
|
refetch: fetchQuery,
|
|
119
124
|
partial: storeValue.partial
|
|
120
125
|
};
|
|
121
|
-
}, [artifact, observer, storeValue, true, true]);
|
|
126
|
+
}, [artifact, observer, session, storeValue, true, true]);
|
|
122
127
|
}
|
|
123
128
|
// Annotate the CommonJS export names for ESM import in node:
|
|
124
129
|
0 && (module.exports = {
|
|
@@ -27,6 +27,7 @@ __export(useDocumentSubscription_exports, {
|
|
|
27
27
|
useDocumentSubscription: () => useDocumentSubscription
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(useDocumentSubscription_exports);
|
|
30
|
+
var import_Router = require("../routing/components/Router");
|
|
30
31
|
var import_useDeepCompareEffect = __toESM(require("./useDeepCompareEffect"));
|
|
31
32
|
var import_useDocumentStore = require("./useDocumentStore");
|
|
32
33
|
function useDocumentSubscription({
|
|
@@ -40,11 +41,12 @@ function useDocumentSubscription({
|
|
|
40
41
|
artifact,
|
|
41
42
|
...observeParams
|
|
42
43
|
});
|
|
44
|
+
const session = (0, import_Router.useSession)();
|
|
43
45
|
(0, import_useDeepCompareEffect.default)(() => {
|
|
44
46
|
if (!disabled) {
|
|
45
47
|
observer.send({
|
|
46
48
|
variables,
|
|
47
|
-
session
|
|
49
|
+
session,
|
|
48
50
|
metadata: {},
|
|
49
51
|
...send
|
|
50
52
|
});
|
|
@@ -54,7 +56,7 @@ function useDocumentSubscription({
|
|
|
54
56
|
observer.cleanup();
|
|
55
57
|
}
|
|
56
58
|
};
|
|
57
|
-
}, [disabled, observer, variables ?? {}, send ?? {}]);
|
|
59
|
+
}, [disabled, session, observer, variables ?? {}, send ?? {}]);
|
|
58
60
|
return [
|
|
59
61
|
{
|
|
60
62
|
parent: send?.stuff?.parentID,
|
|
@@ -21,12 +21,14 @@ __export(useMutation_exports, {
|
|
|
21
21
|
useMutation: () => useMutation
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(useMutation_exports);
|
|
24
|
+
var import_Router = require("../routing/components/Router");
|
|
24
25
|
var import_useDocumentStore = require("./useDocumentStore");
|
|
25
26
|
function useMutation({
|
|
26
27
|
artifact
|
|
27
28
|
}) {
|
|
28
29
|
const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({ artifact });
|
|
29
30
|
const pending = storeValue.fetching;
|
|
31
|
+
const session = (0, import_Router.useSession)();
|
|
30
32
|
const mutate = ({
|
|
31
33
|
metadata,
|
|
32
34
|
fetch,
|
|
@@ -35,7 +37,7 @@ function useMutation({
|
|
|
35
37
|
}) => observer.send({
|
|
36
38
|
variables,
|
|
37
39
|
metadata,
|
|
38
|
-
session
|
|
40
|
+
session,
|
|
39
41
|
stuff: {
|
|
40
42
|
...mutationConfig
|
|
41
43
|
}
|
|
@@ -7,7 +7,7 @@ import { PendingCache } from './routing/components/Router';
|
|
|
7
7
|
import { SuspenseCache } from './routing/lib/cache';
|
|
8
8
|
export * from './hooks';
|
|
9
9
|
export * from './routing';
|
|
10
|
-
export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, }: {
|
|
10
|
+
export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, session, }: {
|
|
11
11
|
intialURL: string;
|
|
12
12
|
cache: Cache;
|
|
13
13
|
loaded_queries?: Record<string, {
|
|
@@ -15,6 +15,7 @@ export declare function Router({ cache, intialURL, artifact_cache, component_cac
|
|
|
15
15
|
variables: GraphQLVariables;
|
|
16
16
|
}>;
|
|
17
17
|
loaded_artifacts?: Record<string, QueryArtifact>;
|
|
18
|
+
session?: App.Session;
|
|
18
19
|
} & RouterCache): JSX.Element;
|
|
19
20
|
type RouterCache = {
|
|
20
21
|
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
@@ -45,7 +45,8 @@ function Router({
|
|
|
45
45
|
pending_cache,
|
|
46
46
|
last_variables,
|
|
47
47
|
loaded_queries,
|
|
48
|
-
loaded_artifacts
|
|
48
|
+
loaded_artifacts,
|
|
49
|
+
session
|
|
49
50
|
}) {
|
|
50
51
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
51
52
|
import_routing.RouterContextProvider,
|
|
@@ -56,7 +57,8 @@ function Router({
|
|
|
56
57
|
component_cache,
|
|
57
58
|
data_cache,
|
|
58
59
|
pending_cache,
|
|
59
|
-
last_variables
|
|
60
|
+
last_variables,
|
|
61
|
+
session
|
|
60
62
|
},
|
|
61
63
|
/* @__PURE__ */ import_react.default.createElement(
|
|
62
64
|
import_routing.Router,
|
|
@@ -21,7 +21,7 @@ export declare function Router({ manifest, intialURL, loaded_queries, loaded_art
|
|
|
21
21
|
loaded_artifacts?: Record<string, QueryArtifact>;
|
|
22
22
|
}): JSX.Element;
|
|
23
23
|
export declare function useNavigationContext(): NavigationContext;
|
|
24
|
-
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, }: {
|
|
24
|
+
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, session: ssrSession, }: {
|
|
25
25
|
children: React.ReactElement;
|
|
26
26
|
client: HoudiniClient;
|
|
27
27
|
cache: Cache;
|
|
@@ -30,6 +30,7 @@ export declare function RouterContextProvider({ children, client, cache, artifac
|
|
|
30
30
|
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
31
31
|
pending_cache: PendingCache;
|
|
32
32
|
last_variables: LRUCache<GraphQLVariables>;
|
|
33
|
+
session?: App.Session;
|
|
33
34
|
}): JSX.Element;
|
|
34
35
|
type RouterContext = {
|
|
35
36
|
client: HoudiniClient;
|
|
@@ -39,6 +40,7 @@ type RouterContext = {
|
|
|
39
40
|
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
40
41
|
pending_cache: PendingCache;
|
|
41
42
|
last_variables: LRUCache<GraphQLVariables>;
|
|
43
|
+
session: App.Session;
|
|
42
44
|
};
|
|
43
45
|
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
44
46
|
resolve: () => void;
|
|
@@ -47,6 +49,8 @@ export type PendingCache = SuspenseCache<Promise<void> & {
|
|
|
47
49
|
export declare const useRouterContext: () => RouterContext;
|
|
48
50
|
export declare function useClient(): HoudiniClient;
|
|
49
51
|
export declare function useCache(): Cache;
|
|
52
|
+
export declare function updateLocalSession(session: App.Session): void;
|
|
53
|
+
export declare function useSession(): App.Session;
|
|
50
54
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
51
55
|
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
|
|
52
56
|
export {};
|
|
@@ -26,12 +26,14 @@ var Router_exports = {};
|
|
|
26
26
|
__export(Router_exports, {
|
|
27
27
|
Router: () => Router,
|
|
28
28
|
RouterContextProvider: () => RouterContextProvider,
|
|
29
|
+
updateLocalSession: () => updateLocalSession,
|
|
29
30
|
useCache: () => useCache,
|
|
30
31
|
useClient: () => useClient,
|
|
31
32
|
useCurrentVariables: () => useCurrentVariables,
|
|
32
33
|
useNavigationContext: () => useNavigationContext,
|
|
33
34
|
useQueryResult: () => useQueryResult,
|
|
34
|
-
useRouterContext: () => useRouterContext
|
|
35
|
+
useRouterContext: () => useRouterContext,
|
|
36
|
+
useSession: () => useSession
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(Router_exports);
|
|
37
39
|
var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
|
|
@@ -99,6 +101,7 @@ function useLoadPage({
|
|
|
99
101
|
last_variables
|
|
100
102
|
} = useRouterContext();
|
|
101
103
|
const stream = (0, import_react_streaming.useStream)();
|
|
104
|
+
const session = useSession();
|
|
102
105
|
function load_query({ id, artifact }) {
|
|
103
106
|
last_variables.set(page.id, variables);
|
|
104
107
|
if (pending_cache.has(id)) {
|
|
@@ -114,7 +117,8 @@ function useLoadPage({
|
|
|
114
117
|
reject = rej;
|
|
115
118
|
observer.send({
|
|
116
119
|
variables,
|
|
117
|
-
cacheParams: { disableSubscriptions: true }
|
|
120
|
+
cacheParams: { disableSubscriptions: true },
|
|
121
|
+
session
|
|
118
122
|
}).then(() => {
|
|
119
123
|
data_cache.set(id, observer);
|
|
120
124
|
if (loaded_queries) {
|
|
@@ -210,8 +214,19 @@ function RouterContextProvider({
|
|
|
210
214
|
component_cache,
|
|
211
215
|
data_cache,
|
|
212
216
|
pending_cache,
|
|
213
|
-
last_variables
|
|
217
|
+
last_variables,
|
|
218
|
+
session: ssrSession = {}
|
|
214
219
|
}) {
|
|
220
|
+
const [session, setSession] = import_react.default.useState(ssrSession);
|
|
221
|
+
const handleNewSession = import_react.default.useCallback((event) => {
|
|
222
|
+
setSession(event.detail);
|
|
223
|
+
}, []);
|
|
224
|
+
import_react.default.useEffect(() => {
|
|
225
|
+
window.addEventListener("_houdini_session_", handleNewSession);
|
|
226
|
+
return () => {
|
|
227
|
+
window.removeEventListener("_houdini_session_", handleNewSession);
|
|
228
|
+
};
|
|
229
|
+
}, []);
|
|
215
230
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
216
231
|
Context.Provider,
|
|
217
232
|
{
|
|
@@ -222,7 +237,8 @@ function RouterContextProvider({
|
|
|
222
237
|
component_cache,
|
|
223
238
|
data_cache,
|
|
224
239
|
pending_cache,
|
|
225
|
-
last_variables
|
|
240
|
+
last_variables,
|
|
241
|
+
session
|
|
226
242
|
}
|
|
227
243
|
},
|
|
228
244
|
children
|
|
@@ -242,6 +258,17 @@ function useClient() {
|
|
|
242
258
|
function useCache() {
|
|
243
259
|
return useRouterContext().cache;
|
|
244
260
|
}
|
|
261
|
+
function updateLocalSession(session) {
|
|
262
|
+
window.dispatchEvent(
|
|
263
|
+
new CustomEvent("_houdini_session_", {
|
|
264
|
+
bubbles: true,
|
|
265
|
+
detail: session
|
|
266
|
+
})
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
function useSession() {
|
|
270
|
+
return useRouterContext().session;
|
|
271
|
+
}
|
|
245
272
|
function useCurrentVariables() {
|
|
246
273
|
return import_react.default.useContext(VariableContext);
|
|
247
274
|
}
|
|
@@ -258,10 +285,12 @@ function useQueryResult(name) {
|
|
|
258
285
|
0 && (module.exports = {
|
|
259
286
|
Router,
|
|
260
287
|
RouterContextProvider,
|
|
288
|
+
updateLocalSession,
|
|
261
289
|
useCache,
|
|
262
290
|
useClient,
|
|
263
291
|
useCurrentVariables,
|
|
264
292
|
useNavigationContext,
|
|
265
293
|
useQueryResult,
|
|
266
|
-
useRouterContext
|
|
294
|
+
useRouterContext,
|
|
295
|
+
useSession
|
|
267
296
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Link } from './Link';
|
|
2
|
-
export { Router, RouterContextProvider, useClient } from './Router';
|
|
2
|
+
export { Router, RouterContextProvider, useClient, updateLocalSession } from './Router';
|
|
@@ -21,6 +21,7 @@ __export(components_exports, {
|
|
|
21
21
|
Link: () => import_Link.Link,
|
|
22
22
|
Router: () => import_Router.Router,
|
|
23
23
|
RouterContextProvider: () => import_Router.RouterContextProvider,
|
|
24
|
+
updateLocalSession: () => import_Router.updateLocalSession,
|
|
24
25
|
useClient: () => import_Router.useClient
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(components_exports);
|
|
@@ -31,5 +32,6 @@ var import_Router = require("./Router");
|
|
|
31
32
|
Link,
|
|
32
33
|
Router,
|
|
33
34
|
RouterContextProvider,
|
|
35
|
+
updateLocalSession,
|
|
34
36
|
useClient
|
|
35
37
|
});
|
|
@@ -2,6 +2,7 @@ import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
|
|
|
2
2
|
import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
|
|
3
3
|
import { ArtifactKind } from "$houdini/runtime/lib/types";
|
|
4
4
|
import React from "react";
|
|
5
|
+
import { useSession } from "../routing/components/Router";
|
|
5
6
|
function useDocumentHandle({
|
|
6
7
|
artifact,
|
|
7
8
|
observer,
|
|
@@ -9,6 +10,7 @@ function useDocumentHandle({
|
|
|
9
10
|
}) {
|
|
10
11
|
const [forwardPending, setForwardPending] = React.useState(false);
|
|
11
12
|
const [backwardPending, setBackwardPending] = React.useState(false);
|
|
13
|
+
const session = useSession();
|
|
12
14
|
return React.useMemo(() => {
|
|
13
15
|
const wrapLoad = (setLoading, fn) => {
|
|
14
16
|
return async (value) => {
|
|
@@ -18,7 +20,10 @@ function useDocumentHandle({
|
|
|
18
20
|
return result;
|
|
19
21
|
};
|
|
20
22
|
};
|
|
21
|
-
const fetchQuery = (args) => observer.send(
|
|
23
|
+
const fetchQuery = (args) => observer.send({
|
|
24
|
+
...args,
|
|
25
|
+
session
|
|
26
|
+
});
|
|
22
27
|
if (artifact.kind !== ArtifactKind.Query || !artifact.refetch?.paginated) {
|
|
23
28
|
return {
|
|
24
29
|
data: storeValue.data,
|
|
@@ -26,7 +31,6 @@ function useDocumentHandle({
|
|
|
26
31
|
partial: storeValue.partial
|
|
27
32
|
};
|
|
28
33
|
}
|
|
29
|
-
const getSession = async () => ({});
|
|
30
34
|
if (artifact.refetch.method === "cursor") {
|
|
31
35
|
const handlers = cursorHandlers({
|
|
32
36
|
artifact,
|
|
@@ -40,10 +44,11 @@ function useDocumentHandle({
|
|
|
40
44
|
disableSubscriptions: true,
|
|
41
45
|
applyUpdates: updates,
|
|
42
46
|
...args?.cacheParams
|
|
43
|
-
}
|
|
47
|
+
},
|
|
48
|
+
session
|
|
44
49
|
});
|
|
45
50
|
},
|
|
46
|
-
getSession
|
|
51
|
+
getSession: async () => session
|
|
47
52
|
});
|
|
48
53
|
return {
|
|
49
54
|
data: storeValue.data,
|
|
@@ -73,7 +78,7 @@ function useDocumentHandle({
|
|
|
73
78
|
}
|
|
74
79
|
});
|
|
75
80
|
},
|
|
76
|
-
getSession: async () =>
|
|
81
|
+
getSession: async () => session
|
|
77
82
|
});
|
|
78
83
|
return {
|
|
79
84
|
data: storeValue.data,
|
|
@@ -89,7 +94,7 @@ function useDocumentHandle({
|
|
|
89
94
|
refetch: fetchQuery,
|
|
90
95
|
partial: storeValue.partial
|
|
91
96
|
};
|
|
92
|
-
}, [artifact, observer, storeValue, true, true]);
|
|
97
|
+
}, [artifact, observer, session, storeValue, true, true]);
|
|
93
98
|
}
|
|
94
99
|
export {
|
|
95
100
|
useDocumentHandle
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useSession } from "../routing/components/Router";
|
|
1
2
|
import useDeepCompareEffect from "./useDeepCompareEffect";
|
|
2
3
|
import { useDocumentStore } from "./useDocumentStore";
|
|
3
4
|
function useDocumentSubscription({
|
|
@@ -11,11 +12,12 @@ function useDocumentSubscription({
|
|
|
11
12
|
artifact,
|
|
12
13
|
...observeParams
|
|
13
14
|
});
|
|
15
|
+
const session = useSession();
|
|
14
16
|
useDeepCompareEffect(() => {
|
|
15
17
|
if (!disabled) {
|
|
16
18
|
observer.send({
|
|
17
19
|
variables,
|
|
18
|
-
session
|
|
20
|
+
session,
|
|
19
21
|
metadata: {},
|
|
20
22
|
...send
|
|
21
23
|
});
|
|
@@ -25,7 +27,7 @@ function useDocumentSubscription({
|
|
|
25
27
|
observer.cleanup();
|
|
26
28
|
}
|
|
27
29
|
};
|
|
28
|
-
}, [disabled, observer, variables ?? {}, send ?? {}]);
|
|
30
|
+
}, [disabled, session, observer, variables ?? {}, send ?? {}]);
|
|
29
31
|
return [
|
|
30
32
|
{
|
|
31
33
|
parent: send?.stuff?.parentID,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { useSession } from "../routing/components/Router";
|
|
1
2
|
import { useDocumentStore } from "./useDocumentStore";
|
|
2
3
|
function useMutation({
|
|
3
4
|
artifact
|
|
4
5
|
}) {
|
|
5
6
|
const [storeValue, observer] = useDocumentStore({ artifact });
|
|
6
7
|
const pending = storeValue.fetching;
|
|
8
|
+
const session = useSession();
|
|
7
9
|
const mutate = ({
|
|
8
10
|
metadata,
|
|
9
11
|
fetch,
|
|
@@ -12,7 +14,7 @@ function useMutation({
|
|
|
12
14
|
}) => observer.send({
|
|
13
15
|
variables,
|
|
14
16
|
metadata,
|
|
15
|
-
session
|
|
17
|
+
session,
|
|
16
18
|
stuff: {
|
|
17
19
|
...mutationConfig
|
|
18
20
|
}
|
|
@@ -7,7 +7,7 @@ import { PendingCache } from './routing/components/Router';
|
|
|
7
7
|
import { SuspenseCache } from './routing/lib/cache';
|
|
8
8
|
export * from './hooks';
|
|
9
9
|
export * from './routing';
|
|
10
|
-
export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, }: {
|
|
10
|
+
export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, session, }: {
|
|
11
11
|
intialURL: string;
|
|
12
12
|
cache: Cache;
|
|
13
13
|
loaded_queries?: Record<string, {
|
|
@@ -15,6 +15,7 @@ export declare function Router({ cache, intialURL, artifact_cache, component_cac
|
|
|
15
15
|
variables: GraphQLVariables;
|
|
16
16
|
}>;
|
|
17
17
|
loaded_artifacts?: Record<string, QueryArtifact>;
|
|
18
|
+
session?: App.Session;
|
|
18
19
|
} & RouterCache): JSX.Element;
|
|
19
20
|
type RouterCache = {
|
|
20
21
|
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
@@ -14,7 +14,8 @@ function Router({
|
|
|
14
14
|
pending_cache,
|
|
15
15
|
last_variables,
|
|
16
16
|
loaded_queries,
|
|
17
|
-
loaded_artifacts
|
|
17
|
+
loaded_artifacts,
|
|
18
|
+
session
|
|
18
19
|
}) {
|
|
19
20
|
return /* @__PURE__ */ React.createElement(
|
|
20
21
|
RouterContextProvider,
|
|
@@ -25,7 +26,8 @@ function Router({
|
|
|
25
26
|
component_cache,
|
|
26
27
|
data_cache,
|
|
27
28
|
pending_cache,
|
|
28
|
-
last_variables
|
|
29
|
+
last_variables,
|
|
30
|
+
session
|
|
29
31
|
},
|
|
30
32
|
/* @__PURE__ */ React.createElement(
|
|
31
33
|
RouterImpl,
|
|
@@ -21,7 +21,7 @@ export declare function Router({ manifest, intialURL, loaded_queries, loaded_art
|
|
|
21
21
|
loaded_artifacts?: Record<string, QueryArtifact>;
|
|
22
22
|
}): JSX.Element;
|
|
23
23
|
export declare function useNavigationContext(): NavigationContext;
|
|
24
|
-
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, }: {
|
|
24
|
+
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, session: ssrSession, }: {
|
|
25
25
|
children: React.ReactElement;
|
|
26
26
|
client: HoudiniClient;
|
|
27
27
|
cache: Cache;
|
|
@@ -30,6 +30,7 @@ export declare function RouterContextProvider({ children, client, cache, artifac
|
|
|
30
30
|
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
31
31
|
pending_cache: PendingCache;
|
|
32
32
|
last_variables: LRUCache<GraphQLVariables>;
|
|
33
|
+
session?: App.Session;
|
|
33
34
|
}): JSX.Element;
|
|
34
35
|
type RouterContext = {
|
|
35
36
|
client: HoudiniClient;
|
|
@@ -39,6 +40,7 @@ type RouterContext = {
|
|
|
39
40
|
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
40
41
|
pending_cache: PendingCache;
|
|
41
42
|
last_variables: LRUCache<GraphQLVariables>;
|
|
43
|
+
session: App.Session;
|
|
42
44
|
};
|
|
43
45
|
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
44
46
|
resolve: () => void;
|
|
@@ -47,6 +49,8 @@ export type PendingCache = SuspenseCache<Promise<void> & {
|
|
|
47
49
|
export declare const useRouterContext: () => RouterContext;
|
|
48
50
|
export declare function useClient(): HoudiniClient;
|
|
49
51
|
export declare function useCache(): Cache;
|
|
52
|
+
export declare function updateLocalSession(session: App.Session): void;
|
|
53
|
+
export declare function useSession(): App.Session;
|
|
50
54
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
51
55
|
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
|
|
52
56
|
export {};
|
|
@@ -63,6 +63,7 @@ function useLoadPage({
|
|
|
63
63
|
last_variables
|
|
64
64
|
} = useRouterContext();
|
|
65
65
|
const stream = useStream();
|
|
66
|
+
const session = useSession();
|
|
66
67
|
function load_query({ id, artifact }) {
|
|
67
68
|
last_variables.set(page.id, variables);
|
|
68
69
|
if (pending_cache.has(id)) {
|
|
@@ -78,7 +79,8 @@ function useLoadPage({
|
|
|
78
79
|
reject = rej;
|
|
79
80
|
observer.send({
|
|
80
81
|
variables,
|
|
81
|
-
cacheParams: { disableSubscriptions: true }
|
|
82
|
+
cacheParams: { disableSubscriptions: true },
|
|
83
|
+
session
|
|
82
84
|
}).then(() => {
|
|
83
85
|
data_cache.set(id, observer);
|
|
84
86
|
if (loaded_queries) {
|
|
@@ -174,8 +176,19 @@ function RouterContextProvider({
|
|
|
174
176
|
component_cache,
|
|
175
177
|
data_cache,
|
|
176
178
|
pending_cache,
|
|
177
|
-
last_variables
|
|
179
|
+
last_variables,
|
|
180
|
+
session: ssrSession = {}
|
|
178
181
|
}) {
|
|
182
|
+
const [session, setSession] = React.useState(ssrSession);
|
|
183
|
+
const handleNewSession = React.useCallback((event) => {
|
|
184
|
+
setSession(event.detail);
|
|
185
|
+
}, []);
|
|
186
|
+
React.useEffect(() => {
|
|
187
|
+
window.addEventListener("_houdini_session_", handleNewSession);
|
|
188
|
+
return () => {
|
|
189
|
+
window.removeEventListener("_houdini_session_", handleNewSession);
|
|
190
|
+
};
|
|
191
|
+
}, []);
|
|
179
192
|
return /* @__PURE__ */ React.createElement(
|
|
180
193
|
Context.Provider,
|
|
181
194
|
{
|
|
@@ -186,7 +199,8 @@ function RouterContextProvider({
|
|
|
186
199
|
component_cache,
|
|
187
200
|
data_cache,
|
|
188
201
|
pending_cache,
|
|
189
|
-
last_variables
|
|
202
|
+
last_variables,
|
|
203
|
+
session
|
|
190
204
|
}
|
|
191
205
|
},
|
|
192
206
|
children
|
|
@@ -206,6 +220,17 @@ function useClient() {
|
|
|
206
220
|
function useCache() {
|
|
207
221
|
return useRouterContext().cache;
|
|
208
222
|
}
|
|
223
|
+
function updateLocalSession(session) {
|
|
224
|
+
window.dispatchEvent(
|
|
225
|
+
new CustomEvent("_houdini_session_", {
|
|
226
|
+
bubbles: true,
|
|
227
|
+
detail: session
|
|
228
|
+
})
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
function useSession() {
|
|
232
|
+
return useRouterContext().session;
|
|
233
|
+
}
|
|
209
234
|
function useCurrentVariables() {
|
|
210
235
|
return React.useContext(VariableContext);
|
|
211
236
|
}
|
|
@@ -221,10 +246,12 @@ function useQueryResult(name) {
|
|
|
221
246
|
export {
|
|
222
247
|
Router,
|
|
223
248
|
RouterContextProvider,
|
|
249
|
+
updateLocalSession,
|
|
224
250
|
useCache,
|
|
225
251
|
useClient,
|
|
226
252
|
useCurrentVariables,
|
|
227
253
|
useNavigationContext,
|
|
228
254
|
useQueryResult,
|
|
229
|
-
useRouterContext
|
|
255
|
+
useRouterContext,
|
|
256
|
+
useSession
|
|
230
257
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Link } from './Link';
|
|
2
|
-
export { Router, RouterContextProvider, useClient } from './Router';
|
|
2
|
+
export { Router, RouterContextProvider, useClient, updateLocalSession } from './Router';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Link } from "./Link";
|
|
2
|
-
import { Router, RouterContextProvider, useClient } from "./Router";
|
|
2
|
+
import { Router, RouterContextProvider, useClient, updateLocalSession } from "./Router";
|
|
3
3
|
export {
|
|
4
4
|
Link,
|
|
5
5
|
Router,
|
|
6
6
|
RouterContextProvider,
|
|
7
|
+
updateLocalSession,
|
|
7
8
|
useClient
|
|
8
9
|
};
|