houdini 1.2.43 → 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.
@@ -65883,8 +65883,22 @@ var query = documentPlugin(ArtifactKind.Query, function() {
65883
65883
  let lastVariables = null;
65884
65884
  return {
65885
65885
  start(ctx, { next }) {
65886
+ const runtimeScalarPayload = {
65887
+ session: ctx.session
65888
+ };
65886
65889
  ctx.variables = {
65887
65890
  ...lastVariables,
65891
+ ...Object.fromEntries(
65892
+ Object.entries(ctx.artifact.input?.runtimeScalars ?? {}).map(
65893
+ ([field, type]) => {
65894
+ const runtimeScalar = ctx.config.features?.runtimeScalars?.[type];
65895
+ if (!runtimeScalar) {
65896
+ return [field, type];
65897
+ }
65898
+ return [field, runtimeScalar.resolve(runtimeScalarPayload)];
65899
+ }
65900
+ )
65901
+ ),
65888
65902
  ...ctx.variables
65889
65903
  };
65890
65904
  next(ctx);
@@ -67061,6 +67075,9 @@ var Config = class {
67061
67075
  get loadingDirective() {
67062
67076
  return `loading`;
67063
67077
  }
67078
+ get runtimeScalarDirective() {
67079
+ return "__houdini__runtimeScalar";
67080
+ }
67064
67081
  get whenDirective() {
67065
67082
  return "when";
67066
67083
  }
@@ -67131,7 +67148,7 @@ var Config = class {
67131
67148
  const internalDirectives = this.#newSchemaInstance?.getDirectives().reduce((list, directive) => {
67132
67149
  return list.concat(directive.name);
67133
67150
  }, []) ?? [];
67134
- return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name));
67151
+ return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name) || name === this.runtimeScalarDirective);
67135
67152
  }
67136
67153
  get componentFieldDirective() {
67137
67154
  return "componentField";
@@ -67692,7 +67709,7 @@ function unwrapType(config, type, wrappers = []) {
67692
67709
  }
67693
67710
  const namedType = config.schema.getType(type.name.value || type.name);
67694
67711
  if (!namedType) {
67695
- throw new Error("Could not unwrap type: " + JSON.stringify(type));
67712
+ throw new Error("Unknown type: " + type.name.value || type.name);
67696
67713
  }
67697
67714
  return { type: namedType, wrappers };
67698
67715
  }
@@ -68926,22 +68943,36 @@ function decode2(token) {
68926
68943
  // src/runtime/router/session.ts
68927
68944
  async function handle_request(args) {
68928
68945
  const plugin_config = args.config.router ?? {};
68929
- const { pathname } = new URL(args.url);
68946
+ const { pathname } = new URL(args.request.url);
68930
68947
  if (plugin_config.auth && "redirect" in plugin_config.auth && pathname.startsWith(plugin_config.auth.redirect)) {
68931
68948
  return await redirect_auth(args);
68932
68949
  }
68933
68950
  }
68934
68951
  async function redirect_auth(args) {
68935
- const { searchParams } = new URL(args.url, `http://${args.headers.get("host")}`);
68936
- const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
68937
- const response = new Response("ok", {
68938
- status: 302,
68939
- headers: {
68940
- Location: redirectTo ?? "/"
68941
- }
68942
- });
68943
- await set_session(args, response, session);
68944
- return response;
68952
+ if (args.request.method === "GET") {
68953
+ const { searchParams } = new URL(
68954
+ args.request.url,
68955
+ `http://${args.request.headers.get("host")}`
68956
+ );
68957
+ const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
68958
+ const response = new Response("ok", {
68959
+ status: 302,
68960
+ headers: {
68961
+ Location: redirectTo ?? "/"
68962
+ }
68963
+ });
68964
+ await set_session(args, response, session);
68965
+ return response;
68966
+ }
68967
+ if (args.request.method === "POST") {
68968
+ const newValues = await args.request.json();
68969
+ const existing = await get_session(args.request.headers, args.session_keys);
68970
+ const response = new Response("ok", {
68971
+ status: 200
68972
+ });
68973
+ await set_session(args, response, { ...existing, ...newValues });
68974
+ return response;
68975
+ }
68945
68976
  }
68946
68977
  var session_cookie_name = "__houdini__";
68947
68978
  async function set_session(req, response, value) {
@@ -65805,8 +65805,22 @@ var query = documentPlugin(ArtifactKind.Query, function() {
65805
65805
  let lastVariables = null;
65806
65806
  return {
65807
65807
  start(ctx, { next }) {
65808
+ const runtimeScalarPayload = {
65809
+ session: ctx.session
65810
+ };
65808
65811
  ctx.variables = {
65809
65812
  ...lastVariables,
65813
+ ...Object.fromEntries(
65814
+ Object.entries(ctx.artifact.input?.runtimeScalars ?? {}).map(
65815
+ ([field, type]) => {
65816
+ const runtimeScalar = ctx.config.features?.runtimeScalars?.[type];
65817
+ if (!runtimeScalar) {
65818
+ return [field, type];
65819
+ }
65820
+ return [field, runtimeScalar.resolve(runtimeScalarPayload)];
65821
+ }
65822
+ )
65823
+ ),
65810
65824
  ...ctx.variables
65811
65825
  };
65812
65826
  next(ctx);
@@ -66982,6 +66996,9 @@ var Config = class {
66982
66996
  get loadingDirective() {
66983
66997
  return `loading`;
66984
66998
  }
66999
+ get runtimeScalarDirective() {
67000
+ return "__houdini__runtimeScalar";
67001
+ }
66985
67002
  get whenDirective() {
66986
67003
  return "when";
66987
67004
  }
@@ -67052,7 +67069,7 @@ var Config = class {
67052
67069
  const internalDirectives = this.#newSchemaInstance?.getDirectives().reduce((list, directive) => {
67053
67070
  return list.concat(directive.name);
67054
67071
  }, []) ?? [];
67055
- return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name));
67072
+ return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name) || name === this.runtimeScalarDirective);
67056
67073
  }
67057
67074
  get componentFieldDirective() {
67058
67075
  return "componentField";
@@ -67613,7 +67630,7 @@ function unwrapType(config, type, wrappers = []) {
67613
67630
  }
67614
67631
  const namedType = config.schema.getType(type.name.value || type.name);
67615
67632
  if (!namedType) {
67616
- throw new Error("Could not unwrap type: " + JSON.stringify(type));
67633
+ throw new Error("Unknown type: " + type.name.value || type.name);
67617
67634
  }
67618
67635
  return { type: namedType, wrappers };
67619
67636
  }
@@ -68847,22 +68864,36 @@ function decode2(token) {
68847
68864
  // src/runtime/router/session.ts
68848
68865
  async function handle_request(args) {
68849
68866
  const plugin_config = args.config.router ?? {};
68850
- const { pathname } = new URL(args.url);
68867
+ const { pathname } = new URL(args.request.url);
68851
68868
  if (plugin_config.auth && "redirect" in plugin_config.auth && pathname.startsWith(plugin_config.auth.redirect)) {
68852
68869
  return await redirect_auth(args);
68853
68870
  }
68854
68871
  }
68855
68872
  async function redirect_auth(args) {
68856
- const { searchParams } = new URL(args.url, `http://${args.headers.get("host")}`);
68857
- const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
68858
- const response = new Response("ok", {
68859
- status: 302,
68860
- headers: {
68861
- Location: redirectTo ?? "/"
68862
- }
68863
- });
68864
- await set_session(args, response, session);
68865
- return response;
68873
+ if (args.request.method === "GET") {
68874
+ const { searchParams } = new URL(
68875
+ args.request.url,
68876
+ `http://${args.request.headers.get("host")}`
68877
+ );
68878
+ const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
68879
+ const response = new Response("ok", {
68880
+ status: 302,
68881
+ headers: {
68882
+ Location: redirectTo ?? "/"
68883
+ }
68884
+ });
68885
+ await set_session(args, response, session);
68886
+ return response;
68887
+ }
68888
+ if (args.request.method === "POST") {
68889
+ const newValues = await args.request.json();
68890
+ const existing = await get_session(args.request.headers, args.session_keys);
68891
+ const response = new Response("ok", {
68892
+ status: 200
68893
+ });
68894
+ await set_session(args, response, { ...existing, ...newValues });
68895
+ return response;
68896
+ }
68866
68897
  }
68867
68898
  var session_cookie_name = "__houdini__";
68868
68899
  async function set_session(req, response, value) {
@@ -119,13 +119,23 @@ export type ConfigFile = {
119
119
  */
120
120
  router?: RouterConfig;
121
121
  /**
122
- * A collection of flags to opt-into experimental features that might break unexpectedly
122
+ * A collection of flags to opt-into experimental features are not yet stable and can break on any
123
+ * minor version.
123
124
  */
124
125
  features?: {
125
- componentFields?: boolean;
126
+ /** Interact with the cache directly using an imperative API.*/
126
127
  imperativeCache?: boolean;
128
+ runtimeScalars?: Record<string, {
129
+ type: string;
130
+ resolve: (args: RuntimeScalarPayload) => any;
131
+ }>;
132
+ /** [React Only] Emebed component references in query responses*/
133
+ componentFields?: boolean;
127
134
  };
128
135
  };
136
+ export type RuntimeScalarPayload = {
137
+ session?: App.Session | null | undefined;
138
+ };
129
139
  type RouterConfig = {
130
140
  auth?: AuthStrategy;
131
141
  apiEndpoint?: string;
@@ -31,6 +31,9 @@ declare global {
31
31
  }
32
32
  }
33
33
  }
34
+ export type RuntimeScalarResolver = (args: {
35
+ session: App.Session;
36
+ }) => any;
34
37
  export type Fragment<_Result> = {
35
38
  readonly shape?: _Result;
36
39
  };
@@ -72,6 +75,7 @@ export type InputObject = {
72
75
  fields: Record<string, string>;
73
76
  types: Record<string, Record<string, string>>;
74
77
  defaults: Record<string, any>;
78
+ runtimeScalars: Record<string, string>;
75
79
  };
76
80
  export type BaseCompiledDocument<_Kind extends ArtifactKinds> = {
77
81
  name: string;
@@ -1,9 +1,8 @@
1
1
  import type { ConfigFile } from '../lib';
2
2
  type ServerHandlerArgs = {
3
- url: string;
3
+ request: Request;
4
4
  config: ConfigFile;
5
5
  session_keys: string[];
6
- headers: Headers;
7
6
  };
8
7
  export declare function handle_request(args: ServerHandlerArgs): Promise<Response | undefined>;
9
8
  export type Server = {
@@ -35,8 +35,22 @@ const query = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Query,
35
35
  let lastVariables = null;
36
36
  return {
37
37
  start(ctx, { next }) {
38
+ const runtimeScalarPayload = {
39
+ session: ctx.session
40
+ };
38
41
  ctx.variables = {
39
42
  ...lastVariables,
43
+ ...Object.fromEntries(
44
+ Object.entries(ctx.artifact.input?.runtimeScalars ?? {}).map(
45
+ ([field, type]) => {
46
+ const runtimeScalar = ctx.config.features?.runtimeScalars?.[type];
47
+ if (!runtimeScalar) {
48
+ return [field, type];
49
+ }
50
+ return [field, runtimeScalar.resolve(runtimeScalarPayload)];
51
+ }
52
+ )
53
+ ),
40
54
  ...ctx.variables
41
55
  };
42
56
  next(ctx);
@@ -119,13 +119,23 @@ export type ConfigFile = {
119
119
  */
120
120
  router?: RouterConfig;
121
121
  /**
122
- * A collection of flags to opt-into experimental features that might break unexpectedly
122
+ * A collection of flags to opt-into experimental features are not yet stable and can break on any
123
+ * minor version.
123
124
  */
124
125
  features?: {
125
- componentFields?: boolean;
126
+ /** Interact with the cache directly using an imperative API.*/
126
127
  imperativeCache?: boolean;
128
+ runtimeScalars?: Record<string, {
129
+ type: string;
130
+ resolve: (args: RuntimeScalarPayload) => any;
131
+ }>;
132
+ /** [React Only] Emebed component references in query responses*/
133
+ componentFields?: boolean;
127
134
  };
128
135
  };
136
+ export type RuntimeScalarPayload = {
137
+ session?: App.Session | null | undefined;
138
+ };
129
139
  type RouterConfig = {
130
140
  auth?: AuthStrategy;
131
141
  apiEndpoint?: string;
@@ -31,6 +31,9 @@ declare global {
31
31
  }
32
32
  }
33
33
  }
34
+ export type RuntimeScalarResolver = (args: {
35
+ session: App.Session;
36
+ }) => any;
34
37
  export type Fragment<_Result> = {
35
38
  readonly shape?: _Result;
36
39
  };
@@ -72,6 +75,7 @@ export type InputObject = {
72
75
  fields: Record<string, string>;
73
76
  types: Record<string, Record<string, string>>;
74
77
  defaults: Record<string, any>;
78
+ runtimeScalars: Record<string, string>;
75
79
  };
76
80
  export type BaseCompiledDocument<_Kind extends ArtifactKinds> = {
77
81
  name: string;
@@ -66,10 +66,9 @@ function _serverHandler({
66
66
  return yoga(request);
67
67
  }
68
68
  const authResponse = await (0, import_session.handle_request)({
69
- url: request.url,
69
+ request,
70
70
  config: config_file,
71
- session_keys,
72
- headers: request.headers
71
+ session_keys
73
72
  });
74
73
  if (authResponse) {
75
74
  return authResponse;
@@ -1,9 +1,8 @@
1
1
  import type { ConfigFile } from '../lib';
2
2
  type ServerHandlerArgs = {
3
- url: string;
3
+ request: Request;
4
4
  config: ConfigFile;
5
5
  session_keys: string[];
6
- headers: Headers;
7
6
  };
8
7
  export declare function handle_request(args: ServerHandlerArgs): Promise<Response | undefined>;
9
8
  export type Server = {
@@ -26,22 +26,36 @@ var import_cookies = require("./cookies");
26
26
  var import_jwt = require("./jwt");
27
27
  async function handle_request(args) {
28
28
  const plugin_config = args.config.router ?? {};
29
- const { pathname } = new URL(args.url);
29
+ const { pathname } = new URL(args.request.url);
30
30
  if (plugin_config.auth && "redirect" in plugin_config.auth && pathname.startsWith(plugin_config.auth.redirect)) {
31
31
  return await redirect_auth(args);
32
32
  }
33
33
  }
34
34
  async function redirect_auth(args) {
35
- const { searchParams } = new URL(args.url, `http://${args.headers.get("host")}`);
36
- const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
37
- const response = new Response("ok", {
38
- status: 302,
39
- headers: {
40
- Location: redirectTo ?? "/"
41
- }
42
- });
43
- await set_session(args, response, session);
44
- return response;
35
+ if (args.request.method === "GET") {
36
+ const { searchParams } = new URL(
37
+ args.request.url,
38
+ `http://${args.request.headers.get("host")}`
39
+ );
40
+ const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
41
+ const response = new Response("ok", {
42
+ status: 302,
43
+ headers: {
44
+ Location: redirectTo ?? "/"
45
+ }
46
+ });
47
+ await set_session(args, response, session);
48
+ return response;
49
+ }
50
+ if (args.request.method === "POST") {
51
+ const newValues = await args.request.json();
52
+ const existing = await get_session(args.request.headers, args.session_keys);
53
+ const response = new Response("ok", {
54
+ status: 200
55
+ });
56
+ await set_session(args, response, { ...existing, ...newValues });
57
+ return response;
58
+ }
45
59
  }
46
60
  const session_cookie_name = "__houdini__";
47
61
  async function set_session(req, response, value) {
@@ -6,8 +6,22 @@ const query = documentPlugin(ArtifactKind.Query, function() {
6
6
  let lastVariables = null;
7
7
  return {
8
8
  start(ctx, { next }) {
9
+ const runtimeScalarPayload = {
10
+ session: ctx.session
11
+ };
9
12
  ctx.variables = {
10
13
  ...lastVariables,
14
+ ...Object.fromEntries(
15
+ Object.entries(ctx.artifact.input?.runtimeScalars ?? {}).map(
16
+ ([field, type]) => {
17
+ const runtimeScalar = ctx.config.features?.runtimeScalars?.[type];
18
+ if (!runtimeScalar) {
19
+ return [field, type];
20
+ }
21
+ return [field, runtimeScalar.resolve(runtimeScalarPayload)];
22
+ }
23
+ )
24
+ ),
11
25
  ...ctx.variables
12
26
  };
13
27
  next(ctx);
@@ -119,13 +119,23 @@ export type ConfigFile = {
119
119
  */
120
120
  router?: RouterConfig;
121
121
  /**
122
- * A collection of flags to opt-into experimental features that might break unexpectedly
122
+ * A collection of flags to opt-into experimental features are not yet stable and can break on any
123
+ * minor version.
123
124
  */
124
125
  features?: {
125
- componentFields?: boolean;
126
+ /** Interact with the cache directly using an imperative API.*/
126
127
  imperativeCache?: boolean;
128
+ runtimeScalars?: Record<string, {
129
+ type: string;
130
+ resolve: (args: RuntimeScalarPayload) => any;
131
+ }>;
132
+ /** [React Only] Emebed component references in query responses*/
133
+ componentFields?: boolean;
127
134
  };
128
135
  };
136
+ export type RuntimeScalarPayload = {
137
+ session?: App.Session | null | undefined;
138
+ };
129
139
  type RouterConfig = {
130
140
  auth?: AuthStrategy;
131
141
  apiEndpoint?: string;
@@ -31,6 +31,9 @@ declare global {
31
31
  }
32
32
  }
33
33
  }
34
+ export type RuntimeScalarResolver = (args: {
35
+ session: App.Session;
36
+ }) => any;
34
37
  export type Fragment<_Result> = {
35
38
  readonly shape?: _Result;
36
39
  };
@@ -72,6 +75,7 @@ export type InputObject = {
72
75
  fields: Record<string, string>;
73
76
  types: Record<string, Record<string, string>>;
74
77
  defaults: Record<string, any>;
78
+ runtimeScalars: Record<string, string>;
75
79
  };
76
80
  export type BaseCompiledDocument<_Kind extends ArtifactKinds> = {
77
81
  name: string;
@@ -42,10 +42,9 @@ function _serverHandler({
42
42
  return yoga(request);
43
43
  }
44
44
  const authResponse = await handle_request({
45
- url: request.url,
45
+ request,
46
46
  config: config_file,
47
- session_keys,
48
- headers: request.headers
47
+ session_keys
49
48
  });
50
49
  if (authResponse) {
51
50
  return authResponse;
@@ -1,9 +1,8 @@
1
1
  import type { ConfigFile } from '../lib';
2
2
  type ServerHandlerArgs = {
3
- url: string;
3
+ request: Request;
4
4
  config: ConfigFile;
5
5
  session_keys: string[];
6
- headers: Headers;
7
6
  };
8
7
  export declare function handle_request(args: ServerHandlerArgs): Promise<Response | undefined>;
9
8
  export type Server = {
@@ -2,22 +2,36 @@ import { parse } from "./cookies";
2
2
  import { decode, encode, verify } from "./jwt";
3
3
  async function handle_request(args) {
4
4
  const plugin_config = args.config.router ?? {};
5
- const { pathname } = new URL(args.url);
5
+ const { pathname } = new URL(args.request.url);
6
6
  if (plugin_config.auth && "redirect" in plugin_config.auth && pathname.startsWith(plugin_config.auth.redirect)) {
7
7
  return await redirect_auth(args);
8
8
  }
9
9
  }
10
10
  async function redirect_auth(args) {
11
- const { searchParams } = new URL(args.url, `http://${args.headers.get("host")}`);
12
- const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
13
- const response = new Response("ok", {
14
- status: 302,
15
- headers: {
16
- Location: redirectTo ?? "/"
17
- }
18
- });
19
- await set_session(args, response, session);
20
- return response;
11
+ if (args.request.method === "GET") {
12
+ const { searchParams } = new URL(
13
+ args.request.url,
14
+ `http://${args.request.headers.get("host")}`
15
+ );
16
+ const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
17
+ const response = new Response("ok", {
18
+ status: 302,
19
+ headers: {
20
+ Location: redirectTo ?? "/"
21
+ }
22
+ });
23
+ await set_session(args, response, session);
24
+ return response;
25
+ }
26
+ if (args.request.method === "POST") {
27
+ const newValues = await args.request.json();
28
+ const existing = await get_session(args.request.headers, args.session_keys);
29
+ const response = new Response("ok", {
30
+ status: 200
31
+ });
32
+ await set_session(args, response, { ...existing, ...newValues });
33
+ return response;
34
+ }
21
35
  }
22
36
  const session_cookie_name = "__houdini__";
23
37
  async function set_session(req, response, value) {