houdini 2.0.0-next.1 → 2.0.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/adapter/index.d.ts +1 -1
- package/build/cmd-cjs/index.js +10068 -10551
- package/build/cmd-esm/index.js +10065 -10548
- package/build/codegen/generators/typescript/addReferencedInputTypes.d.ts +1 -1
- package/build/codegen/generators/typescript/inlineType.d.ts +2 -1
- package/build/codegen-cjs/index.js +9887 -10448
- package/build/codegen-esm/index.js +9884 -10445
- package/build/lib/fs.d.ts +2 -2
- package/build/lib/types.d.ts +3 -3
- package/build/lib/typescript.d.ts +3 -3
- package/build/lib-cjs/index.js +9394 -10158
- package/build/lib-esm/index.js +9394 -10158
- package/build/runtime/lib/types.d.ts +2 -2
- package/build/runtime/public/cache.d.ts +0 -1
- package/build/runtime/router/cookies.d.ts +9 -9
- package/build/runtime/router/server.d.ts +6 -6
- package/build/runtime/router/session.d.ts +1 -0
- package/build/runtime/server/index.d.ts +17 -0
- package/build/runtime-cjs/cache/cache.js +36 -29
- package/build/runtime-cjs/client/documentStore.js +2 -2
- package/build/runtime-cjs/client/index.js +1 -1
- package/build/runtime-cjs/client/plugins/test.js +2 -2
- package/build/runtime-cjs/lib/types.d.ts +2 -2
- package/build/runtime-cjs/public/cache.d.ts +0 -1
- package/build/runtime-cjs/public/cache.js +0 -14
- package/build/runtime-cjs/router/cookies.d.ts +9 -9
- package/build/runtime-cjs/router/cookies.js +1 -1
- package/build/runtime-cjs/router/server.d.ts +6 -6
- package/build/runtime-cjs/router/server.js +32 -17
- package/build/runtime-cjs/router/session.d.ts +1 -0
- package/build/runtime-cjs/router/session.js +7 -2
- package/build/runtime-cjs/server/index.d.ts +17 -0
- package/build/runtime-cjs/server/index.js +62 -0
- package/build/runtime-esm/cache/cache.js +36 -29
- package/build/runtime-esm/client/documentStore.js +2 -2
- package/build/runtime-esm/client/index.js +1 -1
- package/build/runtime-esm/client/plugins/test.js +2 -2
- package/build/runtime-esm/lib/types.d.ts +2 -2
- package/build/runtime-esm/public/cache.d.ts +0 -1
- package/build/runtime-esm/public/cache.js +0 -14
- package/build/runtime-esm/router/cookies.d.ts +9 -9
- package/build/runtime-esm/router/cookies.js +1 -1
- package/build/runtime-esm/router/server.d.ts +6 -6
- package/build/runtime-esm/router/server.js +36 -21
- package/build/runtime-esm/router/session.d.ts +1 -0
- package/build/runtime-esm/router/session.js +5 -1
- package/build/runtime-esm/server/index.d.ts +17 -0
- package/build/runtime-esm/server/index.js +38 -0
- package/build/test-cjs/index.js +9885 -10447
- package/build/test-esm/index.js +9882 -10444
- package/build/vite/hmr.d.ts +0 -2
- package/build/vite-cjs/index.js +9804 -10365
- package/build/vite-esm/index.js +9801 -10362
- 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
|
|
376
|
-
|
|
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
|
|
33
|
-
maxAge
|
|
34
|
-
domain
|
|
35
|
-
path
|
|
36
|
-
expires
|
|
37
|
-
httpOnly
|
|
38
|
-
priority
|
|
39
|
-
secure
|
|
40
|
-
sameSite
|
|
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
|
|
2
|
-
import {
|
|
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,
|
|
6
|
+
export declare function _serverHandler<ComponentType = unknown>({ schema, server, client, production, manifest, graphqlEndpoint, on_render, componentCache, }: {
|
|
7
7
|
schema?: GraphQLSchema | null;
|
|
8
|
-
|
|
8
|
+
server?: Server<any, any>;
|
|
9
9
|
client: HoudiniClient;
|
|
10
10
|
production: boolean;
|
|
11
11
|
manifest: RouterManifest<ComponentType> | null;
|
|
@@ -20,5 +20,5 @@ export declare function _serverHandler<ComponentType = unknown>({ schema, yoga,
|
|
|
20
20
|
componentCache: Record<string, any>;
|
|
21
21
|
}) => Response | Promise<Response | undefined> | undefined;
|
|
22
22
|
} & Omit<YogaServerOptions, 'schema'>): (request: Request) => Promise<Response>;
|
|
23
|
-
export declare const serverAdapterFactory: (args: Parameters<typeof _serverHandler>[0]) => ReturnType<typeof
|
|
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
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
-
|
|
450
|
-
const
|
|
451
|
-
for (const id of
|
|
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 (
|
|
457
|
+
if (!node) {
|
|
457
458
|
continue;
|
|
458
459
|
}
|
|
459
|
-
|
|
460
|
+
const nodeID = this.storage.get(node, "id");
|
|
461
|
+
if (!nodeID) {
|
|
460
462
|
continue;
|
|
461
463
|
}
|
|
462
|
-
|
|
464
|
+
existingIDs.add(nodeID.value);
|
|
463
465
|
}
|
|
464
|
-
|
|
466
|
+
return insert.filter((id) => {
|
|
465
467
|
if (!id) {
|
|
466
468
|
return true;
|
|
467
469
|
}
|
|
468
|
-
const { value:
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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
|
|
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(
|
|
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 ? "" : `
|
|
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
|
|
376
|
-
|
|
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
|
|
33
|
-
maxAge
|
|
34
|
-
domain
|
|
35
|
-
path
|
|
36
|
-
expires
|
|
37
|
-
httpOnly
|
|
38
|
-
priority
|
|
39
|
-
secure
|
|
40
|
-
sameSite
|
|
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
|
|
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
|
|
2
|
-
import {
|
|
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,
|
|
6
|
+
export declare function _serverHandler<ComponentType = unknown>({ schema, server, client, production, manifest, graphqlEndpoint, on_render, componentCache, }: {
|
|
7
7
|
schema?: GraphQLSchema | null;
|
|
8
|
-
|
|
8
|
+
server?: Server<any, any>;
|
|
9
9
|
client: HoudiniClient;
|
|
10
10
|
production: boolean;
|
|
11
11
|
manifest: RouterManifest<ComponentType> | null;
|
|
@@ -20,5 +20,5 @@ export declare function _serverHandler<ComponentType = unknown>({ schema, yoga,
|
|
|
20
20
|
componentCache: Record<string, any>;
|
|
21
21
|
}) => Response | Promise<Response | undefined> | undefined;
|
|
22
22
|
} & Omit<YogaServerOptions, 'schema'>): (request: Request) => Promise<Response>;
|
|
23
|
-
export declare const serverAdapterFactory: (args: Parameters<typeof _serverHandler>[0]) => ReturnType<typeof
|
|
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
|
-
|
|
35
|
+
server,
|
|
36
36
|
client,
|
|
37
37
|
production,
|
|
38
38
|
manifest,
|
|
@@ -40,23 +40,38 @@ function _serverHandler({
|
|
|
40
40
|
on_render,
|
|
41
41
|
componentCache
|
|
42
42
|
}) {
|
|
43
|
-
if (schema && !
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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 (
|
|
57
|
+
if (requestHandler) {
|
|
52
58
|
client.registerProxy(graphqlEndpoint, async ({ query, variables, session }) => {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
77
|
return async (request) => {
|
|
@@ -67,8 +82,8 @@ function _serverHandler({
|
|
|
67
82
|
);
|
|
68
83
|
}
|
|
69
84
|
const url = new URL(request.url).pathname;
|
|
70
|
-
if (
|
|
71
|
-
return
|
|
85
|
+
if (requestHandler && url === graphqlEndpoint) {
|
|
86
|
+
return requestHandler(request);
|
|
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
|
+
});
|