houdini 2.0.0-next.4 → 2.0.0-next.6

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.
@@ -76,7 +76,7 @@ class HoudiniClient {
76
76
  }
77
77
  this.throwOnError_operations = throwOnError?.operations ?? [];
78
78
  let serverPort = globalThis.process?.env?.HOUDINI_PORT ?? "5173";
79
- this.url = url ?? (globalThis.window ? "" : `https://localhost:${serverPort}`) + (0, import_lib.localApiEndpoint)((0, import_lib.getCurrentConfig)());
79
+ this.url = url ?? (globalThis.window ? "" : `http://localhost:${serverPort}`) + (0, import_lib.localApiEndpoint)((0, import_lib.getCurrentConfig)());
80
80
  this.throwOnError = throwOnError;
81
81
  this.fetchParams = fetchParams;
82
82
  this.pipeline = pipeline;
@@ -29,13 +29,13 @@ export declare function parse(str: string, options?: {
29
29
  *
30
30
  */
31
31
  export declare function serialize(name: string, val: string, options: {
32
- encode: boolean;
33
- maxAge: number;
34
- domain: string;
35
- path: string;
36
- expires: Date;
37
- httpOnly: boolean;
38
- priority: string | number;
39
- secure: boolean;
40
- sameSite: string | boolean;
32
+ encode?: boolean;
33
+ maxAge?: number;
34
+ domain?: string;
35
+ path?: string;
36
+ expires?: Date;
37
+ httpOnly?: boolean;
38
+ priority?: string | number;
39
+ secure?: boolean;
40
+ sameSite?: string | boolean;
41
41
  }): string;
@@ -76,7 +76,7 @@ function serialize(name, val, options) {
76
76
  throw new TypeError("argument val is invalid");
77
77
  }
78
78
  let str = name + "=" + value;
79
- if (opt.maxAge !== null) {
79
+ if (opt.maxAge) {
80
80
  let maxAge = opt.maxAge - 0;
81
81
  if (Number.isNaN(maxAge) || !isFinite(maxAge)) {
82
82
  throw new TypeError("option maxAge is invalid");
@@ -1,5 +1,5 @@
1
1
  import { createServerAdapter as createAdapter } from '@whatwg-node/server';
2
- import { type GraphQLSchema } from 'graphql';
2
+ import type { GraphQLSchema } from 'graphql';
3
3
  import { createYoga } from 'graphql-yoga';
4
4
  import type { HoudiniClient } from '../client';
5
5
  import type { RouterManifest, RouterPageManifest, YogaServerOptions } from './types';
@@ -23,9 +23,9 @@ __export(server_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(server_exports);
25
25
  var import_server = require("@whatwg-node/server");
26
- var import_graphql = require("graphql");
27
26
  var import_graphql_yoga = require("graphql-yoga");
28
27
  var import_config = require("../lib/config");
28
+ var import_cookies = require("./cookies");
29
29
  var import_match = require("./match");
30
30
  var import_session = require("./session");
31
31
  const config_file = (0, import_config.getCurrentConfig)();
@@ -44,19 +44,29 @@ function _serverHandler({
44
44
  yoga = (0, import_graphql_yoga.createYoga)({
45
45
  schema,
46
46
  landingPage: !production,
47
- graphqlEndpoint
47
+ graphqlEndpoint,
48
+ context: async (request) => await (0, import_session.get_session)(request.headers, session_keys)
48
49
  });
49
50
  }
50
51
  client.componentCache = componentCache;
51
52
  if (schema) {
52
53
  client.registerProxy(graphqlEndpoint, async ({ query, variables, session }) => {
53
- const parsed = (0, import_graphql.parse)(query);
54
- return await (0, import_graphql.execute)({
55
- schema,
56
- document: parsed,
57
- contextValue: session,
58
- variableValues: variables
59
- });
54
+ const response = await yoga(
55
+ new Request(`http://localhost/${graphqlEndpoint}`, {
56
+ method: "POST",
57
+ headers: {
58
+ "Content-Type": "application/json",
59
+ Cookie: (0, import_cookies.serialize)(import_session.session_cookie_name, JSON.stringify(session ?? {}), {
60
+ httpOnly: true
61
+ })
62
+ },
63
+ body: JSON.stringify({
64
+ query,
65
+ variables
66
+ })
67
+ })
68
+ );
69
+ return await response.json();
60
70
  });
61
71
  }
62
72
  return async (request) => {
@@ -17,5 +17,6 @@ export type ServerResponse = {
17
17
  redirect(url: string, status?: number): void;
18
18
  set_header(name: string, value: string): void;
19
19
  };
20
+ export declare const session_cookie_name = "__houdini__";
20
21
  export declare function get_session(req: Headers, secrets: string[]): Promise<App.Session>;
21
22
  export {};
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var session_exports = {};
20
20
  __export(session_exports, {
21
21
  get_session: () => get_session,
22
- handle_request: () => handle_request
22
+ handle_request: () => handle_request,
23
+ session_cookie_name: () => session_cookie_name
23
24
  });
24
25
  module.exports = __toCommonJS(session_exports);
25
26
  var import_cookies = require("./cookies");
@@ -91,5 +92,6 @@ async function get_session(req, secrets) {
91
92
  // Annotate the CommonJS export names for ESM import in node:
92
93
  0 && (module.exports = {
93
94
  get_session,
94
- handle_request
95
+ handle_request,
96
+ session_cookie_name
95
97
  });
@@ -45,7 +45,7 @@ class HoudiniClient {
45
45
  }
46
46
  this.throwOnError_operations = throwOnError?.operations ?? [];
47
47
  let serverPort = globalThis.process?.env?.HOUDINI_PORT ?? "5173";
48
- this.url = url ?? (globalThis.window ? "" : `https://localhost:${serverPort}`) + localApiEndpoint(getCurrentConfig());
48
+ this.url = url ?? (globalThis.window ? "" : `http://localhost:${serverPort}`) + localApiEndpoint(getCurrentConfig());
49
49
  this.throwOnError = throwOnError;
50
50
  this.fetchParams = fetchParams;
51
51
  this.pipeline = pipeline;
@@ -29,13 +29,13 @@ export declare function parse(str: string, options?: {
29
29
  *
30
30
  */
31
31
  export declare function serialize(name: string, val: string, options: {
32
- encode: boolean;
33
- maxAge: number;
34
- domain: string;
35
- path: string;
36
- expires: Date;
37
- httpOnly: boolean;
38
- priority: string | number;
39
- secure: boolean;
40
- sameSite: string | boolean;
32
+ encode?: boolean;
33
+ maxAge?: number;
34
+ domain?: string;
35
+ path?: string;
36
+ expires?: Date;
37
+ httpOnly?: boolean;
38
+ priority?: string | number;
39
+ secure?: boolean;
40
+ sameSite?: string | boolean;
41
41
  }): string;
@@ -52,7 +52,7 @@ function serialize(name, val, options) {
52
52
  throw new TypeError("argument val is invalid");
53
53
  }
54
54
  let str = name + "=" + value;
55
- if (opt.maxAge !== null) {
55
+ if (opt.maxAge) {
56
56
  let maxAge = opt.maxAge - 0;
57
57
  if (Number.isNaN(maxAge) || !isFinite(maxAge)) {
58
58
  throw new TypeError("option maxAge is invalid");
@@ -1,5 +1,5 @@
1
1
  import { createServerAdapter as createAdapter } from '@whatwg-node/server';
2
- import { type GraphQLSchema } from 'graphql';
2
+ import type { GraphQLSchema } from 'graphql';
3
3
  import { createYoga } from 'graphql-yoga';
4
4
  import type { HoudiniClient } from '../client';
5
5
  import type { RouterManifest, RouterPageManifest, YogaServerOptions } from './types';
@@ -1,9 +1,9 @@
1
1
  import { createServerAdapter as createAdapter } from "@whatwg-node/server";
2
- import { parse, execute } from "graphql";
3
2
  import { createYoga } from "graphql-yoga";
4
3
  import { localApiSessionKeys, localApiEndpoint, getCurrentConfig } from "../lib/config";
4
+ import { serialize as encodeCookie } from "./cookies";
5
5
  import { find_match } from "./match";
6
- import { get_session, handle_request } from "./session";
6
+ import { get_session, handle_request, session_cookie_name } from "./session";
7
7
  const config_file = getCurrentConfig();
8
8
  const session_keys = localApiSessionKeys(config_file);
9
9
  function _serverHandler({
@@ -20,19 +20,29 @@ function _serverHandler({
20
20
  yoga = createYoga({
21
21
  schema,
22
22
  landingPage: !production,
23
- graphqlEndpoint
23
+ graphqlEndpoint,
24
+ context: async (request) => await get_session(request.headers, session_keys)
24
25
  });
25
26
  }
26
27
  client.componentCache = componentCache;
27
28
  if (schema) {
28
29
  client.registerProxy(graphqlEndpoint, async ({ query, variables, session }) => {
29
- const parsed = parse(query);
30
- return await execute({
31
- schema,
32
- document: parsed,
33
- contextValue: session,
34
- variableValues: variables
35
- });
30
+ const response = await yoga(
31
+ new Request(`http://localhost/${graphqlEndpoint}`, {
32
+ method: "POST",
33
+ headers: {
34
+ "Content-Type": "application/json",
35
+ Cookie: encodeCookie(session_cookie_name, JSON.stringify(session ?? {}), {
36
+ httpOnly: true
37
+ })
38
+ },
39
+ body: JSON.stringify({
40
+ query,
41
+ variables
42
+ })
43
+ })
44
+ );
45
+ return await response.json();
36
46
  });
37
47
  }
38
48
  return async (request) => {
@@ -17,5 +17,6 @@ export type ServerResponse = {
17
17
  redirect(url: string, status?: number): void;
18
18
  set_header(name: string, value: string): void;
19
19
  };
20
+ export declare const session_cookie_name = "__houdini__";
20
21
  export declare function get_session(req: Headers, secrets: string[]): Promise<App.Session>;
21
22
  export {};
@@ -66,5 +66,6 @@ async function get_session(req, secrets) {
66
66
  }
67
67
  export {
68
68
  get_session,
69
- handle_request
69
+ handle_request,
70
+ session_cookie_name
70
71
  };
@@ -66403,10 +66403,10 @@ var AST3 = recast2.types.builders;
66403
66403
  function unwrappedTsTypeReference(config, filepath, missingScalars, {
66404
66404
  type,
66405
66405
  wrappers
66406
- }, body) {
66406
+ }, body, input) {
66407
66407
  let result;
66408
66408
  if (graphql6.isScalarType(type)) {
66409
- result = scalarPropertyValue(config, filepath, missingScalars, type, body, null);
66409
+ result = scalarPropertyValue(config, filepath, missingScalars, type, body, null, input);
66410
66410
  } else if (graphql6.isEnumType(type)) {
66411
66411
  result = enumReference(config, body, type.name);
66412
66412
  } else {
@@ -66423,14 +66423,15 @@ function unwrappedTsTypeReference(config, filepath, missingScalars, {
66423
66423
  }
66424
66424
  return result;
66425
66425
  }
66426
- function tsTypeReference(config, filepath, missingScalars, definition, body) {
66426
+ function tsTypeReference(config, filepath, missingScalars, definition, body, input) {
66427
66427
  const { type, wrappers } = unwrapType(config, definition.type);
66428
66428
  return unwrappedTsTypeReference(
66429
66429
  config,
66430
66430
  filepath,
66431
66431
  missingScalars,
66432
66432
  { type, wrappers },
66433
- body
66433
+ body,
66434
+ input
66434
66435
  );
66435
66436
  }
66436
66437
  function enumReference(config, body, name) {
@@ -66459,7 +66460,7 @@ function nullableField(inner, input = false) {
66459
66460
  }
66460
66461
  return AST3.tsUnionType(members);
66461
66462
  }
66462
- function scalarPropertyValue(config, filepath, missingScalars, target, body, field) {
66463
+ function scalarPropertyValue(config, filepath, missingScalars, target, body, field, input) {
66463
66464
  if (config.configFile.features?.componentFields && target.name === config.componentScalar) {
66464
66465
  if (!field) {
66465
66466
  return AST3.tsNeverKeyword();
@@ -66518,6 +66519,9 @@ function scalarPropertyValue(config, filepath, missingScalars, target, body, fie
66518
66519
  return AST3.tsBooleanKeyword();
66519
66520
  }
66520
66521
  case "ID": {
66522
+ if (input) {
66523
+ return AST3.tsUnionType([AST3.tsStringKeyword(), AST3.tsNumberKeyword()]);
66524
+ }
66521
66525
  return AST3.tsStringKeyword();
66522
66526
  }
66523
66527
  default: {
@@ -66528,7 +66532,8 @@ function scalarPropertyValue(config, filepath, missingScalars, target, body, fie
66528
66532
  missingScalars,
66529
66533
  target.ofType,
66530
66534
  body,
66531
- field
66535
+ field,
66536
+ input
66532
66537
  );
66533
66538
  }
66534
66539
  if (config.scalars?.[target.name]) {
@@ -69245,7 +69250,7 @@ var recast11 = __toESM(require_main2(), 1);
69245
69250
  var graphql19 = __toESM(require("graphql"), 1);
69246
69251
  var recast7 = __toESM(require_main2(), 1);
69247
69252
  var AST8 = recast7.types.builders;
69248
- function addReferencedInputTypes(config, filepath, body, visitedTypes, missingScalars, rootType) {
69253
+ function addReferencedInputTypes(config, filepath, body, visitedTypes, missingScalars, rootType, input) {
69249
69254
  const { type } = unwrapType(config, rootType);
69250
69255
  if (graphql19.isScalarType(type)) {
69251
69256
  return;
@@ -69270,12 +69275,20 @@ function addReferencedInputTypes(config, filepath, body, visitedTypes, missingSc
69270
69275
  }
69271
69276
  const members = [];
69272
69277
  for (const field of Object.values(type.getFields())) {
69273
- addReferencedInputTypes(config, filepath, body, visitedTypes, missingScalars, field.type);
69278
+ addReferencedInputTypes(
69279
+ config,
69280
+ filepath,
69281
+ body,
69282
+ visitedTypes,
69283
+ missingScalars,
69284
+ field.type,
69285
+ input
69286
+ );
69274
69287
  members.push(
69275
69288
  AST8.tsPropertySignature(
69276
69289
  AST8.identifier(field.name),
69277
69290
  AST8.tsTypeAnnotation(
69278
- tsTypeReference(config, filepath, missingScalars, field, body)
69291
+ tsTypeReference(config, filepath, missingScalars, field, body, input)
69279
69292
  ),
69280
69293
  graphql19.isNullableType(field.type)
69281
69294
  )
@@ -69318,7 +69331,8 @@ function inlineType({
69318
69331
  includeFragments,
69319
69332
  allOptional,
69320
69333
  forceNonNull,
69321
- field
69334
+ field,
69335
+ input
69322
69336
  }) {
69323
69337
  const { type, wrappers } = unwrapType(config, rootType);
69324
69338
  let result;
@@ -69330,7 +69344,8 @@ function inlineType({
69330
69344
  missingScalars,
69331
69345
  type,
69332
69346
  body,
69333
- field
69347
+ field,
69348
+ input
69334
69349
  );
69335
69350
  } else if (graphql20.isEnumType(type)) {
69336
69351
  ensureImports({
@@ -69438,7 +69453,8 @@ function inlineType({
69438
69453
  field: {
69439
69454
  field: attributeName,
69440
69455
  parent: type.name
69441
- }
69456
+ },
69457
+ input
69442
69458
  });
69443
69459
  const hasIncludeOrSkipDirective = selection.directives && selection.directives.filter(
69444
69460
  (directive) => directive.name.value === "include" || directive.name.value === "skip"
@@ -69502,7 +69518,8 @@ function inlineType({
69502
69518
  missingScalars,
69503
69519
  includeFragments,
69504
69520
  allOptional,
69505
- field: null
69521
+ field: null,
69522
+ input: false
69506
69523
  });
69507
69524
  let objectType = fragmentType;
69508
69525
  if (fragmentType.type === "TSUnionType") {
@@ -69967,7 +69984,8 @@ async function generateOperationTypeDefs(config, filepath, document, body, defin
69967
69984
  body,
69968
69985
  missingScalars,
69969
69986
  includeFragments: true,
69970
- field: null
69987
+ field: null,
69988
+ input: false
69971
69989
  });
69972
69990
  if (artifact.kind === "HoudiniQuery") {
69973
69991
  resultType = withLoadingState({
@@ -70016,7 +70034,8 @@ async function generateOperationTypeDefs(config, filepath, document, body, defin
70016
70034
  body,
70017
70035
  visitedTypes,
70018
70036
  missingScalars,
70019
- variableDefinition.type
70037
+ variableDefinition.type,
70038
+ true
70020
70039
  );
70021
70040
  }
70022
70041
  body.push(
@@ -70034,7 +70053,8 @@ async function generateOperationTypeDefs(config, filepath, document, body, defin
70034
70053
  filepath,
70035
70054
  missingScalars,
70036
70055
  definition2,
70037
- body
70056
+ body,
70057
+ true
70038
70058
  )
70039
70059
  ),
70040
70060
  definition2.type.kind !== "NonNullType"
@@ -70069,7 +70089,8 @@ async function generateOperationTypeDefs(config, filepath, document, body, defin
70069
70089
  missingScalars,
70070
70090
  includeFragments: false,
70071
70091
  allOptional: true,
70072
- field: null
70092
+ field: null,
70093
+ input: false
70073
70094
  })
70074
70095
  )
70075
70096
  )
@@ -70102,7 +70123,8 @@ async function generateFragmentTypeDefs(config, filepath, body, selections, defi
70102
70123
  filepath,
70103
70124
  missingScalars,
70104
70125
  definition2,
70105
- body
70126
+ body,
70127
+ false
70106
70128
  )
70107
70129
  ),
70108
70130
  definition2.type.kind !== "NonNullType"
@@ -70165,7 +70187,8 @@ async function generateFragmentTypeDefs(config, filepath, body, selections, defi
70165
70187
  visitedTypes,
70166
70188
  missingScalars,
70167
70189
  includeFragments: true,
70168
- field: null
70190
+ field: null,
70191
+ input: false
70169
70192
  })
70170
70193
  })
70171
70194
  )
@@ -70261,7 +70284,8 @@ function typeDefinitions(config, filepath, body, docs, returnType) {
70261
70284
  {
70262
70285
  field: key,
70263
70286
  parent: type.name
70264
- }
70287
+ },
70288
+ false
70265
70289
  )
70266
70290
  )
70267
70291
  );
@@ -70288,7 +70312,8 @@ function typeDefinitions(config, filepath, body, docs, returnType) {
70288
70312
  {
70289
70313
  field: key,
70290
70314
  parent: type.name
70291
- }
70315
+ },
70316
+ false
70292
70317
  )
70293
70318
  );
70294
70319
  } else if (graphql21.isEnumType(unwrapped.type)) {
@@ -70326,7 +70351,8 @@ function typeDefinitions(config, filepath, body, docs, returnType) {
70326
70351
  body,
70327
70352
  visitedTypes,
70328
70353
  /* @__PURE__ */ new Set(),
70329
- arg.type
70354
+ arg.type,
70355
+ true
70330
70356
  );
70331
70357
  const prop = AST13.tsPropertySignature(
70332
70358
  AST13.identifier(arg.name),
@@ -70336,7 +70362,8 @@ function typeDefinitions(config, filepath, body, docs, returnType) {
70336
70362
  filepath,
70337
70363
  /* @__PURE__ */ new Set(),
70338
70364
  arg,
70339
- body
70365
+ body,
70366
+ graphql21.isInputType(arg.type)
70340
70367
  )
70341
70368
  )
70342
70369
  );
@@ -70448,7 +70475,8 @@ function listDefinitions(config, filepath, body, docs) {
70448
70475
  filepath,
70449
70476
  /* @__PURE__ */ new Set(),
70450
70477
  arg,
70451
- body
70478
+ body,
70479
+ graphql21.isInputType(arg.type)
70452
70480
  )
70453
70481
  )
70454
70482
  );