houdini-react 1.2.44 → 1.2.46
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-cjs/index.js +871 -868
- package/build/plugin-esm/index.js +871 -868
- package/build/runtime/hooks/useDocumentHandle.d.ts +2 -0
- package/build/runtime/index.d.ts +1 -1
- package/build/runtime/routing/Router.d.ts +13 -1
- package/build/runtime-cjs/clientPlugin.js +1 -1
- package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +2 -0
- package/build/runtime-cjs/hooks/useDocumentHandle.js +20 -5
- package/build/runtime-cjs/index.d.ts +1 -1
- package/build/runtime-cjs/index.js +2 -0
- package/build/runtime-cjs/routing/Router.d.ts +13 -1
- package/build/runtime-cjs/routing/Router.js +75 -19
- package/build/runtime-esm/clientPlugin.js +1 -1
- package/build/runtime-esm/hooks/useDocumentHandle.d.ts +2 -0
- package/build/runtime-esm/hooks/useDocumentHandle.js +21 -6
- package/build/runtime-esm/index.d.ts +1 -1
- package/build/runtime-esm/index.js +2 -1
- package/build/runtime-esm/routing/Router.d.ts +13 -1
- package/build/runtime-esm/routing/Router.js +73 -19
- package/package.json +4 -4
|
@@ -10,6 +10,8 @@ export declare function useDocumentHandle<_Artifact extends QueryArtifact, _Data
|
|
|
10
10
|
export type DocumentHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables> = {
|
|
11
11
|
data: _Data;
|
|
12
12
|
partial: boolean;
|
|
13
|
+
fetch: FetchFn<_Data, Partial<_Input>>;
|
|
14
|
+
variables: _Input;
|
|
13
15
|
} & RefetchHandlers<_Artifact, _Data, _Input>;
|
|
14
16
|
type RefetchHandlers<_Artifact extends QueryArtifact, _Data extends GraphQLObject, _Input> = _Artifact extends {
|
|
15
17
|
refetch: {
|
package/build/runtime/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { GraphQLObject } from '$houdini/lib/types';
|
|
|
2
2
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
3
3
|
import { RouterCache } from './routing';
|
|
4
4
|
export * from './hooks';
|
|
5
|
-
export { router_cache, useSession, useLocation } from './routing';
|
|
5
|
+
export { router_cache, useSession, useLocation, useRoute } from './routing';
|
|
6
6
|
export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session, assetPrefix, injectToStream, }: {
|
|
7
7
|
initialURL: string;
|
|
8
8
|
initialVariables: GraphQLObject;
|
|
@@ -5,6 +5,7 @@ import { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
|
5
5
|
import { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
6
6
|
import type { RouterManifest } from '$houdini/runtime/router/types';
|
|
7
7
|
import React from 'react';
|
|
8
|
+
import { DocumentHandle } from '../hooks/useDocumentHandle';
|
|
8
9
|
import { SuspenseCache } from './cache';
|
|
9
10
|
type ComponentType = any;
|
|
10
11
|
/**
|
|
@@ -20,6 +21,7 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
20
21
|
}): JSX.Element;
|
|
21
22
|
export declare const useLocation: () => {
|
|
22
23
|
pathname: string;
|
|
24
|
+
params: Record<string, any>;
|
|
23
25
|
};
|
|
24
26
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
25
27
|
children: React.ReactElement;
|
|
@@ -53,7 +55,7 @@ export declare function useCache(): Cache;
|
|
|
53
55
|
export declare function updateLocalSession(session: App.Session): void;
|
|
54
56
|
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
55
57
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
56
|
-
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null,
|
|
58
|
+
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentHandle<any, _Data, _Input>];
|
|
57
59
|
export type RouterCache = {
|
|
58
60
|
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
59
61
|
component_cache: SuspenseCache<(props: any) => React.ReactElement>;
|
|
@@ -69,4 +71,14 @@ export declare function router_cache({ pending_queries, artifacts, components, i
|
|
|
69
71
|
initialVariables?: Record<string, GraphQLVariables>;
|
|
70
72
|
initialArtifacts?: Record<string, QueryArtifact>;
|
|
71
73
|
}): RouterCache;
|
|
74
|
+
export declare function PageContextProvider({ keys, children, }: {
|
|
75
|
+
keys: string[];
|
|
76
|
+
children: React.ReactNode;
|
|
77
|
+
}): JSX.Element;
|
|
78
|
+
export declare function useRoute<PageProps extends {
|
|
79
|
+
Params: {};
|
|
80
|
+
}>(): RouteProp<PageProps['Params']>;
|
|
81
|
+
export type RouteProp<Params> = {
|
|
82
|
+
params: Params;
|
|
83
|
+
};
|
|
72
84
|
export {};
|
|
@@ -10,6 +10,8 @@ export declare function useDocumentHandle<_Artifact extends QueryArtifact, _Data
|
|
|
10
10
|
export type DocumentHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables> = {
|
|
11
11
|
data: _Data;
|
|
12
12
|
partial: boolean;
|
|
13
|
+
fetch: FetchFn<_Data, Partial<_Input>>;
|
|
14
|
+
variables: _Input;
|
|
13
15
|
} & RefetchHandlers<_Artifact, _Data, _Input>;
|
|
14
16
|
type RefetchHandlers<_Artifact extends QueryArtifact, _Data extends GraphQLObject, _Input> = _Artifact extends {
|
|
15
17
|
refetch: {
|
|
@@ -40,6 +40,13 @@ function useDocumentHandle({
|
|
|
40
40
|
const [forwardPending, setForwardPending] = import_react.default.useState(false);
|
|
41
41
|
const [backwardPending, setBackwardPending] = import_react.default.useState(false);
|
|
42
42
|
const [session] = (0, import_Router.useSession)();
|
|
43
|
+
const client = (0, import_Router.useClient)();
|
|
44
|
+
const paginationObserver = import_react.default.useMemo(() => {
|
|
45
|
+
if (!artifact.refetch?.paginated) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return client.observe({ artifact });
|
|
49
|
+
}, [artifact.name]);
|
|
43
50
|
return import_react.default.useMemo(() => {
|
|
44
51
|
const wrapLoad = (setLoading, fn) => {
|
|
45
52
|
return async (value) => {
|
|
@@ -55,7 +62,9 @@ function useDocumentHandle({
|
|
|
55
62
|
});
|
|
56
63
|
if (artifact.kind !== import_types.ArtifactKind.Query || !artifact.refetch?.paginated) {
|
|
57
64
|
return {
|
|
65
|
+
artifact,
|
|
58
66
|
data: storeValue.data,
|
|
67
|
+
variables: storeValue.variables,
|
|
59
68
|
fetch: fetchQuery,
|
|
60
69
|
partial: storeValue.partial
|
|
61
70
|
};
|
|
@@ -67,12 +76,12 @@ function useDocumentHandle({
|
|
|
67
76
|
getVariables: () => storeValue.variables,
|
|
68
77
|
fetch: fetchQuery,
|
|
69
78
|
fetchUpdate: (args, updates) => {
|
|
70
|
-
return
|
|
79
|
+
return paginationObserver.send({
|
|
71
80
|
...args,
|
|
72
81
|
cacheParams: {
|
|
82
|
+
...args?.cacheParams,
|
|
73
83
|
disableSubscriptions: true,
|
|
74
|
-
applyUpdates: updates
|
|
75
|
-
...args?.cacheParams
|
|
84
|
+
applyUpdates: updates
|
|
76
85
|
},
|
|
77
86
|
session
|
|
78
87
|
});
|
|
@@ -80,7 +89,9 @@ function useDocumentHandle({
|
|
|
80
89
|
getSession: async () => session
|
|
81
90
|
});
|
|
82
91
|
return {
|
|
92
|
+
artifact,
|
|
83
93
|
data: storeValue.data,
|
|
94
|
+
variables: storeValue.variables,
|
|
84
95
|
fetch: handlers.fetch,
|
|
85
96
|
partial: storeValue.partial,
|
|
86
97
|
loadNext: wrapLoad(setForwardPending, handlers.loadNextPage),
|
|
@@ -98,7 +109,7 @@ function useDocumentHandle({
|
|
|
98
109
|
storeName: artifact.name,
|
|
99
110
|
fetch: fetchQuery,
|
|
100
111
|
fetchUpdate: async (args, updates = ["append"]) => {
|
|
101
|
-
return
|
|
112
|
+
return paginationObserver.send({
|
|
102
113
|
...args,
|
|
103
114
|
cacheParams: {
|
|
104
115
|
disableSubscriptions: true,
|
|
@@ -110,7 +121,9 @@ function useDocumentHandle({
|
|
|
110
121
|
getSession: async () => session
|
|
111
122
|
});
|
|
112
123
|
return {
|
|
124
|
+
artifact,
|
|
113
125
|
data: storeValue.data,
|
|
126
|
+
variables: storeValue.variables,
|
|
114
127
|
fetch: handlers.fetch,
|
|
115
128
|
partial: storeValue.partial,
|
|
116
129
|
loadNext: wrapLoad(setForwardPending, handlers.loadNextPage),
|
|
@@ -118,12 +131,14 @@ function useDocumentHandle({
|
|
|
118
131
|
};
|
|
119
132
|
}
|
|
120
133
|
return {
|
|
134
|
+
artifact,
|
|
121
135
|
data: storeValue.data,
|
|
136
|
+
variables: storeValue.variables,
|
|
122
137
|
fetch: fetchQuery,
|
|
123
138
|
refetch: fetchQuery,
|
|
124
139
|
partial: storeValue.partial
|
|
125
140
|
};
|
|
126
|
-
}, [artifact, observer, session, storeValue
|
|
141
|
+
}, [artifact, observer, session, storeValue]);
|
|
127
142
|
}
|
|
128
143
|
// Annotate the CommonJS export names for ESM import in node:
|
|
129
144
|
0 && (module.exports = {
|
|
@@ -2,7 +2,7 @@ import type { GraphQLObject } from '$houdini/lib/types';
|
|
|
2
2
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
3
3
|
import { RouterCache } from './routing';
|
|
4
4
|
export * from './hooks';
|
|
5
|
-
export { router_cache, useSession, useLocation } from './routing';
|
|
5
|
+
export { router_cache, useSession, useLocation, useRoute } from './routing';
|
|
6
6
|
export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session, assetPrefix, injectToStream, }: {
|
|
7
7
|
initialURL: string;
|
|
8
8
|
initialVariables: GraphQLObject;
|
|
@@ -28,6 +28,7 @@ __export(runtime_exports, {
|
|
|
28
28
|
Router: () => Router,
|
|
29
29
|
router_cache: () => import_routing2.router_cache,
|
|
30
30
|
useLocation: () => import_routing2.useLocation,
|
|
31
|
+
useRoute: () => import_routing2.useRoute,
|
|
31
32
|
useSession: () => import_routing2.useSession
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(runtime_exports);
|
|
@@ -77,5 +78,6 @@ function Router({
|
|
|
77
78
|
Router,
|
|
78
79
|
router_cache,
|
|
79
80
|
useLocation,
|
|
81
|
+
useRoute,
|
|
80
82
|
useSession
|
|
81
83
|
});
|
|
@@ -5,6 +5,7 @@ import { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
|
5
5
|
import { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
6
6
|
import type { RouterManifest } from '$houdini/runtime/router/types';
|
|
7
7
|
import React from 'react';
|
|
8
|
+
import { DocumentHandle } from '../hooks/useDocumentHandle';
|
|
8
9
|
import { SuspenseCache } from './cache';
|
|
9
10
|
type ComponentType = any;
|
|
10
11
|
/**
|
|
@@ -20,6 +21,7 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
20
21
|
}): JSX.Element;
|
|
21
22
|
export declare const useLocation: () => {
|
|
22
23
|
pathname: string;
|
|
24
|
+
params: Record<string, any>;
|
|
23
25
|
};
|
|
24
26
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
25
27
|
children: React.ReactElement;
|
|
@@ -53,7 +55,7 @@ export declare function useCache(): Cache;
|
|
|
53
55
|
export declare function updateLocalSession(session: App.Session): void;
|
|
54
56
|
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
55
57
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
56
|
-
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null,
|
|
58
|
+
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentHandle<any, _Data, _Input>];
|
|
57
59
|
export type RouterCache = {
|
|
58
60
|
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
59
61
|
component_cache: SuspenseCache<(props: any) => React.ReactElement>;
|
|
@@ -69,4 +71,14 @@ export declare function router_cache({ pending_queries, artifacts, components, i
|
|
|
69
71
|
initialVariables?: Record<string, GraphQLVariables>;
|
|
70
72
|
initialArtifacts?: Record<string, QueryArtifact>;
|
|
71
73
|
}): RouterCache;
|
|
74
|
+
export declare function PageContextProvider({ keys, children, }: {
|
|
75
|
+
keys: string[];
|
|
76
|
+
children: React.ReactNode;
|
|
77
|
+
}): JSX.Element;
|
|
78
|
+
export declare function useRoute<PageProps extends {
|
|
79
|
+
Params: {};
|
|
80
|
+
}>(): RouteProp<PageProps['Params']>;
|
|
81
|
+
export type RouteProp<Params> = {
|
|
82
|
+
params: Params;
|
|
83
|
+
};
|
|
72
84
|
export {};
|
|
@@ -24,6 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var Router_exports = {};
|
|
26
26
|
__export(Router_exports, {
|
|
27
|
+
PageContextProvider: () => PageContextProvider,
|
|
27
28
|
Router: () => Router,
|
|
28
29
|
RouterContextProvider: () => RouterContextProvider,
|
|
29
30
|
router_cache: () => router_cache,
|
|
@@ -33,6 +34,7 @@ __export(Router_exports, {
|
|
|
33
34
|
useCurrentVariables: () => useCurrentVariables,
|
|
34
35
|
useLocation: () => useLocation,
|
|
35
36
|
useQueryResult: () => useQueryResult,
|
|
37
|
+
useRoute: () => useRoute,
|
|
36
38
|
useRouterContext: () => useRouterContext,
|
|
37
39
|
useSession: () => useSession
|
|
38
40
|
});
|
|
@@ -40,9 +42,11 @@ module.exports = __toCommonJS(Router_exports);
|
|
|
40
42
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
43
|
var import_config = __toESM(require("$houdini/runtime/imports/config"));
|
|
42
44
|
var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
|
|
45
|
+
var import_scalars = require("$houdini/runtime/lib/scalars");
|
|
43
46
|
var import_match = require("$houdini/runtime/router/match");
|
|
44
47
|
var import_react = __toESM(require("react"));
|
|
45
48
|
var import_react2 = require("react");
|
|
49
|
+
var import_useDocumentHandle = require("../hooks/useDocumentHandle");
|
|
46
50
|
var import_useDocumentStore = require("../hooks/useDocumentStore");
|
|
47
51
|
var import_cache = require("./cache");
|
|
48
52
|
const PreloadWhich = {
|
|
@@ -59,7 +63,10 @@ function Router({
|
|
|
59
63
|
const [currentURL, setCurrentURL] = import_react.default.useState(() => {
|
|
60
64
|
return initialURL || window.location.pathname;
|
|
61
65
|
});
|
|
62
|
-
const [page, variables] = (0, import_match.find_match)(manifest, currentURL);
|
|
66
|
+
const [page, variables] = (0, import_match.find_match)(import_config.default, manifest, currentURL);
|
|
67
|
+
if (!page) {
|
|
68
|
+
throw new Error("404");
|
|
69
|
+
}
|
|
63
70
|
const { loadData, loadComponent } = usePageData({
|
|
64
71
|
page,
|
|
65
72
|
variables,
|
|
@@ -90,7 +97,7 @@ function Router({
|
|
|
90
97
|
setCurrentURL(val);
|
|
91
98
|
},
|
|
92
99
|
preload(url, which) {
|
|
93
|
-
const [page2, variables2] = (0, import_match.find_match)(manifest, url);
|
|
100
|
+
const [page2, variables2] = (0, import_match.find_match)(import_config.default, manifest, url);
|
|
94
101
|
if (["both", "component"].includes(which)) {
|
|
95
102
|
loadComponent(page2);
|
|
96
103
|
}
|
|
@@ -99,7 +106,7 @@ function Router({
|
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
108
|
});
|
|
102
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocationContext.Provider, { value: { pathname: currentURL }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: currentURL }, page.id) }) });
|
|
109
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocationContext.Provider, { value: { pathname: currentURL, params: variables ?? {} }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: currentURL }, page.id) }) });
|
|
103
110
|
}
|
|
104
111
|
const useLocation = () => (0, import_react2.useContext)(LocationContext);
|
|
105
112
|
function usePageData({
|
|
@@ -135,9 +142,8 @@ function usePageData({
|
|
|
135
142
|
reject = rej;
|
|
136
143
|
observer.send({
|
|
137
144
|
variables,
|
|
138
|
-
cacheParams: { disableSubscriptions: true },
|
|
139
145
|
session
|
|
140
|
-
}).then(() => {
|
|
146
|
+
}).then(async () => {
|
|
141
147
|
data_cache.set(id, observer);
|
|
142
148
|
if (observer.state.errors && observer.state.errors.length > 0) {
|
|
143
149
|
reject(observer.state.errors.map((e) => e.message).join("\n"));
|
|
@@ -149,7 +155,12 @@ function usePageData({
|
|
|
149
155
|
window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
|
|
150
156
|
|
|
151
157
|
const artifactName = "${artifact.name}"
|
|
152
|
-
const value = ${JSON.stringify(
|
|
158
|
+
const value = ${JSON.stringify(
|
|
159
|
+
await (0, import_scalars.marshalSelection)({
|
|
160
|
+
selection: observer.artifact.selection,
|
|
161
|
+
data: observer.state.data
|
|
162
|
+
})
|
|
163
|
+
)}
|
|
153
164
|
|
|
154
165
|
// if the data is pending, we need to resolve it
|
|
155
166
|
if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
|
|
@@ -158,10 +169,22 @@ function usePageData({
|
|
|
158
169
|
const new_store = window.__houdini__client__.observe({
|
|
159
170
|
artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
|
|
160
171
|
cache: window.__houdini__cache__,
|
|
161
|
-
initialValue: value,
|
|
162
172
|
})
|
|
163
173
|
|
|
164
|
-
|
|
174
|
+
// we're pushing this store onto the client, it should be initialized
|
|
175
|
+
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
176
|
+
setup: true,
|
|
177
|
+
variables: ${JSON.stringify(
|
|
178
|
+
(0, import_scalars.marshalInputs)({
|
|
179
|
+
artifact: observer.artifact,
|
|
180
|
+
input: variables,
|
|
181
|
+
config: import_config.default
|
|
182
|
+
})
|
|
183
|
+
)}
|
|
184
|
+
}).then(() => {
|
|
185
|
+
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
186
|
+
})
|
|
187
|
+
|
|
165
188
|
}
|
|
166
189
|
|
|
167
190
|
|
|
@@ -178,12 +201,12 @@ function usePageData({
|
|
|
178
201
|
if (!window.__houdini__pending_artifacts__) {
|
|
179
202
|
window.__houdini__pending_artifacts__ = {}
|
|
180
203
|
}
|
|
181
|
-
|
|
182
|
-
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(variables)}
|
|
183
|
-
window.__houdini__pending_data__[artifactName] = value
|
|
184
|
-
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
185
204
|
}
|
|
186
205
|
|
|
206
|
+
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(observer.state.variables)}
|
|
207
|
+
window.__houdini__pending_data__[artifactName] = value
|
|
208
|
+
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
209
|
+
|
|
187
210
|
// if this payload finishes off an ssr request, we need to resolve the signal
|
|
188
211
|
if (window.__houdini__nav_caches__?.ssr_signals.has(artifactName)) {
|
|
189
212
|
|
|
@@ -192,7 +215,13 @@ function usePageData({
|
|
|
192
215
|
// we're pushing this store onto the client, it should be initialized
|
|
193
216
|
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
194
217
|
setup: true,
|
|
195
|
-
variables: ${JSON.stringify(
|
|
218
|
+
variables: ${JSON.stringify(
|
|
219
|
+
(0, import_scalars.marshalInputs)({
|
|
220
|
+
artifact: observer.artifact,
|
|
221
|
+
input: variables,
|
|
222
|
+
config: import_config.default
|
|
223
|
+
})
|
|
224
|
+
)}
|
|
196
225
|
})
|
|
197
226
|
}
|
|
198
227
|
|
|
@@ -222,7 +251,7 @@ function usePageData({
|
|
|
222
251
|
}
|
|
223
252
|
let last = {};
|
|
224
253
|
let usedVariables = {};
|
|
225
|
-
for (const variable of pageVariables) {
|
|
254
|
+
for (const variable of Object.keys(pageVariables)) {
|
|
226
255
|
last[variable] = last_variables.get(artifact)[variable];
|
|
227
256
|
usedVariables[variable] = (variables2 ?? {})[variable];
|
|
228
257
|
}
|
|
@@ -348,7 +377,8 @@ function useSession() {
|
|
|
348
377
|
method: "POST",
|
|
349
378
|
body: JSON.stringify(newSession),
|
|
350
379
|
headers: {
|
|
351
|
-
"Content-Type": "application/json"
|
|
380
|
+
"Content-Type": "application/json",
|
|
381
|
+
Accept: "application/json"
|
|
352
382
|
}
|
|
353
383
|
});
|
|
354
384
|
};
|
|
@@ -358,17 +388,27 @@ function useCurrentVariables() {
|
|
|
358
388
|
return import_react.default.useContext(VariableContext);
|
|
359
389
|
}
|
|
360
390
|
const VariableContext = import_react.default.createContext(null);
|
|
361
|
-
const LocationContext = import_react.default.createContext({
|
|
391
|
+
const LocationContext = import_react.default.createContext({
|
|
392
|
+
pathname: "",
|
|
393
|
+
params: {}
|
|
394
|
+
});
|
|
362
395
|
function useQueryResult(name) {
|
|
363
|
-
const
|
|
364
|
-
const
|
|
396
|
+
const { data_cache, artifact_cache } = useRouterContext();
|
|
397
|
+
const store_ref = data_cache.get(name);
|
|
398
|
+
const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({
|
|
365
399
|
artifact: store_ref.artifact,
|
|
366
400
|
observer: store_ref
|
|
367
401
|
});
|
|
402
|
+
const { data, errors } = storeValue;
|
|
368
403
|
if (errors && errors.length > 0) {
|
|
369
404
|
throw new Error(JSON.stringify(errors));
|
|
370
405
|
}
|
|
371
|
-
|
|
406
|
+
const handle = (0, import_useDocumentHandle.useDocumentHandle)({
|
|
407
|
+
artifact: artifact_cache.get(name),
|
|
408
|
+
observer,
|
|
409
|
+
storeValue
|
|
410
|
+
});
|
|
411
|
+
return [data, handle];
|
|
372
412
|
}
|
|
373
413
|
function useLinkBehavior({
|
|
374
414
|
goto,
|
|
@@ -468,6 +508,20 @@ function router_cache({
|
|
|
468
508
|
}
|
|
469
509
|
return result;
|
|
470
510
|
}
|
|
511
|
+
const PageContext = import_react.default.createContext({ params: {} });
|
|
512
|
+
function PageContextProvider({
|
|
513
|
+
keys,
|
|
514
|
+
children
|
|
515
|
+
}) {
|
|
516
|
+
const location2 = useLocation();
|
|
517
|
+
const params = Object.fromEntries(
|
|
518
|
+
Object.entries(location2.params).filter(([key]) => keys.includes(key))
|
|
519
|
+
);
|
|
520
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageContext.Provider, { value: { params }, children });
|
|
521
|
+
}
|
|
522
|
+
function useRoute() {
|
|
523
|
+
return (0, import_react2.useContext)(PageContext);
|
|
524
|
+
}
|
|
471
525
|
function signal_promise() {
|
|
472
526
|
let resolve = () => {
|
|
473
527
|
};
|
|
@@ -485,6 +539,7 @@ function signal_promise() {
|
|
|
485
539
|
}
|
|
486
540
|
// Annotate the CommonJS export names for ESM import in node:
|
|
487
541
|
0 && (module.exports = {
|
|
542
|
+
PageContextProvider,
|
|
488
543
|
Router,
|
|
489
544
|
RouterContextProvider,
|
|
490
545
|
router_cache,
|
|
@@ -494,6 +549,7 @@ function signal_promise() {
|
|
|
494
549
|
useCurrentVariables,
|
|
495
550
|
useLocation,
|
|
496
551
|
useQueryResult,
|
|
552
|
+
useRoute,
|
|
497
553
|
useRouterContext,
|
|
498
554
|
useSession
|
|
499
555
|
});
|
|
@@ -10,6 +10,8 @@ export declare function useDocumentHandle<_Artifact extends QueryArtifact, _Data
|
|
|
10
10
|
export type DocumentHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables> = {
|
|
11
11
|
data: _Data;
|
|
12
12
|
partial: boolean;
|
|
13
|
+
fetch: FetchFn<_Data, Partial<_Input>>;
|
|
14
|
+
variables: _Input;
|
|
13
15
|
} & RefetchHandlers<_Artifact, _Data, _Input>;
|
|
14
16
|
type RefetchHandlers<_Artifact extends QueryArtifact, _Data extends GraphQLObject, _Input> = _Artifact extends {
|
|
15
17
|
refetch: {
|
|
@@ -2,7 +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/Router";
|
|
5
|
+
import { useClient, useSession } from "../routing/Router";
|
|
6
6
|
function useDocumentHandle({
|
|
7
7
|
artifact,
|
|
8
8
|
observer,
|
|
@@ -11,6 +11,13 @@ function useDocumentHandle({
|
|
|
11
11
|
const [forwardPending, setForwardPending] = React.useState(false);
|
|
12
12
|
const [backwardPending, setBackwardPending] = React.useState(false);
|
|
13
13
|
const [session] = useSession();
|
|
14
|
+
const client = useClient();
|
|
15
|
+
const paginationObserver = React.useMemo(() => {
|
|
16
|
+
if (!artifact.refetch?.paginated) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return client.observe({ artifact });
|
|
20
|
+
}, [artifact.name]);
|
|
14
21
|
return React.useMemo(() => {
|
|
15
22
|
const wrapLoad = (setLoading, fn) => {
|
|
16
23
|
return async (value) => {
|
|
@@ -26,7 +33,9 @@ function useDocumentHandle({
|
|
|
26
33
|
});
|
|
27
34
|
if (artifact.kind !== ArtifactKind.Query || !artifact.refetch?.paginated) {
|
|
28
35
|
return {
|
|
36
|
+
artifact,
|
|
29
37
|
data: storeValue.data,
|
|
38
|
+
variables: storeValue.variables,
|
|
30
39
|
fetch: fetchQuery,
|
|
31
40
|
partial: storeValue.partial
|
|
32
41
|
};
|
|
@@ -38,12 +47,12 @@ function useDocumentHandle({
|
|
|
38
47
|
getVariables: () => storeValue.variables,
|
|
39
48
|
fetch: fetchQuery,
|
|
40
49
|
fetchUpdate: (args, updates) => {
|
|
41
|
-
return
|
|
50
|
+
return paginationObserver.send({
|
|
42
51
|
...args,
|
|
43
52
|
cacheParams: {
|
|
53
|
+
...args?.cacheParams,
|
|
44
54
|
disableSubscriptions: true,
|
|
45
|
-
applyUpdates: updates
|
|
46
|
-
...args?.cacheParams
|
|
55
|
+
applyUpdates: updates
|
|
47
56
|
},
|
|
48
57
|
session
|
|
49
58
|
});
|
|
@@ -51,7 +60,9 @@ function useDocumentHandle({
|
|
|
51
60
|
getSession: async () => session
|
|
52
61
|
});
|
|
53
62
|
return {
|
|
63
|
+
artifact,
|
|
54
64
|
data: storeValue.data,
|
|
65
|
+
variables: storeValue.variables,
|
|
55
66
|
fetch: handlers.fetch,
|
|
56
67
|
partial: storeValue.partial,
|
|
57
68
|
loadNext: wrapLoad(setForwardPending, handlers.loadNextPage),
|
|
@@ -69,7 +80,7 @@ function useDocumentHandle({
|
|
|
69
80
|
storeName: artifact.name,
|
|
70
81
|
fetch: fetchQuery,
|
|
71
82
|
fetchUpdate: async (args, updates = ["append"]) => {
|
|
72
|
-
return
|
|
83
|
+
return paginationObserver.send({
|
|
73
84
|
...args,
|
|
74
85
|
cacheParams: {
|
|
75
86
|
disableSubscriptions: true,
|
|
@@ -81,7 +92,9 @@ function useDocumentHandle({
|
|
|
81
92
|
getSession: async () => session
|
|
82
93
|
});
|
|
83
94
|
return {
|
|
95
|
+
artifact,
|
|
84
96
|
data: storeValue.data,
|
|
97
|
+
variables: storeValue.variables,
|
|
85
98
|
fetch: handlers.fetch,
|
|
86
99
|
partial: storeValue.partial,
|
|
87
100
|
loadNext: wrapLoad(setForwardPending, handlers.loadNextPage),
|
|
@@ -89,12 +102,14 @@ function useDocumentHandle({
|
|
|
89
102
|
};
|
|
90
103
|
}
|
|
91
104
|
return {
|
|
105
|
+
artifact,
|
|
92
106
|
data: storeValue.data,
|
|
107
|
+
variables: storeValue.variables,
|
|
93
108
|
fetch: fetchQuery,
|
|
94
109
|
refetch: fetchQuery,
|
|
95
110
|
partial: storeValue.partial
|
|
96
111
|
};
|
|
97
|
-
}, [artifact, observer, session, storeValue
|
|
112
|
+
}, [artifact, observer, session, storeValue]);
|
|
98
113
|
}
|
|
99
114
|
export {
|
|
100
115
|
useDocumentHandle
|
|
@@ -2,7 +2,7 @@ import type { GraphQLObject } from '$houdini/lib/types';
|
|
|
2
2
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
3
3
|
import { RouterCache } from './routing';
|
|
4
4
|
export * from './hooks';
|
|
5
|
-
export { router_cache, useSession, useLocation } from './routing';
|
|
5
|
+
export { router_cache, useSession, useLocation, useRoute } from './routing';
|
|
6
6
|
export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session, assetPrefix, injectToStream, }: {
|
|
7
7
|
initialURL: string;
|
|
8
8
|
initialVariables: GraphQLObject;
|
|
@@ -3,7 +3,7 @@ import client from "./client";
|
|
|
3
3
|
import manifest from "./manifest";
|
|
4
4
|
import { Router as RouterImpl, RouterContextProvider } from "./routing";
|
|
5
5
|
export * from "./hooks";
|
|
6
|
-
import { router_cache, useSession, useLocation } from "./routing";
|
|
6
|
+
import { router_cache, useSession, useLocation, useRoute } from "./routing";
|
|
7
7
|
function Router({
|
|
8
8
|
cache,
|
|
9
9
|
initialURL,
|
|
@@ -43,5 +43,6 @@ export {
|
|
|
43
43
|
Router,
|
|
44
44
|
router_cache,
|
|
45
45
|
useLocation,
|
|
46
|
+
useRoute,
|
|
46
47
|
useSession
|
|
47
48
|
};
|
|
@@ -5,6 +5,7 @@ import { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
|
5
5
|
import { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
6
6
|
import type { RouterManifest } from '$houdini/runtime/router/types';
|
|
7
7
|
import React from 'react';
|
|
8
|
+
import { DocumentHandle } from '../hooks/useDocumentHandle';
|
|
8
9
|
import { SuspenseCache } from './cache';
|
|
9
10
|
type ComponentType = any;
|
|
10
11
|
/**
|
|
@@ -20,6 +21,7 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
20
21
|
}): JSX.Element;
|
|
21
22
|
export declare const useLocation: () => {
|
|
22
23
|
pathname: string;
|
|
24
|
+
params: Record<string, any>;
|
|
23
25
|
};
|
|
24
26
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
25
27
|
children: React.ReactElement;
|
|
@@ -53,7 +55,7 @@ export declare function useCache(): Cache;
|
|
|
53
55
|
export declare function updateLocalSession(session: App.Session): void;
|
|
54
56
|
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
55
57
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
56
|
-
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null,
|
|
58
|
+
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentHandle<any, _Data, _Input>];
|
|
57
59
|
export type RouterCache = {
|
|
58
60
|
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
59
61
|
component_cache: SuspenseCache<(props: any) => React.ReactElement>;
|
|
@@ -69,4 +71,14 @@ export declare function router_cache({ pending_queries, artifacts, components, i
|
|
|
69
71
|
initialVariables?: Record<string, GraphQLVariables>;
|
|
70
72
|
initialArtifacts?: Record<string, QueryArtifact>;
|
|
71
73
|
}): RouterCache;
|
|
74
|
+
export declare function PageContextProvider({ keys, children, }: {
|
|
75
|
+
keys: string[];
|
|
76
|
+
children: React.ReactNode;
|
|
77
|
+
}): JSX.Element;
|
|
78
|
+
export declare function useRoute<PageProps extends {
|
|
79
|
+
Params: {};
|
|
80
|
+
}>(): RouteProp<PageProps['Params']>;
|
|
81
|
+
export type RouteProp<Params> = {
|
|
82
|
+
params: Params;
|
|
83
|
+
};
|
|
72
84
|
export {};
|