houdini 2.0.0-next.1 → 2.0.0-next.11

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.
Files changed (54) hide show
  1. package/build/adapter/index.d.ts +1 -1
  2. package/build/cmd-cjs/index.js +10068 -10551
  3. package/build/cmd-esm/index.js +10065 -10548
  4. package/build/codegen/generators/typescript/addReferencedInputTypes.d.ts +1 -1
  5. package/build/codegen/generators/typescript/inlineType.d.ts +2 -1
  6. package/build/codegen-cjs/index.js +9887 -10448
  7. package/build/codegen-esm/index.js +9884 -10445
  8. package/build/lib/fs.d.ts +2 -2
  9. package/build/lib/types.d.ts +3 -3
  10. package/build/lib/typescript.d.ts +3 -3
  11. package/build/lib-cjs/index.js +9394 -10158
  12. package/build/lib-esm/index.js +9394 -10158
  13. package/build/runtime/lib/types.d.ts +2 -2
  14. package/build/runtime/public/cache.d.ts +0 -1
  15. package/build/runtime/router/cookies.d.ts +9 -9
  16. package/build/runtime/router/server.d.ts +7 -7
  17. package/build/runtime/router/session.d.ts +1 -0
  18. package/build/runtime/server/index.d.ts +17 -0
  19. package/build/runtime-cjs/cache/cache.js +36 -29
  20. package/build/runtime-cjs/client/documentStore.js +2 -2
  21. package/build/runtime-cjs/client/index.js +1 -1
  22. package/build/runtime-cjs/client/plugins/test.js +2 -2
  23. package/build/runtime-cjs/lib/types.d.ts +2 -2
  24. package/build/runtime-cjs/public/cache.d.ts +0 -1
  25. package/build/runtime-cjs/public/cache.js +0 -14
  26. package/build/runtime-cjs/router/cookies.d.ts +9 -9
  27. package/build/runtime-cjs/router/cookies.js +1 -1
  28. package/build/runtime-cjs/router/server.d.ts +7 -7
  29. package/build/runtime-cjs/router/server.js +33 -18
  30. package/build/runtime-cjs/router/session.d.ts +1 -0
  31. package/build/runtime-cjs/router/session.js +7 -2
  32. package/build/runtime-cjs/server/index.d.ts +17 -0
  33. package/build/runtime-cjs/server/index.js +62 -0
  34. package/build/runtime-esm/cache/cache.js +36 -29
  35. package/build/runtime-esm/client/documentStore.js +2 -2
  36. package/build/runtime-esm/client/index.js +1 -1
  37. package/build/runtime-esm/client/plugins/test.js +2 -2
  38. package/build/runtime-esm/lib/types.d.ts +2 -2
  39. package/build/runtime-esm/public/cache.d.ts +0 -1
  40. package/build/runtime-esm/public/cache.js +0 -14
  41. package/build/runtime-esm/router/cookies.d.ts +9 -9
  42. package/build/runtime-esm/router/cookies.js +1 -1
  43. package/build/runtime-esm/router/server.d.ts +7 -7
  44. package/build/runtime-esm/router/server.js +37 -22
  45. package/build/runtime-esm/router/session.d.ts +1 -0
  46. package/build/runtime-esm/router/session.js +5 -1
  47. package/build/runtime-esm/server/index.d.ts +17 -0
  48. package/build/runtime-esm/server/index.js +38 -0
  49. package/build/test-cjs/index.js +9885 -10447
  50. package/build/test-esm/index.js +9882 -10444
  51. package/build/vite/hmr.d.ts +0 -2
  52. package/build/vite-cjs/index.js +9805 -10366
  53. package/build/vite-esm/index.js +9802 -10363
  54. package/package.json +4 -4
@@ -372,8 +372,8 @@ export type ProjectManifest = {
372
372
  artifacts: string[];
373
373
  /** Whether or not there is a local schema defined */
374
374
  local_schema: boolean;
375
- /** Whether or not there is a custom instance of yoga defined */
376
- local_yoga: boolean;
375
+ /** Whether or not there is a custom server defined */
376
+ local_server: boolean;
377
377
  /** Information about componentFields defined in the project */
378
378
  component_fields: Record<string, {
379
379
  filepath: string;
@@ -6,7 +6,6 @@ import type { ArgType, CacheTypeDef, IDFields, QueryInput, QueryList, QueryValue
6
6
  export declare class Cache<Def extends CacheTypeDef> {
7
7
  _internal_unstable: _Cache;
8
8
  constructor(cache: _Cache);
9
- validateInstabilityWarning(): void;
10
9
  get<T extends TypeNames<Def>>(type: T, data: IDFields<Def, T>): Record<Def, T>;
11
10
  get config(): import("../lib").ConfigFile;
12
11
  list<Name extends ValidLists<Def>>(name: Name, { parentID, allLists }?: {
@@ -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;
@@ -1,11 +1,11 @@
1
- import { createServerAdapter as createAdapter } from '@whatwg-node/server';
2
- import { type GraphQLSchema } from 'graphql';
3
- import { createYoga } from 'graphql-yoga';
1
+ import { createServerAdapter } from '@whatwg-node/server';
2
+ import type { GraphQLSchema } from 'graphql';
4
3
  import type { HoudiniClient } from '../client';
4
+ import { Server } from '../server';
5
5
  import type { RouterManifest, RouterPageManifest, YogaServerOptions } from './types';
6
- export declare function _serverHandler<ComponentType = unknown>({ schema, yoga, client, production, manifest, graphqlEndpoint, on_render, componentCache, }: {
6
+ export declare function _serverHandler<ComponentType = unknown>({ schema, server, client, production, manifest, graphqlEndpoint, on_render, componentCache, }: {
7
7
  schema?: GraphQLSchema | null;
8
- yoga?: ReturnType<typeof createYoga> | null;
8
+ server?: Server<any, any>;
9
9
  client: HoudiniClient;
10
10
  production: boolean;
11
11
  manifest: RouterManifest<ComponentType> | null;
@@ -19,6 +19,6 @@ export declare function _serverHandler<ComponentType = unknown>({ schema, yoga,
19
19
  session: App.Session;
20
20
  componentCache: Record<string, any>;
21
21
  }) => Response | Promise<Response | undefined> | undefined;
22
- } & Omit<YogaServerOptions, 'schema'>): (request: Request) => Promise<Response>;
23
- export declare const serverAdapterFactory: (args: Parameters<typeof _serverHandler>[0]) => ReturnType<typeof createAdapter>;
22
+ } & Omit<YogaServerOptions, 'schema'>): (request: Request, ...extraContext: Array<any>) => Promise<Response>;
23
+ export declare const serverAdapterFactory: (args: Parameters<typeof _serverHandler>[0]) => ReturnType<typeof createServerAdapter>;
24
24
  export type ServerAdapterFactory = typeof serverAdapterFactory;
@@ -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 {};
@@ -0,0 +1,17 @@
1
+ import type { ServerAdapterRequestHandler } from '@whatwg-node/server';
2
+ import { YogaServer } from 'graphql-yoga';
3
+ import type { YogaSchemaDefinition } from 'graphql-yoga/typings/plugins/use-schema';
4
+ type YogaParams = Required<ConstructorParameters<typeof YogaServer>>[0];
5
+ type ConstructorParams = Omit<YogaParams, 'schema' | 'graphqlEndpoint'>;
6
+ export declare class Server<ServerContext extends Record<string, any>, UserContext extends Record<string, any>> {
7
+ opts: ConstructorParams | null;
8
+ _yoga: YogaServer<any, any> | null;
9
+ constructor(opts?: ConstructorParams);
10
+ init({ endpoint, schema, getSession, }: {
11
+ schema: YogaSchemaDefinition<any, any>;
12
+ endpoint: string;
13
+ getSession: (request: Request) => Promise<UserContext>;
14
+ }): import("@whatwg-node/server").ServerAdapter<ServerContext, Server<ServerContext, UserContext>>;
15
+ handle: ServerAdapterRequestHandler<ServerContext>;
16
+ }
17
+ export {};
@@ -414,20 +414,21 @@ class CacheInternal {
414
414
  } else if (Array.isArray(value) && // make typescript happy
415
415
  (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
416
416
  let oldIDs = [...previousValue || []];
417
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
418
- if (!id) {
419
- return "";
420
- }
421
- const { value: cursorField } = this.storage.get(id, "cursor");
422
- if (cursorField) {
423
- return "";
424
- }
425
- const { value: node } = this.storage.get(id, "node");
426
- if (!node) {
427
- return "";
428
- }
429
- return node;
430
- });
417
+ if (updates?.includes("append") || updates?.includes("prepend")) {
418
+ oldIDs = oldIDs.filter((id) => {
419
+ for (const layer2 of this.storage.data) {
420
+ for (const operation of Object.values(layer2.operations)) {
421
+ if (operation.fields?.[key])
422
+ for (const listOperation of operation.fields[key]) {
423
+ if ("id" in listOperation && listOperation.id === id) {
424
+ return false;
425
+ }
426
+ }
427
+ }
428
+ }
429
+ return true;
430
+ });
431
+ }
431
432
  let linkedIDs = [];
432
433
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
433
434
  value,
@@ -446,39 +447,45 @@ class CacheInternal {
446
447
  layer.writeLink(parent, key, linkedIDs);
447
448
  };
448
449
  if (applyUpdates && updates) {
449
- if (key === "edges") {
450
- const newNodeIDs = [];
451
- for (const id of newIDs) {
450
+ const filterIDs = (keep, insert) => {
451
+ const existingIDs = /* @__PURE__ */ new Set();
452
+ for (const id of keep) {
452
453
  if (!id) {
453
454
  continue;
454
455
  }
455
456
  const { value: node } = this.storage.get(id, "node");
456
- if (typeof node !== "string") {
457
+ if (!node) {
457
458
  continue;
458
459
  }
459
- if (!node || !this.storage.get(node, "__typename")) {
460
+ const nodeID = this.storage.get(node, "id");
461
+ if (!nodeID) {
460
462
  continue;
461
463
  }
462
- newNodeIDs.push(node);
464
+ existingIDs.add(nodeID.value);
463
465
  }
464
- oldIDs = oldIDs.filter((id) => {
466
+ return insert.filter((id) => {
465
467
  if (!id) {
466
468
  return true;
467
469
  }
468
- const { value: value2 } = this.storage.get(id, "node");
469
- const node = value2;
470
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
471
- return false;
470
+ const { value: node } = this.storage.get(id, "node");
471
+ if (!node) {
472
+ return true;
473
+ }
474
+ const nodeID = this.storage.get(node, "id");
475
+ if (!nodeID) {
476
+ return true;
472
477
  }
473
- return true;
478
+ return !existingIDs.has(nodeID.value);
474
479
  });
475
- }
480
+ };
476
481
  for (const update of applyUpdates) {
477
482
  if (update !== "replace" && !updates.includes(update)) {
478
483
  continue;
479
484
  }
480
485
  if (update === "prepend") {
481
- linkedIDs = newIDs.concat(oldIDs);
486
+ linkedIDs = newIDs.concat(
487
+ filterIDs(newIDs, oldIDs)
488
+ );
482
489
  if (layer?.optimistic) {
483
490
  action = () => {
484
491
  for (const id of newIDs) {
@@ -489,7 +496,7 @@ class CacheInternal {
489
496
  };
490
497
  }
491
498
  } else if (update === "append") {
492
- linkedIDs = oldIDs.concat(newIDs);
499
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
493
500
  if (layer?.optimistic) {
494
501
  action = () => {
495
502
  for (const id of newIDs) {
@@ -288,9 +288,9 @@ class DocumentStore extends import_store.Writable {
288
288
  handlers = {
289
289
  ...common,
290
290
  value,
291
- resolve: (ctx2, data) => {
291
+ resolve: ((ctx2, data) => {
292
292
  return common.resolve(ctx2, data ?? value);
293
- }
293
+ })
294
294
  };
295
295
  } else if (direction === "error") {
296
296
  handlers = {
@@ -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;
@@ -100,7 +100,7 @@ function fakeFetch({
100
100
  partial: false,
101
101
  stale: false
102
102
  };
103
- return () => ({
103
+ return (() => ({
104
104
  network(ctx, { resolve }) {
105
105
  spy?.(ctx);
106
106
  if (onRequest) {
@@ -109,7 +109,7 @@ function fakeFetch({
109
109
  resolve(ctx, { ...result });
110
110
  }
111
111
  }
112
- });
112
+ }));
113
113
  }
114
114
  // Annotate the CommonJS export names for ESM import in node:
115
115
  0 && (module.exports = {
@@ -372,8 +372,8 @@ export type ProjectManifest = {
372
372
  artifacts: string[];
373
373
  /** Whether or not there is a local schema defined */
374
374
  local_schema: boolean;
375
- /** Whether or not there is a custom instance of yoga defined */
376
- local_yoga: boolean;
375
+ /** Whether or not there is a custom server defined */
376
+ local_server: boolean;
377
377
  /** Information about componentFields defined in the project */
378
378
  component_fields: Record<string, {
379
379
  filepath: string;
@@ -6,7 +6,6 @@ import type { ArgType, CacheTypeDef, IDFields, QueryInput, QueryList, QueryValue
6
6
  export declare class Cache<Def extends CacheTypeDef> {
7
7
  _internal_unstable: _Cache;
8
8
  constructor(cache: _Cache);
9
- validateInstabilityWarning(): void;
10
9
  get<T extends TypeNames<Def>>(type: T, data: IDFields<Def, T>): Record<Def, T>;
11
10
  get config(): import("../lib").ConfigFile;
12
11
  list<Name extends ValidLists<Def>>(name: Name, { parentID, allLists }?: {
@@ -29,19 +29,8 @@ class Cache {
29
29
  constructor(cache) {
30
30
  this._internal_unstable = cache;
31
31
  }
32
- // if the user is using the imperative API, we want the ability to break the API
33
- // with any minor version. In order to do this, we require them to accept this contract
34
- // through their config file
35
- validateInstabilityWarning() {
36
- if (!this.config.acceptImperativeInstability && !this.config.features?.imperativeCache) {
37
- console.warn(`\u26A0\uFE0F The imperative cache API is considered unstable and will change in any minor version release
38
- Please acknowledge this by enabling the imperative cache feature flage in your config file.
39
- For more information: https://houdinigraphql.com/api/cache`);
40
- }
41
- }
42
32
  // return the record proxy for the given type/id combo
43
33
  get(type, data) {
44
- this.validateInstabilityWarning();
45
34
  let recordID = this._internal_unstable._internal_unstable.id(type, data);
46
35
  if (!recordID) {
47
36
  throw new Error("todo");
@@ -57,7 +46,6 @@ For more information: https://houdinigraphql.com/api/cache`);
57
46
  return (0, import_lib.getCurrentConfig)();
58
47
  }
59
48
  list(name, { parentID, allLists } = {}) {
60
- this.validateInstabilityWarning();
61
49
  return new import_list.ListCollection({
62
50
  cache: this,
63
51
  name,
@@ -69,7 +57,6 @@ For more information: https://houdinigraphql.com/api/cache`);
69
57
  query,
70
58
  variables
71
59
  }) {
72
- this.validateInstabilityWarning();
73
60
  return this._internal_unstable.read({
74
61
  selection: query.artifact.selection,
75
62
  variables
@@ -80,7 +67,6 @@ For more information: https://houdinigraphql.com/api/cache`);
80
67
  variables,
81
68
  data
82
69
  }) {
83
- this.validateInstabilityWarning();
84
70
  this._internal_unstable.write({
85
71
  selection: query.artifact.selection,
86
72
  // @ts-expect-error
@@ -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,11 +1,11 @@
1
- import { createServerAdapter as createAdapter } from '@whatwg-node/server';
2
- import { type GraphQLSchema } from 'graphql';
3
- import { createYoga } from 'graphql-yoga';
1
+ import { createServerAdapter } from '@whatwg-node/server';
2
+ import type { GraphQLSchema } from 'graphql';
4
3
  import type { HoudiniClient } from '../client';
4
+ import { Server } from '../server';
5
5
  import type { RouterManifest, RouterPageManifest, YogaServerOptions } from './types';
6
- export declare function _serverHandler<ComponentType = unknown>({ schema, yoga, client, production, manifest, graphqlEndpoint, on_render, componentCache, }: {
6
+ export declare function _serverHandler<ComponentType = unknown>({ schema, server, client, production, manifest, graphqlEndpoint, on_render, componentCache, }: {
7
7
  schema?: GraphQLSchema | null;
8
- yoga?: ReturnType<typeof createYoga> | null;
8
+ server?: Server<any, any>;
9
9
  client: HoudiniClient;
10
10
  production: boolean;
11
11
  manifest: RouterManifest<ComponentType> | null;
@@ -19,6 +19,6 @@ export declare function _serverHandler<ComponentType = unknown>({ schema, yoga,
19
19
  session: App.Session;
20
20
  componentCache: Record<string, any>;
21
21
  }) => Response | Promise<Response | undefined> | undefined;
22
- } & Omit<YogaServerOptions, 'schema'>): (request: Request) => Promise<Response>;
23
- export declare const serverAdapterFactory: (args: Parameters<typeof _serverHandler>[0]) => ReturnType<typeof createAdapter>;
22
+ } & Omit<YogaServerOptions, 'schema'>): (request: Request, ...extraContext: Array<any>) => Promise<Response>;
23
+ export declare const serverAdapterFactory: (args: Parameters<typeof _serverHandler>[0]) => ReturnType<typeof createServerAdapter>;
24
24
  export type ServerAdapterFactory = typeof serverAdapterFactory;
@@ -23,16 +23,16 @@ __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
- var import_graphql_yoga = require("graphql-yoga");
28
26
  var import_config = require("../lib/config");
27
+ var import_server2 = require("../server");
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)();
32
32
  const session_keys = (0, import_config.localApiSessionKeys)(config_file);
33
33
  function _serverHandler({
34
34
  schema,
35
- yoga,
35
+ server,
36
36
  client,
37
37
  production,
38
38
  manifest,
@@ -40,26 +40,41 @@ function _serverHandler({
40
40
  on_render,
41
41
  componentCache
42
42
  }) {
43
- if (schema && !yoga) {
44
- yoga = (0, import_graphql_yoga.createYoga)({
43
+ if (schema && !server) {
44
+ server = new import_server2.Server({
45
+ landingPage: !production
46
+ });
47
+ }
48
+ let requestHandler = null;
49
+ if (server && schema) {
50
+ requestHandler = server.init({
45
51
  schema,
46
- landingPage: !production,
47
- graphqlEndpoint
52
+ endpoint: graphqlEndpoint,
53
+ getSession: (request) => (0, import_session.get_session)(request.headers, session_keys)
48
54
  });
49
55
  }
50
56
  client.componentCache = componentCache;
51
- if (schema) {
57
+ if (requestHandler) {
52
58
  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
- });
59
+ const response = await requestHandler(
60
+ new Request(`http://localhost/${graphqlEndpoint}`, {
61
+ method: "POST",
62
+ headers: {
63
+ "Content-Type": "application/json",
64
+ Cookie: (0, import_cookies.serialize)(import_session.session_cookie_name, JSON.stringify(session ?? {}), {
65
+ httpOnly: true
66
+ })
67
+ },
68
+ body: JSON.stringify({
69
+ query,
70
+ variables
71
+ })
72
+ })
73
+ );
74
+ return await response.json();
60
75
  });
61
76
  }
62
- return async (request) => {
77
+ return async (request, ...extraContext) => {
63
78
  if (!manifest) {
64
79
  return new Response(
65
80
  "Adapter did not provide the project's manifest. Please open an issue on github.",
@@ -67,8 +82,8 @@ function _serverHandler({
67
82
  );
68
83
  }
69
84
  const url = new URL(request.url).pathname;
70
- if (yoga && url === (0, import_config.localApiEndpoint)(config_file)) {
71
- return yoga(request);
85
+ if (requestHandler && url === graphqlEndpoint) {
86
+ return requestHandler(request, ...extraContext);
72
87
  }
73
88
  const authResponse = await (0, import_session.handle_request)({
74
89
  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");
@@ -76,6 +77,9 @@ async function get_session(req, secrets) {
76
77
  if (!cookie) {
77
78
  return {};
78
79
  }
80
+ if (cookie === "{}") {
81
+ return {};
82
+ }
79
83
  for (const secret of secrets) {
80
84
  if (!await (0, import_jwt.verify)(cookie, secret)) {
81
85
  continue;
@@ -91,5 +95,6 @@ async function get_session(req, secrets) {
91
95
  // Annotate the CommonJS export names for ESM import in node:
92
96
  0 && (module.exports = {
93
97
  get_session,
94
- handle_request
98
+ handle_request,
99
+ session_cookie_name
95
100
  });
@@ -0,0 +1,17 @@
1
+ import type { ServerAdapterRequestHandler } from '@whatwg-node/server';
2
+ import { YogaServer } from 'graphql-yoga';
3
+ import type { YogaSchemaDefinition } from 'graphql-yoga/typings/plugins/use-schema';
4
+ type YogaParams = Required<ConstructorParameters<typeof YogaServer>>[0];
5
+ type ConstructorParams = Omit<YogaParams, 'schema' | 'graphqlEndpoint'>;
6
+ export declare class Server<ServerContext extends Record<string, any>, UserContext extends Record<string, any>> {
7
+ opts: ConstructorParams | null;
8
+ _yoga: YogaServer<any, any> | null;
9
+ constructor(opts?: ConstructorParams);
10
+ init({ endpoint, schema, getSession, }: {
11
+ schema: YogaSchemaDefinition<any, any>;
12
+ endpoint: string;
13
+ getSession: (request: Request) => Promise<UserContext>;
14
+ }): import("@whatwg-node/server").ServerAdapter<ServerContext, Server<ServerContext, UserContext>>;
15
+ handle: ServerAdapterRequestHandler<ServerContext>;
16
+ }
17
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var server_exports = {};
20
+ __export(server_exports, {
21
+ Server: () => Server
22
+ });
23
+ module.exports = __toCommonJS(server_exports);
24
+ var import_server = require("@whatwg-node/server");
25
+ var import_graphql_yoga = require("graphql-yoga");
26
+ class Server {
27
+ opts;
28
+ _yoga = null;
29
+ constructor(opts) {
30
+ this.opts = opts ?? null;
31
+ }
32
+ init({
33
+ endpoint,
34
+ schema,
35
+ getSession
36
+ }) {
37
+ this._yoga = new import_graphql_yoga.YogaServer({
38
+ ...this.opts,
39
+ schema,
40
+ graphqlEndpoint: endpoint,
41
+ context: async (ctx) => {
42
+ const userContext = !this.opts ? {} : typeof this.opts.context === "function" ? await this.opts.context(ctx) : this.opts.context || {};
43
+ const sessionContext = await getSession(ctx.request) || {};
44
+ return {
45
+ ...userContext,
46
+ session: sessionContext
47
+ };
48
+ }
49
+ });
50
+ return (0, import_server.createServerAdapter)(this, {
51
+ fetchAPI: this._yoga.fetchAPI,
52
+ plugins: this._yoga["plugins"]
53
+ });
54
+ }
55
+ handle = (request, serverContext) => {
56
+ return this._yoga.handle(request, serverContext);
57
+ };
58
+ }
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ Server
62
+ });