houdini-react 0.0.0-20240328033602 → 0.0.0-20240329010223
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 +9 -1
- package/build/plugin-esm/index.js +9 -1
- package/build/runtime/hooks/useDocumentHandle.d.ts +2 -1
- package/build/runtime-cjs/clientPlugin.js +1 -1
- package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +2 -1
- package/build/runtime-cjs/hooks/useDocumentHandle.js +20 -5
- package/build/runtime-cjs/routing/Router.js +5 -6
- package/build/runtime-esm/clientPlugin.js +1 -1
- package/build/runtime-esm/hooks/useDocumentHandle.d.ts +2 -1
- package/build/runtime-esm/hooks/useDocumentHandle.js +21 -6
- package/build/runtime-esm/routing/Router.js +5 -6
- package/package.json +2 -2
|
@@ -78700,7 +78700,6 @@ async function walk_routes(args) {
|
|
|
78700
78700
|
async function add_view(args) {
|
|
78701
78701
|
const target = args.type === "page" ? args.project.pages : args.project.layouts;
|
|
78702
78702
|
const queries = await extractQueries(args.contents);
|
|
78703
|
-
console.log({ queries });
|
|
78704
78703
|
const missing_queries = queries.filter((query2) => !args.queries.includes(query2));
|
|
78705
78704
|
if (missing_queries.length > 0) {
|
|
78706
78705
|
throw {
|
|
@@ -78817,6 +78816,9 @@ async function extractQueries(source) {
|
|
|
78817
78816
|
if (query2.endsWith("$handle")) {
|
|
78818
78817
|
query2 = query2.substring(0, query2.length - "$handle".length);
|
|
78819
78818
|
}
|
|
78819
|
+
if (queries.includes(query2)) {
|
|
78820
|
+
return queries;
|
|
78821
|
+
}
|
|
78820
78822
|
return queries.concat([query2]);
|
|
78821
78823
|
}, []);
|
|
78822
78824
|
}
|
|
@@ -79859,6 +79861,12 @@ var vite_default = {
|
|
|
79859
79861
|
initialVariables: variables,
|
|
79860
79862
|
})
|
|
79861
79863
|
|
|
79864
|
+
// initialize the observer we just created
|
|
79865
|
+
observer.send({
|
|
79866
|
+
setup: true,
|
|
79867
|
+
variables,
|
|
79868
|
+
})
|
|
79869
|
+
|
|
79862
79870
|
// save it in the cache
|
|
79863
79871
|
initialData[artifactName] = observer
|
|
79864
79872
|
initialVariables[artifactName] = variables
|
|
@@ -78690,7 +78690,6 @@ async function walk_routes(args) {
|
|
|
78690
78690
|
async function add_view(args) {
|
|
78691
78691
|
const target = args.type === "page" ? args.project.pages : args.project.layouts;
|
|
78692
78692
|
const queries = await extractQueries(args.contents);
|
|
78693
|
-
console.log({ queries });
|
|
78694
78693
|
const missing_queries = queries.filter((query2) => !args.queries.includes(query2));
|
|
78695
78694
|
if (missing_queries.length > 0) {
|
|
78696
78695
|
throw {
|
|
@@ -78807,6 +78806,9 @@ async function extractQueries(source) {
|
|
|
78807
78806
|
if (query2.endsWith("$handle")) {
|
|
78808
78807
|
query2 = query2.substring(0, query2.length - "$handle".length);
|
|
78809
78808
|
}
|
|
78809
|
+
if (queries.includes(query2)) {
|
|
78810
|
+
return queries;
|
|
78811
|
+
}
|
|
78810
78812
|
return queries.concat([query2]);
|
|
78811
78813
|
}, []);
|
|
78812
78814
|
}
|
|
@@ -79849,6 +79851,12 @@ var vite_default = {
|
|
|
79849
79851
|
initialVariables: variables,
|
|
79850
79852
|
})
|
|
79851
79853
|
|
|
79854
|
+
// initialize the observer we just created
|
|
79855
|
+
observer.send({
|
|
79856
|
+
setup: true,
|
|
79857
|
+
variables,
|
|
79858
|
+
})
|
|
79859
|
+
|
|
79852
79860
|
// save it in the cache
|
|
79853
79861
|
initialData[artifactName] = observer
|
|
79854
79862
|
initialVariables[artifactName] = variables
|
|
@@ -10,7 +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, _Input
|
|
13
|
+
fetch: FetchFn<_Data, Partial<_Input>>;
|
|
14
|
+
variables: _Input;
|
|
14
15
|
} & RefetchHandlers<_Artifact, _Data, _Input>;
|
|
15
16
|
type RefetchHandlers<_Artifact extends QueryArtifact, _Data extends GraphQLObject, _Input> = _Artifact extends {
|
|
16
17
|
refetch: {
|
|
@@ -10,7 +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, _Input
|
|
13
|
+
fetch: FetchFn<_Data, Partial<_Input>>;
|
|
14
|
+
variables: _Input;
|
|
14
15
|
} & RefetchHandlers<_Artifact, _Data, _Input>;
|
|
15
16
|
type RefetchHandlers<_Artifact extends QueryArtifact, _Data extends GraphQLObject, _Input> = _Artifact extends {
|
|
16
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 = {
|
|
@@ -63,7 +63,7 @@ function Router({
|
|
|
63
63
|
const [currentURL, setCurrentURL] = import_react.default.useState(() => {
|
|
64
64
|
return initialURL || window.location.pathname;
|
|
65
65
|
});
|
|
66
|
-
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
67
|
if (!page) {
|
|
68
68
|
throw new Error("404");
|
|
69
69
|
}
|
|
@@ -97,7 +97,7 @@ function Router({
|
|
|
97
97
|
setCurrentURL(val);
|
|
98
98
|
},
|
|
99
99
|
preload(url, which) {
|
|
100
|
-
const [page2, variables2] = (0, import_match.find_match)(manifest, url);
|
|
100
|
+
const [page2, variables2] = (0, import_match.find_match)(import_config.default, manifest, url);
|
|
101
101
|
if (["both", "component"].includes(which)) {
|
|
102
102
|
loadComponent(page2);
|
|
103
103
|
}
|
|
@@ -142,7 +142,6 @@ function usePageData({
|
|
|
142
142
|
reject = rej;
|
|
143
143
|
observer.send({
|
|
144
144
|
variables,
|
|
145
|
-
cacheParams: { disableSubscriptions: true },
|
|
146
145
|
session
|
|
147
146
|
}).then(async () => {
|
|
148
147
|
data_cache.set(id, observer);
|
|
@@ -182,9 +181,10 @@ function usePageData({
|
|
|
182
181
|
config: import_config.default
|
|
183
182
|
})
|
|
184
183
|
)}
|
|
184
|
+
}).then(() => {
|
|
185
|
+
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
185
186
|
})
|
|
186
187
|
|
|
187
|
-
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
|
|
@@ -403,9 +403,8 @@ function useQueryResult(name) {
|
|
|
403
403
|
if (errors && errors.length > 0) {
|
|
404
404
|
throw new Error(JSON.stringify(errors));
|
|
405
405
|
}
|
|
406
|
-
const artifact = artifact_cache.get(name);
|
|
407
406
|
const handle = (0, import_useDocumentHandle.useDocumentHandle)({
|
|
408
|
-
artifact,
|
|
407
|
+
artifact: artifact_cache.get(name),
|
|
409
408
|
observer,
|
|
410
409
|
storeValue
|
|
411
410
|
});
|
|
@@ -10,7 +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, _Input
|
|
13
|
+
fetch: FetchFn<_Data, Partial<_Input>>;
|
|
14
|
+
variables: _Input;
|
|
14
15
|
} & RefetchHandlers<_Artifact, _Data, _Input>;
|
|
15
16
|
type RefetchHandlers<_Artifact extends QueryArtifact, _Data extends GraphQLObject, _Input> = _Artifact extends {
|
|
16
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
|
|
@@ -22,7 +22,7 @@ function Router({
|
|
|
22
22
|
const [currentURL, setCurrentURL] = React.useState(() => {
|
|
23
23
|
return initialURL || window.location.pathname;
|
|
24
24
|
});
|
|
25
|
-
const [page, variables] = find_match(manifest, currentURL);
|
|
25
|
+
const [page, variables] = find_match(configFile, manifest, currentURL);
|
|
26
26
|
if (!page) {
|
|
27
27
|
throw new Error("404");
|
|
28
28
|
}
|
|
@@ -56,7 +56,7 @@ function Router({
|
|
|
56
56
|
setCurrentURL(val);
|
|
57
57
|
},
|
|
58
58
|
preload(url, which) {
|
|
59
|
-
const [page2, variables2] = find_match(manifest, url);
|
|
59
|
+
const [page2, variables2] = find_match(configFile, manifest, url);
|
|
60
60
|
if (["both", "component"].includes(which)) {
|
|
61
61
|
loadComponent(page2);
|
|
62
62
|
}
|
|
@@ -101,7 +101,6 @@ function usePageData({
|
|
|
101
101
|
reject = rej;
|
|
102
102
|
observer.send({
|
|
103
103
|
variables,
|
|
104
|
-
cacheParams: { disableSubscriptions: true },
|
|
105
104
|
session
|
|
106
105
|
}).then(async () => {
|
|
107
106
|
data_cache.set(id, observer);
|
|
@@ -141,9 +140,10 @@ function usePageData({
|
|
|
141
140
|
config: configFile
|
|
142
141
|
})
|
|
143
142
|
)}
|
|
143
|
+
}).then(() => {
|
|
144
|
+
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
144
145
|
})
|
|
145
146
|
|
|
146
|
-
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
|
|
@@ -362,9 +362,8 @@ function useQueryResult(name) {
|
|
|
362
362
|
if (errors && errors.length > 0) {
|
|
363
363
|
throw new Error(JSON.stringify(errors));
|
|
364
364
|
}
|
|
365
|
-
const artifact = artifact_cache.get(name);
|
|
366
365
|
const handle = useDocumentHandle({
|
|
367
|
-
artifact,
|
|
366
|
+
artifact: artifact_cache.get(name),
|
|
368
367
|
observer,
|
|
369
368
|
storeValue
|
|
370
369
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "houdini-react",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20240329010223",
|
|
4
4
|
"description": "The React plugin for houdini",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"recast": "^0.23.1",
|
|
44
44
|
"rollup": "^3.7.4",
|
|
45
45
|
"use-deep-compare-effect": "^1.8.1",
|
|
46
|
-
"houdini": "^0.0.0-
|
|
46
|
+
"houdini": "^0.0.0-20240329010223"
|
|
47
47
|
},
|
|
48
48
|
"files": [
|
|
49
49
|
"build"
|