houdini-react 1.3.7 → 2.0.0-next.0
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/index.d.ts +1 -3
- package/build/plugin/state.d.ts +3 -0
- package/build/plugin/vite.d.ts +1 -44
- package/build/plugin-cjs/index.js +34065 -28140
- package/build/plugin-esm/index.js +32507 -26576
- package/build/runtime/hooks/index.d.ts +1 -1
- package/build/runtime/hooks/useMutation.d.ts +3 -0
- package/build/runtime/routing/Router.d.ts +6 -32
- package/build/runtime/routing/hooks.d.ts +40 -0
- package/build/runtime/routing/index.d.ts +1 -0
- package/build/runtime-cjs/client.js +0 -2
- package/build/runtime-cjs/clientPlugin.js +0 -2
- package/build/runtime-cjs/hooks/index.d.ts +1 -1
- package/build/runtime-cjs/hooks/index.js +2 -2
- package/build/runtime-cjs/hooks/useDeepCompareEffect.js +4 -0
- package/build/runtime-cjs/hooks/useDocumentHandle.js +8 -4
- package/build/runtime-cjs/hooks/useDocumentStore.js +6 -2
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +7 -2
- package/build/runtime-cjs/hooks/useFragment.js +5 -0
- package/build/runtime-cjs/hooks/useMutation.d.ts +3 -0
- package/build/runtime-cjs/hooks/useMutation.js +26 -11
- package/build/runtime-cjs/hooks/useQueryHandle.js +6 -0
- package/build/runtime-cjs/index.js +10 -5
- package/build/runtime-cjs/manifest.js +0 -2
- package/build/runtime-cjs/routing/Router.d.ts +6 -32
- package/build/runtime-cjs/routing/Router.js +22 -65
- package/build/runtime-cjs/routing/cache.js +3 -0
- package/build/runtime-cjs/routing/hooks.d.ts +40 -0
- package/build/runtime-cjs/routing/hooks.js +93 -0
- package/build/runtime-cjs/routing/index.d.ts +1 -0
- package/build/runtime-cjs/routing/index.js +4 -1
- package/build/runtime-esm/hooks/index.d.ts +1 -1
- package/build/runtime-esm/hooks/index.js +2 -3
- package/build/runtime-esm/hooks/useDocumentHandle.js +1 -1
- package/build/runtime-esm/hooks/useDocumentStore.js +1 -1
- package/build/runtime-esm/hooks/useDocumentSubscription.js +2 -1
- package/build/runtime-esm/hooks/useFragment.js +1 -0
- package/build/runtime-esm/hooks/useMutation.d.ts +3 -0
- package/build/runtime-esm/hooks/useMutation.js +24 -10
- package/build/runtime-esm/hooks/useQueryHandle.js +2 -0
- package/build/runtime-esm/routing/Router.d.ts +6 -32
- package/build/runtime-esm/routing/Router.js +10 -52
- package/build/runtime-esm/routing/cache.js +3 -0
- package/build/runtime-esm/routing/hooks.d.ts +40 -0
- package/build/runtime-esm/routing/hooks.js +53 -0
- package/build/runtime-esm/routing/index.d.ts +1 -0
- package/build/runtime-esm/routing/index.js +1 -0
- package/build/server-cjs/index.js +3 -3
- package/package.json +4 -4
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -29,14 +33,9 @@ __export(Router_exports, {
|
|
|
29
33
|
RouterContextProvider: () => RouterContextProvider,
|
|
30
34
|
router_cache: () => router_cache,
|
|
31
35
|
updateLocalSession: () => updateLocalSession,
|
|
32
|
-
useCache: () => useCache,
|
|
33
|
-
useClient: () => useClient,
|
|
34
36
|
useCurrentVariables: () => useCurrentVariables,
|
|
35
|
-
useLocation: () => useLocation,
|
|
36
37
|
useQueryResult: () => useQueryResult,
|
|
37
|
-
useRoute: () => useRoute
|
|
38
|
-
useRouterContext: () => useRouterContext,
|
|
39
|
-
useSession: () => useSession
|
|
38
|
+
useRoute: () => useRoute
|
|
40
39
|
});
|
|
41
40
|
module.exports = __toCommonJS(Router_exports);
|
|
42
41
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -46,9 +45,10 @@ var import_scalars = require("$houdini/runtime/lib/scalars");
|
|
|
46
45
|
var import_match = require("$houdini/runtime/router/match");
|
|
47
46
|
var import_react = __toESM(require("react"));
|
|
48
47
|
var import_react2 = require("react");
|
|
48
|
+
var import_cache = require("./cache");
|
|
49
49
|
var import_useDocumentHandle = require("../hooks/useDocumentHandle");
|
|
50
50
|
var import_useDocumentStore = require("../hooks/useDocumentStore");
|
|
51
|
-
var
|
|
51
|
+
var import_hooks = require("./hooks");
|
|
52
52
|
const PreloadWhich = {
|
|
53
53
|
component: "component",
|
|
54
54
|
data: "data",
|
|
@@ -73,7 +73,7 @@ function Router({
|
|
|
73
73
|
assetPrefix,
|
|
74
74
|
injectToStream
|
|
75
75
|
});
|
|
76
|
-
const { component_cache, data_cache } = useRouterContext();
|
|
76
|
+
const { component_cache, data_cache } = (0, import_hooks.useRouterContext)();
|
|
77
77
|
const PageComponent = component_cache.get(page.id);
|
|
78
78
|
import_react.default.useEffect(() => {
|
|
79
79
|
if (globalThis.window && window.location.pathname !== currentURL) {
|
|
@@ -112,7 +112,7 @@ function Router({
|
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
114
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
115
|
-
LocationContext.Provider,
|
|
115
|
+
import_hooks.LocationContext.Provider,
|
|
116
116
|
{
|
|
117
117
|
value: {
|
|
118
118
|
pathname: currentURL,
|
|
@@ -123,7 +123,6 @@ function Router({
|
|
|
123
123
|
}
|
|
124
124
|
) });
|
|
125
125
|
}
|
|
126
|
-
const useLocation = () => (0, import_react2.useContext)(LocationContext);
|
|
127
126
|
function usePageData({
|
|
128
127
|
page,
|
|
129
128
|
variables,
|
|
@@ -138,8 +137,8 @@ function usePageData({
|
|
|
138
137
|
artifact_cache,
|
|
139
138
|
ssr_signals,
|
|
140
139
|
last_variables
|
|
141
|
-
} = useRouterContext();
|
|
142
|
-
const [session] = useSession();
|
|
140
|
+
} = (0, import_hooks.useRouterContext)();
|
|
141
|
+
const [session] = (0, import_hooks.useSession)();
|
|
143
142
|
function load_query({
|
|
144
143
|
id,
|
|
145
144
|
artifact,
|
|
@@ -250,7 +249,7 @@ function usePageData({
|
|
|
250
249
|
window.__houdini__nav_caches__.ssr_signals.delete(artifactName)
|
|
251
250
|
}
|
|
252
251
|
}
|
|
253
|
-
|
|
252
|
+
</script>
|
|
254
253
|
`);
|
|
255
254
|
resolve();
|
|
256
255
|
}).catch(reject);
|
|
@@ -295,7 +294,7 @@ function usePageData({
|
|
|
295
294
|
const artifact = mod.default;
|
|
296
295
|
artifact_cache.set(artifact_id, artifact);
|
|
297
296
|
injectToStream?.(`
|
|
298
|
-
<script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""
|
|
297
|
+
<script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""></script>
|
|
299
298
|
`);
|
|
300
299
|
load_query({ id: artifact.name, artifact, variables: variables2 });
|
|
301
300
|
}).catch((err) => {
|
|
@@ -346,7 +345,7 @@ function RouterContextProvider({
|
|
|
346
345
|
};
|
|
347
346
|
}, []);
|
|
348
347
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
349
|
-
Context.Provider,
|
|
348
|
+
import_hooks.Context.Provider,
|
|
350
349
|
{
|
|
351
350
|
value: {
|
|
352
351
|
client,
|
|
@@ -363,20 +362,6 @@ function RouterContextProvider({
|
|
|
363
362
|
}
|
|
364
363
|
);
|
|
365
364
|
}
|
|
366
|
-
const Context = import_react.default.createContext(null);
|
|
367
|
-
const useRouterContext = () => {
|
|
368
|
-
const ctx = import_react.default.useContext(Context);
|
|
369
|
-
if (!ctx) {
|
|
370
|
-
throw new Error("Could not find router context");
|
|
371
|
-
}
|
|
372
|
-
return ctx;
|
|
373
|
-
};
|
|
374
|
-
function useClient() {
|
|
375
|
-
return useRouterContext().client;
|
|
376
|
-
}
|
|
377
|
-
function useCache() {
|
|
378
|
-
return useRouterContext().cache;
|
|
379
|
-
}
|
|
380
365
|
function updateLocalSession(session) {
|
|
381
366
|
window.dispatchEvent(
|
|
382
367
|
new CustomEvent("_houdini_session_", {
|
|
@@ -385,39 +370,12 @@ function updateLocalSession(session) {
|
|
|
385
370
|
})
|
|
386
371
|
);
|
|
387
372
|
}
|
|
388
|
-
function useSession() {
|
|
389
|
-
const ctx = useRouterContext();
|
|
390
|
-
const updateSession = (newSession) => {
|
|
391
|
-
ctx.data_cache.clear();
|
|
392
|
-
ctx.setSession(newSession);
|
|
393
|
-
const auth = import_config.default.router?.auth;
|
|
394
|
-
if (!auth) {
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
const url = "redirect" in auth ? auth.redirect : auth.url;
|
|
398
|
-
fetch(url, {
|
|
399
|
-
method: "POST",
|
|
400
|
-
body: JSON.stringify(newSession),
|
|
401
|
-
headers: {
|
|
402
|
-
"Content-Type": "application/json",
|
|
403
|
-
Accept: "application/json"
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
|
-
return [ctx.session, updateSession];
|
|
408
|
-
}
|
|
409
373
|
function useCurrentVariables() {
|
|
410
374
|
return import_react.default.useContext(VariableContext);
|
|
411
375
|
}
|
|
412
376
|
const VariableContext = import_react.default.createContext(null);
|
|
413
|
-
const LocationContext = import_react.default.createContext({
|
|
414
|
-
pathname: "",
|
|
415
|
-
params: {},
|
|
416
|
-
goto: () => {
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
377
|
function useQueryResult(name) {
|
|
420
|
-
const { data_cache, artifact_cache } = useRouterContext();
|
|
378
|
+
const { data_cache, artifact_cache } = (0, import_hooks.useRouterContext)();
|
|
421
379
|
const store_ref = data_cache.get(name);
|
|
422
380
|
const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({
|
|
423
381
|
artifact: store_ref.artifact,
|
|
@@ -451,7 +409,11 @@ function useLinkNavigation({ goto }) {
|
|
|
451
409
|
return;
|
|
452
410
|
}
|
|
453
411
|
const link = e.target?.closest("a");
|
|
454
|
-
if (!(link && link instanceof HTMLAnchorElement && link.href && (!link.target || link.target === "_self") && link.origin === location.origin && !link.hasAttribute("download") && e.button === 0 &&
|
|
412
|
+
if (!(link && link instanceof HTMLAnchorElement && link.href && (!link.target || link.target === "_self") && link.origin === location.origin && !link.hasAttribute("download") && e.button === 0 && // left clicks only
|
|
413
|
+
!e.metaKey && // open in new tab (mac)
|
|
414
|
+
!e.ctrlKey && // open in new tab (windows)
|
|
415
|
+
!e.altKey && // download
|
|
416
|
+
!e.shiftKey && !e.defaultPrevented)) {
|
|
455
417
|
return;
|
|
456
418
|
}
|
|
457
419
|
const target = link.attributes.getNamedItem("href")?.value;
|
|
@@ -541,7 +503,7 @@ function PageContextProvider({
|
|
|
541
503
|
keys,
|
|
542
504
|
children
|
|
543
505
|
}) {
|
|
544
|
-
const location2 = useLocation();
|
|
506
|
+
const location2 = (0, import_hooks.useLocation)();
|
|
545
507
|
const params = Object.fromEntries(
|
|
546
508
|
Object.entries(location2.params).filter(([key]) => keys.includes(key))
|
|
547
509
|
);
|
|
@@ -572,12 +534,7 @@ function signal_promise() {
|
|
|
572
534
|
RouterContextProvider,
|
|
573
535
|
router_cache,
|
|
574
536
|
updateLocalSession,
|
|
575
|
-
useCache,
|
|
576
|
-
useClient,
|
|
577
537
|
useCurrentVariables,
|
|
578
|
-
useLocation,
|
|
579
538
|
useQueryResult,
|
|
580
|
-
useRoute
|
|
581
|
-
useRouterContext,
|
|
582
|
-
useSession
|
|
539
|
+
useRoute
|
|
583
540
|
});
|
|
@@ -31,6 +31,8 @@ function suspense_cache(initialData) {
|
|
|
31
31
|
return cache;
|
|
32
32
|
}
|
|
33
33
|
class SuspenseCache extends import_lru.LRUCache {
|
|
34
|
+
// if get is called before set, we need to invoke a callback.
|
|
35
|
+
// that means we need a place to put our callbacks
|
|
34
36
|
#callbacks = /* @__PURE__ */ new Map();
|
|
35
37
|
get(key) {
|
|
36
38
|
if (super.has(key)) {
|
|
@@ -40,6 +42,7 @@ class SuspenseCache extends import_lru.LRUCache {
|
|
|
40
42
|
this.#subscribe(key, resolve, reject);
|
|
41
43
|
});
|
|
42
44
|
}
|
|
45
|
+
// TODO: reject?
|
|
43
46
|
set(key, value) {
|
|
44
47
|
super.set(key, value);
|
|
45
48
|
if (this.#callbacks.has(key)) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
2
|
+
import type { DocumentStore, HoudiniClient } from '$houdini/runtime/client';
|
|
3
|
+
import type { LRUCache } from '$houdini/runtime/lib/lru';
|
|
4
|
+
import type { GraphQLObject, GraphQLVariables, QueryArtifact } from '$houdini/runtime/lib/types';
|
|
5
|
+
import { default as React } from 'react';
|
|
6
|
+
import type { SuspenseCache } from './cache';
|
|
7
|
+
export type PageComponent = React.ComponentType<{
|
|
8
|
+
url: string;
|
|
9
|
+
}>;
|
|
10
|
+
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
11
|
+
resolve: () => void;
|
|
12
|
+
reject: (message: string) => void;
|
|
13
|
+
}>;
|
|
14
|
+
type RouterContext = {
|
|
15
|
+
client: HoudiniClient;
|
|
16
|
+
cache: Cache;
|
|
17
|
+
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
18
|
+
component_cache: SuspenseCache<PageComponent>;
|
|
19
|
+
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
20
|
+
ssr_signals: PendingCache;
|
|
21
|
+
last_variables: LRUCache<GraphQLVariables>;
|
|
22
|
+
session: App.Session;
|
|
23
|
+
setSession: (newSession: Partial<App.Session>) => void;
|
|
24
|
+
};
|
|
25
|
+
export declare const Context: React.Context<RouterContext | null>;
|
|
26
|
+
export declare const LocationContext: React.Context<{
|
|
27
|
+
pathname: string;
|
|
28
|
+
params: Record<string, any>;
|
|
29
|
+
goto: (url: string) => void;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const useLocation: () => {
|
|
32
|
+
pathname: string;
|
|
33
|
+
params: Record<string, any>;
|
|
34
|
+
goto: (url: string) => void;
|
|
35
|
+
};
|
|
36
|
+
export declare const useRouterContext: () => RouterContext;
|
|
37
|
+
export declare function useClient(): HoudiniClient;
|
|
38
|
+
export declare function useCache(): Cache;
|
|
39
|
+
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var hooks_exports = {};
|
|
30
|
+
__export(hooks_exports, {
|
|
31
|
+
Context: () => Context,
|
|
32
|
+
LocationContext: () => LocationContext,
|
|
33
|
+
useCache: () => useCache,
|
|
34
|
+
useClient: () => useClient,
|
|
35
|
+
useLocation: () => useLocation,
|
|
36
|
+
useRouterContext: () => useRouterContext,
|
|
37
|
+
useSession: () => useSession
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
40
|
+
var import_config = __toESM(require("$houdini/runtime/imports/config"));
|
|
41
|
+
var import_react = __toESM(require("react"));
|
|
42
|
+
const Context = import_react.default.createContext(null);
|
|
43
|
+
const LocationContext = import_react.default.createContext({
|
|
44
|
+
pathname: "",
|
|
45
|
+
params: {},
|
|
46
|
+
goto: () => {
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const useLocation = () => (0, import_react.useContext)(LocationContext);
|
|
50
|
+
const useRouterContext = () => {
|
|
51
|
+
const ctx = import_react.default.useContext(Context);
|
|
52
|
+
if (!ctx) {
|
|
53
|
+
throw new Error("Could not find router context");
|
|
54
|
+
}
|
|
55
|
+
return ctx;
|
|
56
|
+
};
|
|
57
|
+
function useClient() {
|
|
58
|
+
return useRouterContext().client;
|
|
59
|
+
}
|
|
60
|
+
function useCache() {
|
|
61
|
+
return useRouterContext().cache;
|
|
62
|
+
}
|
|
63
|
+
function useSession() {
|
|
64
|
+
const ctx = useRouterContext();
|
|
65
|
+
const updateSession = (newSession) => {
|
|
66
|
+
ctx.data_cache.clear();
|
|
67
|
+
ctx.setSession(newSession);
|
|
68
|
+
const auth = import_config.default.router?.auth;
|
|
69
|
+
if (!auth) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const url = "redirect" in auth ? auth.redirect : auth.url;
|
|
73
|
+
fetch(url, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
body: JSON.stringify(newSession),
|
|
76
|
+
headers: {
|
|
77
|
+
"Content-Type": "application/json",
|
|
78
|
+
Accept: "application/json"
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
return [ctx.session, updateSession];
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
Context,
|
|
87
|
+
LocationContext,
|
|
88
|
+
useCache,
|
|
89
|
+
useClient,
|
|
90
|
+
useLocation,
|
|
91
|
+
useRouterContext,
|
|
92
|
+
useSession
|
|
93
|
+
});
|
|
@@ -23,8 +23,11 @@ __export(routing_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(routing_exports);
|
|
25
25
|
__reExport(routing_exports, require("./Router"), module.exports);
|
|
26
|
+
__reExport(routing_exports, require("./hooks"), module.exports);
|
|
26
27
|
var import_cache = require("./cache");
|
|
27
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
29
|
0 && (module.exports = {
|
|
29
|
-
suspense_cache
|
|
30
|
+
suspense_cache,
|
|
31
|
+
...require("./Router"),
|
|
32
|
+
...require("./hooks")
|
|
30
33
|
});
|
|
@@ -2,7 +2,7 @@ export { useQuery } from './useQuery';
|
|
|
2
2
|
export { useQueryHandle } from './useQueryHandle';
|
|
3
3
|
export { useFragment } from './useFragment';
|
|
4
4
|
export { useFragmentHandle } from './useFragmentHandle';
|
|
5
|
-
export { useMutation } from './useMutation';
|
|
5
|
+
export { useMutation, RuntimeGraphQLError } from './useMutation';
|
|
6
6
|
export { useSubscription } from './useSubscription';
|
|
7
7
|
export { type DocumentHandle } from './useDocumentHandle';
|
|
8
8
|
export { type UseQueryConfig } from './useQueryHandle';
|
|
@@ -2,11 +2,10 @@ import { useQuery } from "./useQuery";
|
|
|
2
2
|
import { useQueryHandle } from "./useQueryHandle";
|
|
3
3
|
import { useFragment } from "./useFragment";
|
|
4
4
|
import { useFragmentHandle } from "./useFragmentHandle";
|
|
5
|
-
import { useMutation } from "./useMutation";
|
|
5
|
+
import { useMutation, RuntimeGraphQLError } from "./useMutation";
|
|
6
6
|
import { useSubscription } from "./useSubscription";
|
|
7
|
-
import {} from "./useDocumentHandle";
|
|
8
|
-
import {} from "./useQueryHandle";
|
|
9
7
|
export {
|
|
8
|
+
RuntimeGraphQLError,
|
|
10
9
|
useFragment,
|
|
11
10
|
useFragmentHandle,
|
|
12
11
|
useMutation,
|
|
@@ -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 { useClient,
|
|
5
|
+
import { useClient, useSession, useLocation } from "../routing/hooks";
|
|
6
6
|
function useDocumentHandle({
|
|
7
7
|
artifact,
|
|
8
8
|
observer,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useSession } from "../routing/
|
|
1
|
+
import { useSession } from "../routing/hooks";
|
|
2
2
|
import useDeepCompareEffect from "./useDeepCompareEffect";
|
|
3
3
|
import { useDocumentStore } from "./useDocumentStore";
|
|
4
4
|
function useDocumentSubscription({
|
|
@@ -18,6 +18,7 @@ function useDocumentSubscription({
|
|
|
18
18
|
observer.send({
|
|
19
19
|
variables,
|
|
20
20
|
session,
|
|
21
|
+
// TODO: metadata
|
|
21
22
|
metadata: {},
|
|
22
23
|
...send
|
|
23
24
|
});
|
|
@@ -9,3 +9,6 @@ export type MutationHandler<_Result, _Input, _Optimistic extends GraphQLObject>
|
|
|
9
9
|
export declare function useMutation<_Result extends GraphQLObject, _Input extends GraphQLVariables, _Optimistic extends GraphQLObject>({ artifact, }: {
|
|
10
10
|
artifact: MutationArtifact;
|
|
11
11
|
}): [boolean, MutationHandler<_Result, _Input, _Optimistic>];
|
|
12
|
+
export declare class RuntimeGraphQLError extends Error {
|
|
13
|
+
raw: QueryResult['errors'];
|
|
14
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useSession } from "../routing/
|
|
1
|
+
import { useSession } from "../routing/hooks";
|
|
2
2
|
import { useDocumentStore } from "./useDocumentStore";
|
|
3
3
|
function useMutation({
|
|
4
4
|
artifact
|
|
@@ -6,23 +6,37 @@ function useMutation({
|
|
|
6
6
|
const [storeValue, observer] = useDocumentStore({ artifact });
|
|
7
7
|
const pending = storeValue.fetching;
|
|
8
8
|
const [session] = useSession();
|
|
9
|
-
const mutate = ({
|
|
9
|
+
const mutate = async ({
|
|
10
10
|
metadata,
|
|
11
11
|
fetch,
|
|
12
12
|
variables,
|
|
13
13
|
abortController,
|
|
14
14
|
...mutationConfig
|
|
15
|
-
}) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
}) => {
|
|
16
|
+
const result = await observer.send({
|
|
17
|
+
variables,
|
|
18
|
+
metadata,
|
|
19
|
+
session,
|
|
20
|
+
abortController,
|
|
21
|
+
stuff: {
|
|
22
|
+
...mutationConfig
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (result.errors && result.errors?.length > 0) {
|
|
26
|
+
const err = new RuntimeGraphQLError(
|
|
27
|
+
result.errors.map((error) => error.message).join(". ")
|
|
28
|
+
);
|
|
29
|
+
err.raw = result.errors;
|
|
30
|
+
throw err;
|
|
22
31
|
}
|
|
23
|
-
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
24
34
|
return [pending, mutate];
|
|
25
35
|
}
|
|
36
|
+
class RuntimeGraphQLError extends Error {
|
|
37
|
+
raw = [];
|
|
38
|
+
}
|
|
26
39
|
export {
|
|
40
|
+
RuntimeGraphQLError,
|
|
27
41
|
useMutation
|
|
28
42
|
};
|
|
@@ -52,11 +52,13 @@ function useQueryHandle({ artifact }, variables = null, config = {}) {
|
|
|
52
52
|
const suspenseUnit = {
|
|
53
53
|
then: loadPromise.then.bind(loadPromise),
|
|
54
54
|
resolve,
|
|
55
|
+
// @ts-ignore
|
|
55
56
|
variables
|
|
56
57
|
};
|
|
57
58
|
promiseCache.set(identifier, suspenseUnit);
|
|
58
59
|
handle.fetch({
|
|
59
60
|
variables,
|
|
61
|
+
// @ts-ignore: this is actually allowed... 🤫
|
|
60
62
|
stuff: {
|
|
61
63
|
silenceLoading: true
|
|
62
64
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
2
2
|
import { DocumentStore, HoudiniClient } from '$houdini/runtime/client';
|
|
3
|
-
import { LRUCache } from '$houdini/runtime/lib/lru';
|
|
4
|
-
import { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
5
|
-
import { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
3
|
+
import type { LRUCache } from '$houdini/runtime/lib/lru';
|
|
4
|
+
import type { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
5
|
+
import type { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
6
6
|
import type { RouterManifest } from '$houdini/runtime/router/types';
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
type PageComponent
|
|
11
|
-
url: string;
|
|
12
|
-
}>;
|
|
8
|
+
import { type SuspenseCache } from './cache';
|
|
9
|
+
import { type DocumentHandle } from '../hooks/useDocumentHandle';
|
|
10
|
+
import { type PageComponent, type PendingCache } from './hooks';
|
|
13
11
|
type ComponentType = any;
|
|
14
12
|
/**
|
|
15
13
|
* Router is the top level entry point for the filesystem-based router.
|
|
@@ -22,11 +20,6 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
22
20
|
assetPrefix: string;
|
|
23
21
|
injectToStream?: undefined | ((chunk: string) => void);
|
|
24
22
|
}): React.JSX.Element;
|
|
25
|
-
export declare const useLocation: () => {
|
|
26
|
-
pathname: string;
|
|
27
|
-
params: Record<string, any>;
|
|
28
|
-
goto: (url: string) => void;
|
|
29
|
-
};
|
|
30
23
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
31
24
|
children: React.ReactNode;
|
|
32
25
|
client: HoudiniClient;
|
|
@@ -38,26 +31,7 @@ export declare function RouterContextProvider({ children, client, cache, artifac
|
|
|
38
31
|
last_variables: LRUCache<GraphQLVariables>;
|
|
39
32
|
session?: App.Session;
|
|
40
33
|
}): React.JSX.Element;
|
|
41
|
-
type RouterContext = {
|
|
42
|
-
client: HoudiniClient;
|
|
43
|
-
cache: Cache;
|
|
44
|
-
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
45
|
-
component_cache: SuspenseCache<PageComponent>;
|
|
46
|
-
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
47
|
-
ssr_signals: PendingCache;
|
|
48
|
-
last_variables: LRUCache<GraphQLVariables>;
|
|
49
|
-
session: App.Session;
|
|
50
|
-
setSession: (newSession: Partial<App.Session>) => void;
|
|
51
|
-
};
|
|
52
|
-
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
53
|
-
resolve: () => void;
|
|
54
|
-
reject: (message: string) => void;
|
|
55
|
-
}>;
|
|
56
|
-
export declare const useRouterContext: () => RouterContext;
|
|
57
|
-
export declare function useClient(): HoudiniClient;
|
|
58
|
-
export declare function useCache(): Cache;
|
|
59
34
|
export declare function updateLocalSession(session: App.Session): void;
|
|
60
|
-
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
61
35
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
62
36
|
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentHandle<any, _Data, _Input>];
|
|
63
37
|
export type RouterCache = {
|