houdini-react 1.2.42 → 1.2.44

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.
@@ -77847,8 +77847,22 @@ var query = documentPlugin(ArtifactKind.Query, function() {
77847
77847
  let lastVariables = null;
77848
77848
  return {
77849
77849
  start(ctx, { next }) {
77850
+ const runtimeScalarPayload = {
77851
+ session: ctx.session
77852
+ };
77850
77853
  ctx.variables = {
77851
77854
  ...lastVariables,
77855
+ ...Object.fromEntries(
77856
+ Object.entries(ctx.artifact.input?.runtimeScalars ?? {}).map(
77857
+ ([field, type]) => {
77858
+ const runtimeScalar = ctx.config.features?.runtimeScalars?.[type];
77859
+ if (!runtimeScalar) {
77860
+ return [field, type];
77861
+ }
77862
+ return [field, runtimeScalar.resolve(runtimeScalarPayload)];
77863
+ }
77864
+ )
77865
+ ),
77852
77866
  ...ctx.variables
77853
77867
  };
77854
77868
  next(ctx);
@@ -79464,7 +79478,8 @@ async function writeTsconfig(config) {
79464
79478
  "../src/**/*.js",
79465
79479
  "../src/**/*.ts",
79466
79480
  "../src/**/*.jsx",
79467
- "../src/**/*.tsx"
79481
+ "../src/**/*.tsx",
79482
+ "../src/+app.d.ts"
79468
79483
  ],
79469
79484
  exclude: ["../node_modules/**", "./[!ambient.d.ts]**"]
79470
79485
  },
@@ -79931,37 +79946,42 @@ if (window.__houdini__nav_caches__ && window.__houdini__nav_caches__.artifact_ca
79931
79946
  for (const [key, value] of Object.entries(req.headers)) {
79932
79947
  request.headers.set(key, value);
79933
79948
  }
79934
- const result = await createServerAdapter({
79935
- production: false,
79936
- manifest: router_manifest,
79937
- assetPrefix: "/virtual:houdini",
79938
- pipe: res,
79939
- documentPremable: `<script type="module" src="/@vite/client" async=""><\/script>`
79940
- })(request);
79941
- if (result && result.status === 404) {
79942
- return next();
79943
- }
79944
- if (result && typeof result !== "boolean") {
79945
- if (res.closed) {
79946
- return;
79947
- }
79948
- for (const header of Object.entries(result.headers ?? {})) {
79949
- res.setHeader(header[0], header[1]);
79950
- }
79951
- if (result.status >= 300 && result.status < 400) {
79952
- res.writeHead(result.status, {
79953
- Location: result.headers.get("Location") ?? "",
79954
- ...[...result.headers.entries()].reduce(
79955
- (headers, [key, value]) => ({
79956
- ...headers,
79957
- [key]: value
79958
- }),
79959
- {}
79960
- )
79961
- });
79962
- } else {
79963
- res.write(await result.text());
79949
+ try {
79950
+ const result = await createServerAdapter({
79951
+ production: false,
79952
+ manifest: router_manifest,
79953
+ assetPrefix: "/virtual:houdini",
79954
+ pipe: res,
79955
+ documentPremable: `<script type="module" src="/@vite/client" async=""><\/script>`
79956
+ })(request);
79957
+ if (result && result.status === 404) {
79958
+ return next();
79959
+ }
79960
+ if (result && typeof result !== "boolean") {
79961
+ if (res.closed) {
79962
+ return;
79963
+ }
79964
+ for (const header of result.headers ?? []) {
79965
+ res.setHeader(header[0], header[1]);
79966
+ }
79967
+ if (result.status >= 300 && result.status < 400) {
79968
+ res.writeHead(result.status, {
79969
+ Location: result.headers.get("Location") ?? "",
79970
+ ...[...result.headers].reduce(
79971
+ (headers, [key, value]) => ({
79972
+ ...headers,
79973
+ [key]: value
79974
+ }),
79975
+ {}
79976
+ )
79977
+ });
79978
+ } else {
79979
+ res.write(await result.text());
79980
+ }
79981
+ res.end();
79964
79982
  }
79983
+ } catch (e2) {
79984
+ console.error(e2);
79965
79985
  res.end();
79966
79986
  }
79967
79987
  });
@@ -77837,8 +77837,22 @@ var query = documentPlugin(ArtifactKind.Query, function() {
77837
77837
  let lastVariables = null;
77838
77838
  return {
77839
77839
  start(ctx, { next }) {
77840
+ const runtimeScalarPayload = {
77841
+ session: ctx.session
77842
+ };
77840
77843
  ctx.variables = {
77841
77844
  ...lastVariables,
77845
+ ...Object.fromEntries(
77846
+ Object.entries(ctx.artifact.input?.runtimeScalars ?? {}).map(
77847
+ ([field, type]) => {
77848
+ const runtimeScalar = ctx.config.features?.runtimeScalars?.[type];
77849
+ if (!runtimeScalar) {
77850
+ return [field, type];
77851
+ }
77852
+ return [field, runtimeScalar.resolve(runtimeScalarPayload)];
77853
+ }
77854
+ )
77855
+ ),
77842
77856
  ...ctx.variables
77843
77857
  };
77844
77858
  next(ctx);
@@ -79454,7 +79468,8 @@ async function writeTsconfig(config) {
79454
79468
  "../src/**/*.js",
79455
79469
  "../src/**/*.ts",
79456
79470
  "../src/**/*.jsx",
79457
- "../src/**/*.tsx"
79471
+ "../src/**/*.tsx",
79472
+ "../src/+app.d.ts"
79458
79473
  ],
79459
79474
  exclude: ["../node_modules/**", "./[!ambient.d.ts]**"]
79460
79475
  },
@@ -79921,37 +79936,42 @@ if (window.__houdini__nav_caches__ && window.__houdini__nav_caches__.artifact_ca
79921
79936
  for (const [key, value] of Object.entries(req.headers)) {
79922
79937
  request.headers.set(key, value);
79923
79938
  }
79924
- const result = await createServerAdapter({
79925
- production: false,
79926
- manifest: router_manifest,
79927
- assetPrefix: "/virtual:houdini",
79928
- pipe: res,
79929
- documentPremable: `<script type="module" src="/@vite/client" async=""><\/script>`
79930
- })(request);
79931
- if (result && result.status === 404) {
79932
- return next();
79933
- }
79934
- if (result && typeof result !== "boolean") {
79935
- if (res.closed) {
79936
- return;
79937
- }
79938
- for (const header of Object.entries(result.headers ?? {})) {
79939
- res.setHeader(header[0], header[1]);
79940
- }
79941
- if (result.status >= 300 && result.status < 400) {
79942
- res.writeHead(result.status, {
79943
- Location: result.headers.get("Location") ?? "",
79944
- ...[...result.headers.entries()].reduce(
79945
- (headers, [key, value]) => ({
79946
- ...headers,
79947
- [key]: value
79948
- }),
79949
- {}
79950
- )
79951
- });
79952
- } else {
79953
- res.write(await result.text());
79939
+ try {
79940
+ const result = await createServerAdapter({
79941
+ production: false,
79942
+ manifest: router_manifest,
79943
+ assetPrefix: "/virtual:houdini",
79944
+ pipe: res,
79945
+ documentPremable: `<script type="module" src="/@vite/client" async=""><\/script>`
79946
+ })(request);
79947
+ if (result && result.status === 404) {
79948
+ return next();
79949
+ }
79950
+ if (result && typeof result !== "boolean") {
79951
+ if (res.closed) {
79952
+ return;
79953
+ }
79954
+ for (const header of result.headers ?? []) {
79955
+ res.setHeader(header[0], header[1]);
79956
+ }
79957
+ if (result.status >= 300 && result.status < 400) {
79958
+ res.writeHead(result.status, {
79959
+ Location: result.headers.get("Location") ?? "",
79960
+ ...[...result.headers].reduce(
79961
+ (headers, [key, value]) => ({
79962
+ ...headers,
79963
+ [key]: value
79964
+ }),
79965
+ {}
79966
+ )
79967
+ });
79968
+ } else {
79969
+ res.write(await result.text());
79970
+ }
79971
+ res.end();
79954
79972
  }
79973
+ } catch (e2) {
79974
+ console.error(e2);
79955
79975
  res.end();
79956
79976
  }
79957
79977
  });
@@ -7,6 +7,5 @@ export type UseDocumentStoreParams<_Artifact extends DocumentArtifact, _Data ext
7
7
  } & Partial<ObserveParams<_Data, DocumentArtifact, _Input>>;
8
8
  export declare function useDocumentStore<_Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables, _Artifact extends DocumentArtifact = DocumentArtifact>({ artifact, observer: obs, ...observeParams }: UseDocumentStoreParams<_Artifact, _Data, _Input>): [
9
9
  QueryResult<_Data, _Input>,
10
- DocumentStore<_Data, _Input>,
11
- (store: DocumentStore<_Data, _Input>) => void
10
+ DocumentStore<_Data, _Input>
12
11
  ];
@@ -6,10 +6,6 @@ export declare function useDocumentSubscription<_Artifact extends DocumentArtifa
6
6
  variables: _Input;
7
7
  disabled?: boolean;
8
8
  send?: Partial<SendParams>;
9
- }): [
10
- QueryResult<_Data, _Input> & {
11
- parent?: string | null;
12
- },
13
- DocumentStore<_Data, _Input>,
14
- (store: DocumentStore<_Data, _Input>) => void
15
- ];
9
+ }): [QueryResult<_Data, _Input> & {
10
+ parent?: string | null;
11
+ }, DocumentStore<_Data, _Input>];
@@ -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 } from './routing';
5
+ export { router_cache, useSession, useLocation } 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;
@@ -18,6 +18,9 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
18
18
  assetPrefix: string;
19
19
  injectToStream?: undefined | ((chunk: string) => void);
20
20
  }): JSX.Element;
21
+ export declare const useLocation: () => {
22
+ pathname: string;
23
+ };
21
24
  export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
22
25
  children: React.ReactElement;
23
26
  client: HoudiniClient;
@@ -38,6 +41,7 @@ type RouterContext = {
38
41
  ssr_signals: PendingCache;
39
42
  last_variables: LRUCache<GraphQLVariables>;
40
43
  session: App.Session;
44
+ setSession: (newSession: Partial<App.Session>) => void;
41
45
  };
42
46
  export type PendingCache = SuspenseCache<Promise<void> & {
43
47
  resolve: () => void;
@@ -47,7 +51,7 @@ export declare const useRouterContext: () => RouterContext;
47
51
  export declare function useClient(): HoudiniClient;
48
52
  export declare function useCache(): Cache;
49
53
  export declare function updateLocalSession(session: App.Session): void;
50
- export declare function useSession(): App.Session;
54
+ export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
51
55
  export declare function useCurrentVariables(): GraphQLVariables;
52
56
  export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
53
57
  export type RouterCache = {
@@ -39,7 +39,7 @@ function useDocumentHandle({
39
39
  }) {
40
40
  const [forwardPending, setForwardPending] = import_react.default.useState(false);
41
41
  const [backwardPending, setBackwardPending] = import_react.default.useState(false);
42
- const session = (0, import_Router.useSession)();
42
+ const [session] = (0, import_Router.useSession)();
43
43
  return import_react.default.useMemo(() => {
44
44
  const wrapLoad = (setLoading, fn) => {
45
45
  return async (value) => {
@@ -7,6 +7,5 @@ export type UseDocumentStoreParams<_Artifact extends DocumentArtifact, _Data ext
7
7
  } & Partial<ObserveParams<_Data, DocumentArtifact, _Input>>;
8
8
  export declare function useDocumentStore<_Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables, _Artifact extends DocumentArtifact = DocumentArtifact>({ artifact, observer: obs, ...observeParams }: UseDocumentStoreParams<_Artifact, _Data, _Input>): [
9
9
  QueryResult<_Data, _Input>,
10
- DocumentStore<_Data, _Input>,
11
- (store: DocumentStore<_Data, _Input>) => void
10
+ DocumentStore<_Data, _Input>
12
11
  ];
@@ -44,6 +44,10 @@ function useDocumentStore({
44
44
  })
45
45
  );
46
46
  const box = React.useRef(observer.state);
47
+ if (obs && obs !== observer) {
48
+ box.current = obs.state;
49
+ setObserver(obs);
50
+ }
47
51
  const subscribe = React.useCallback(
48
52
  (fn) => {
49
53
  return observer.subscribe((val) => {
@@ -60,7 +64,7 @@ function useDocumentStore({
60
64
  () => box.current,
61
65
  () => box.current
62
66
  );
63
- return [storeValue, observer, setObserver];
67
+ return [storeValue, observer];
64
68
  }
65
69
  // Annotate the CommonJS export names for ESM import in node:
66
70
  0 && (module.exports = {
@@ -6,10 +6,6 @@ export declare function useDocumentSubscription<_Artifact extends DocumentArtifa
6
6
  variables: _Input;
7
7
  disabled?: boolean;
8
8
  send?: Partial<SendParams>;
9
- }): [
10
- QueryResult<_Data, _Input> & {
11
- parent?: string | null;
12
- },
13
- DocumentStore<_Data, _Input>,
14
- (store: DocumentStore<_Data, _Input>) => void
15
- ];
9
+ }): [QueryResult<_Data, _Input> & {
10
+ parent?: string | null;
11
+ }, DocumentStore<_Data, _Input>];
@@ -37,11 +37,11 @@ function useDocumentSubscription({
37
37
  disabled,
38
38
  ...observeParams
39
39
  }) {
40
- const [storeValue, observer, setObserver] = (0, import_useDocumentStore.useDocumentStore)({
40
+ const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({
41
41
  artifact,
42
42
  ...observeParams
43
43
  });
44
- const session = (0, import_Router.useSession)();
44
+ const [session] = (0, import_Router.useSession)();
45
45
  (0, import_useDeepCompareEffect.default)(() => {
46
46
  if (!disabled) {
47
47
  observer.send({
@@ -62,8 +62,7 @@ function useDocumentSubscription({
62
62
  parent: send?.stuff?.parentID,
63
63
  ...storeValue
64
64
  },
65
- observer,
66
- setObserver
65
+ observer
67
66
  ];
68
67
  }
69
68
  // Annotate the CommonJS export names for ESM import in node:
@@ -28,7 +28,7 @@ function useMutation({
28
28
  }) {
29
29
  const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({ artifact });
30
30
  const pending = storeValue.fetching;
31
- const session = (0, import_Router.useSession)();
31
+ const [session] = (0, import_Router.useSession)();
32
32
  const mutate = ({
33
33
  metadata,
34
34
  fetch,
@@ -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 } from './routing';
5
+ export { router_cache, useSession, useLocation } 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;
@@ -26,7 +26,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
26
26
  var runtime_exports = {};
27
27
  __export(runtime_exports, {
28
28
  Router: () => Router,
29
- router_cache: () => import_routing2.router_cache
29
+ router_cache: () => import_routing2.router_cache,
30
+ useLocation: () => import_routing2.useLocation,
31
+ useSession: () => import_routing2.useSession
30
32
  });
31
33
  module.exports = __toCommonJS(runtime_exports);
32
34
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -73,5 +75,7 @@ function Router({
73
75
  // Annotate the CommonJS export names for ESM import in node:
74
76
  0 && (module.exports = {
75
77
  Router,
76
- router_cache
78
+ router_cache,
79
+ useLocation,
80
+ useSession
77
81
  });
@@ -18,6 +18,9 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
18
18
  assetPrefix: string;
19
19
  injectToStream?: undefined | ((chunk: string) => void);
20
20
  }): JSX.Element;
21
+ export declare const useLocation: () => {
22
+ pathname: string;
23
+ };
21
24
  export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
22
25
  children: React.ReactElement;
23
26
  client: HoudiniClient;
@@ -38,6 +41,7 @@ type RouterContext = {
38
41
  ssr_signals: PendingCache;
39
42
  last_variables: LRUCache<GraphQLVariables>;
40
43
  session: App.Session;
44
+ setSession: (newSession: Partial<App.Session>) => void;
41
45
  };
42
46
  export type PendingCache = SuspenseCache<Promise<void> & {
43
47
  resolve: () => void;
@@ -47,7 +51,7 @@ export declare const useRouterContext: () => RouterContext;
47
51
  export declare function useClient(): HoudiniClient;
48
52
  export declare function useCache(): Cache;
49
53
  export declare function updateLocalSession(session: App.Session): void;
50
- export declare function useSession(): App.Session;
54
+ export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
51
55
  export declare function useCurrentVariables(): GraphQLVariables;
52
56
  export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
53
57
  export type RouterCache = {
@@ -31,15 +31,18 @@ __export(Router_exports, {
31
31
  useCache: () => useCache,
32
32
  useClient: () => useClient,
33
33
  useCurrentVariables: () => useCurrentVariables,
34
+ useLocation: () => useLocation,
34
35
  useQueryResult: () => useQueryResult,
35
36
  useRouterContext: () => useRouterContext,
36
37
  useSession: () => useSession
37
38
  });
38
39
  module.exports = __toCommonJS(Router_exports);
39
40
  var import_jsx_runtime = require("react/jsx-runtime");
41
+ var import_config = __toESM(require("$houdini/runtime/imports/config"));
40
42
  var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
41
43
  var import_match = require("$houdini/runtime/router/match");
42
44
  var import_react = __toESM(require("react"));
45
+ var import_react2 = require("react");
43
46
  var import_useDocumentStore = require("../hooks/useDocumentStore");
44
47
  var import_cache = require("./cache");
45
48
  const PreloadWhich = {
@@ -96,8 +99,9 @@ function Router({
96
99
  }
97
100
  }
98
101
  });
99
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: currentURL }, page.id) });
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) }) });
100
103
  }
104
+ const useLocation = () => (0, import_react2.useContext)(LocationContext);
101
105
  function usePageData({
102
106
  page,
103
107
  variables,
@@ -113,7 +117,7 @@ function usePageData({
113
117
  ssr_signals,
114
118
  last_variables
115
119
  } = useRouterContext();
116
- const session = useSession();
120
+ const [session] = useSession();
117
121
  function load_query({ id, artifact }) {
118
122
  for (const artifact2 of Object.keys(page.documents)) {
119
123
  last_variables.set(artifact2, variables);
@@ -301,7 +305,8 @@ function RouterContextProvider({
301
305
  data_cache,
302
306
  ssr_signals,
303
307
  last_variables,
304
- session
308
+ session,
309
+ setSession: (newSession) => setSession((old) => ({ ...old, ...newSession }))
305
310
  },
306
311
  children
307
312
  }
@@ -330,12 +335,30 @@ function updateLocalSession(session) {
330
335
  );
331
336
  }
332
337
  function useSession() {
333
- return useRouterContext().session;
338
+ const ctx = useRouterContext();
339
+ const updateSession = (newSession) => {
340
+ ctx.data_cache.clear();
341
+ ctx.setSession(newSession);
342
+ const auth = import_config.default.router?.auth;
343
+ if (!auth) {
344
+ return;
345
+ }
346
+ const url = "redirect" in auth ? auth.redirect : auth.url;
347
+ fetch(url, {
348
+ method: "POST",
349
+ body: JSON.stringify(newSession),
350
+ headers: {
351
+ "Content-Type": "application/json"
352
+ }
353
+ });
354
+ };
355
+ return [ctx.session, updateSession];
334
356
  }
335
357
  function useCurrentVariables() {
336
358
  return import_react.default.useContext(VariableContext);
337
359
  }
338
360
  const VariableContext = import_react.default.createContext(null);
361
+ const LocationContext = import_react.default.createContext({ pathname: "" });
339
362
  function useQueryResult(name) {
340
363
  const store_ref = useRouterContext().data_cache.get(name);
341
364
  const [{ data, errors }, observer] = (0, import_useDocumentStore.useDocumentStore)({
@@ -469,6 +492,7 @@ function signal_promise() {
469
492
  useCache,
470
493
  useClient,
471
494
  useCurrentVariables,
495
+ useLocation,
472
496
  useQueryResult,
473
497
  useRouterContext,
474
498
  useSession
@@ -10,7 +10,7 @@ function useDocumentHandle({
10
10
  }) {
11
11
  const [forwardPending, setForwardPending] = React.useState(false);
12
12
  const [backwardPending, setBackwardPending] = React.useState(false);
13
- const session = useSession();
13
+ const [session] = useSession();
14
14
  return React.useMemo(() => {
15
15
  const wrapLoad = (setLoading, fn) => {
16
16
  return async (value) => {
@@ -7,6 +7,5 @@ export type UseDocumentStoreParams<_Artifact extends DocumentArtifact, _Data ext
7
7
  } & Partial<ObserveParams<_Data, DocumentArtifact, _Input>>;
8
8
  export declare function useDocumentStore<_Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables, _Artifact extends DocumentArtifact = DocumentArtifact>({ artifact, observer: obs, ...observeParams }: UseDocumentStoreParams<_Artifact, _Data, _Input>): [
9
9
  QueryResult<_Data, _Input>,
10
- DocumentStore<_Data, _Input>,
11
- (store: DocumentStore<_Data, _Input>) => void
10
+ DocumentStore<_Data, _Input>
12
11
  ];
@@ -15,6 +15,10 @@ function useDocumentStore({
15
15
  })
16
16
  );
17
17
  const box = React.useRef(observer.state);
18
+ if (obs && obs !== observer) {
19
+ box.current = obs.state;
20
+ setObserver(obs);
21
+ }
18
22
  const subscribe = React.useCallback(
19
23
  (fn) => {
20
24
  return observer.subscribe((val) => {
@@ -31,7 +35,7 @@ function useDocumentStore({
31
35
  () => box.current,
32
36
  () => box.current
33
37
  );
34
- return [storeValue, observer, setObserver];
38
+ return [storeValue, observer];
35
39
  }
36
40
  export {
37
41
  useDocumentStore
@@ -6,10 +6,6 @@ export declare function useDocumentSubscription<_Artifact extends DocumentArtifa
6
6
  variables: _Input;
7
7
  disabled?: boolean;
8
8
  send?: Partial<SendParams>;
9
- }): [
10
- QueryResult<_Data, _Input> & {
11
- parent?: string | null;
12
- },
13
- DocumentStore<_Data, _Input>,
14
- (store: DocumentStore<_Data, _Input>) => void
15
- ];
9
+ }): [QueryResult<_Data, _Input> & {
10
+ parent?: string | null;
11
+ }, DocumentStore<_Data, _Input>];
@@ -8,11 +8,11 @@ function useDocumentSubscription({
8
8
  disabled,
9
9
  ...observeParams
10
10
  }) {
11
- const [storeValue, observer, setObserver] = useDocumentStore({
11
+ const [storeValue, observer] = useDocumentStore({
12
12
  artifact,
13
13
  ...observeParams
14
14
  });
15
- const session = useSession();
15
+ const [session] = useSession();
16
16
  useDeepCompareEffect(() => {
17
17
  if (!disabled) {
18
18
  observer.send({
@@ -33,8 +33,7 @@ function useDocumentSubscription({
33
33
  parent: send?.stuff?.parentID,
34
34
  ...storeValue
35
35
  },
36
- observer,
37
- setObserver
36
+ observer
38
37
  ];
39
38
  }
40
39
  export {
@@ -5,7 +5,7 @@ function useMutation({
5
5
  }) {
6
6
  const [storeValue, observer] = useDocumentStore({ artifact });
7
7
  const pending = storeValue.fetching;
8
- const session = useSession();
8
+ const [session] = useSession();
9
9
  const mutate = ({
10
10
  metadata,
11
11
  fetch,
@@ -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 } from './routing';
5
+ export { router_cache, useSession, useLocation } 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 } from "./routing";
6
+ import { router_cache, useSession, useLocation } from "./routing";
7
7
  function Router({
8
8
  cache,
9
9
  initialURL,
@@ -41,5 +41,7 @@ function Router({
41
41
  }
42
42
  export {
43
43
  Router,
44
- router_cache
44
+ router_cache,
45
+ useLocation,
46
+ useSession
45
47
  };
@@ -18,6 +18,9 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
18
18
  assetPrefix: string;
19
19
  injectToStream?: undefined | ((chunk: string) => void);
20
20
  }): JSX.Element;
21
+ export declare const useLocation: () => {
22
+ pathname: string;
23
+ };
21
24
  export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
22
25
  children: React.ReactElement;
23
26
  client: HoudiniClient;
@@ -38,6 +41,7 @@ type RouterContext = {
38
41
  ssr_signals: PendingCache;
39
42
  last_variables: LRUCache<GraphQLVariables>;
40
43
  session: App.Session;
44
+ setSession: (newSession: Partial<App.Session>) => void;
41
45
  };
42
46
  export type PendingCache = SuspenseCache<Promise<void> & {
43
47
  resolve: () => void;
@@ -47,7 +51,7 @@ export declare const useRouterContext: () => RouterContext;
47
51
  export declare function useClient(): HoudiniClient;
48
52
  export declare function useCache(): Cache;
49
53
  export declare function updateLocalSession(session: App.Session): void;
50
- export declare function useSession(): App.Session;
54
+ export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
51
55
  export declare function useCurrentVariables(): GraphQLVariables;
52
56
  export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
53
57
  export type RouterCache = {
@@ -1,7 +1,9 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
+ import configFile from "$houdini/runtime/imports/config";
2
3
  import { deepEquals } from "$houdini/runtime/lib/deepEquals";
3
4
  import { find_match } from "$houdini/runtime/router/match";
4
5
  import React from "react";
6
+ import { useContext } from "react";
5
7
  import { useDocumentStore } from "../hooks/useDocumentStore";
6
8
  import { suspense_cache } from "./cache";
7
9
  const PreloadWhich = {
@@ -58,8 +60,9 @@ function Router({
58
60
  }
59
61
  }
60
62
  });
61
- return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(PageComponent, { url: currentURL }, page.id) });
63
+ return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(LocationContext.Provider, { value: { pathname: currentURL }, children: /* @__PURE__ */ jsx(PageComponent, { url: currentURL }, page.id) }) });
62
64
  }
65
+ const useLocation = () => useContext(LocationContext);
63
66
  function usePageData({
64
67
  page,
65
68
  variables,
@@ -75,7 +78,7 @@ function usePageData({
75
78
  ssr_signals,
76
79
  last_variables
77
80
  } = useRouterContext();
78
- const session = useSession();
81
+ const [session] = useSession();
79
82
  function load_query({ id, artifact }) {
80
83
  for (const artifact2 of Object.keys(page.documents)) {
81
84
  last_variables.set(artifact2, variables);
@@ -263,7 +266,8 @@ function RouterContextProvider({
263
266
  data_cache,
264
267
  ssr_signals,
265
268
  last_variables,
266
- session
269
+ session,
270
+ setSession: (newSession) => setSession((old) => ({ ...old, ...newSession }))
267
271
  },
268
272
  children
269
273
  }
@@ -292,12 +296,30 @@ function updateLocalSession(session) {
292
296
  );
293
297
  }
294
298
  function useSession() {
295
- return useRouterContext().session;
299
+ const ctx = useRouterContext();
300
+ const updateSession = (newSession) => {
301
+ ctx.data_cache.clear();
302
+ ctx.setSession(newSession);
303
+ const auth = configFile.router?.auth;
304
+ if (!auth) {
305
+ return;
306
+ }
307
+ const url = "redirect" in auth ? auth.redirect : auth.url;
308
+ fetch(url, {
309
+ method: "POST",
310
+ body: JSON.stringify(newSession),
311
+ headers: {
312
+ "Content-Type": "application/json"
313
+ }
314
+ });
315
+ };
316
+ return [ctx.session, updateSession];
296
317
  }
297
318
  function useCurrentVariables() {
298
319
  return React.useContext(VariableContext);
299
320
  }
300
321
  const VariableContext = React.createContext(null);
322
+ const LocationContext = React.createContext({ pathname: "" });
301
323
  function useQueryResult(name) {
302
324
  const store_ref = useRouterContext().data_cache.get(name);
303
325
  const [{ data, errors }, observer] = useDocumentStore({
@@ -430,6 +452,7 @@ export {
430
452
  useCache,
431
453
  useClient,
432
454
  useCurrentVariables,
455
+ useLocation,
433
456
  useQueryResult,
434
457
  useRouterContext,
435
458
  useSession
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini-react",
3
- "version": "1.2.42",
3
+ "version": "1.2.44",
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": "^1.2.42"
46
+ "houdini": "^1.2.44"
47
47
  },
48
48
  "files": [
49
49
  "build"