houdini 1.2.43 → 1.2.45
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/cmd-cjs/index.js +684 -786
- package/build/cmd-esm/index.js +534 -636
- package/build/codegen/generators/artifacts/inputs.d.ts +1 -1
- package/build/codegen/generators/comments/jsdoc.d.ts +2 -0
- package/build/codegen/transforms/index.d.ts +1 -0
- package/build/codegen/transforms/runtimeScalars.d.ts +2 -0
- package/build/codegen-cjs/index.js +677 -782
- package/build/codegen-esm/index.js +527 -632
- package/build/lib/config.d.ts +1 -0
- package/build/lib/graphql.d.ts +1 -1
- package/build/lib/index.d.ts +1 -0
- package/build/lib/typescript.d.ts +19 -0
- package/build/lib-cjs/index.js +711 -477
- package/build/lib-esm/index.js +705 -477
- package/build/runtime/client/index.d.ts +7 -1
- package/build/runtime/client/plugins/fragment.d.ts +2 -2
- package/build/runtime/client/plugins/mutation.d.ts +2 -1
- package/build/runtime/client/plugins/query.d.ts +2 -2
- package/build/runtime/lib/config.d.ts +12 -2
- package/build/runtime/lib/scalars.d.ts +1 -1
- package/build/runtime/lib/types.d.ts +17 -2
- package/build/runtime/router/session.d.ts +1 -2
- package/build/runtime/router/types.d.ts +3 -1
- package/build/runtime-cjs/client/index.d.ts +7 -1
- package/build/runtime-cjs/client/index.js +26 -11
- package/build/runtime-cjs/client/plugins/fragment.d.ts +2 -2
- package/build/runtime-cjs/client/plugins/fragment.js +4 -11
- package/build/runtime-cjs/client/plugins/mutation.d.ts +2 -1
- package/build/runtime-cjs/client/plugins/mutation.js +8 -15
- package/build/runtime-cjs/client/plugins/query.d.ts +2 -2
- package/build/runtime-cjs/client/plugins/query.js +18 -11
- package/build/runtime-cjs/lib/config.d.ts +12 -2
- package/build/runtime-cjs/lib/scalars.d.ts +1 -1
- package/build/runtime-cjs/lib/scalars.js +4 -0
- package/build/runtime-cjs/lib/types.d.ts +17 -2
- package/build/runtime-cjs/router/server.js +2 -3
- package/build/runtime-cjs/router/session.d.ts +1 -2
- package/build/runtime-cjs/router/session.js +25 -11
- package/build/runtime-cjs/router/types.d.ts +3 -1
- package/build/runtime-esm/client/index.d.ts +7 -1
- package/build/runtime-esm/client/index.js +26 -11
- package/build/runtime-esm/client/plugins/fragment.d.ts +2 -2
- package/build/runtime-esm/client/plugins/fragment.js +1 -2
- package/build/runtime-esm/client/plugins/mutation.d.ts +2 -1
- package/build/runtime-esm/client/plugins/mutation.js +1 -2
- package/build/runtime-esm/client/plugins/query.d.ts +2 -2
- package/build/runtime-esm/client/plugins/query.js +15 -2
- package/build/runtime-esm/lib/config.d.ts +12 -2
- package/build/runtime-esm/lib/scalars.d.ts +1 -1
- package/build/runtime-esm/lib/scalars.js +6 -0
- package/build/runtime-esm/lib/types.d.ts +17 -2
- package/build/runtime-esm/router/server.js +2 -3
- package/build/runtime-esm/router/session.d.ts +1 -2
- package/build/runtime-esm/router/session.js +25 -11
- package/build/runtime-esm/router/types.d.ts +3 -1
- package/build/test-cjs/index.js +706 -785
- package/build/test-esm/index.js +556 -635
- package/build/vite-cjs/index.js +793 -793
- package/build/vite-esm/index.js +643 -643
- package/package.json +1 -1
- package/build/codegen/generators/typescript/typeReference.d.ts +0 -8
- package/build/codegen/generators/typescript/types.d.ts +0 -10
|
@@ -23,8 +23,12 @@ export type ObserveParams<_Data extends GraphQLObject, _Artifact extends Documen
|
|
|
23
23
|
};
|
|
24
24
|
export declare class HoudiniClient {
|
|
25
25
|
url: string;
|
|
26
|
-
readonly plugins: ClientPlugin[];
|
|
27
26
|
readonly throwOnError_operations: ThrowOnErrorOperations[];
|
|
27
|
+
private cache;
|
|
28
|
+
private throwOnError;
|
|
29
|
+
private fetchParams;
|
|
30
|
+
private pipeline;
|
|
31
|
+
private extraPlugins;
|
|
28
32
|
proxies: Record<string, (operation: {
|
|
29
33
|
query: string;
|
|
30
34
|
variables: any;
|
|
@@ -32,7 +36,9 @@ export declare class HoudiniClient {
|
|
|
32
36
|
session: App.Session | null | undefined;
|
|
33
37
|
}) => Promise<any>>;
|
|
34
38
|
componentCache: Record<string, any>;
|
|
39
|
+
setCache(cache: Cache): void;
|
|
35
40
|
constructor({ url, fetchParams, plugins, pipeline, throwOnError, }?: HoudiniClientConstructorArgs);
|
|
41
|
+
get plugins(): ClientPlugin[];
|
|
36
42
|
observe<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ enableCache, fetching, ...rest }: ObserveParams<_Data, DocumentArtifact, _Input>): DocumentStore<_Data, _Input>;
|
|
37
43
|
registerProxy(url: string, handler: (operation: {
|
|
38
44
|
query: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import cacheRef from "../cache";
|
|
1
2
|
import { getCurrentConfig, localApiEndpoint } from "../lib";
|
|
2
3
|
import { flatten } from "../lib/flatten";
|
|
3
4
|
import { DocumentStore } from "./documentStore";
|
|
@@ -14,10 +15,17 @@ import { DocumentStore as DocumentStore2 } from "./documentStore";
|
|
|
14
15
|
import { fetch, mutation, query, subscription } from "./plugins";
|
|
15
16
|
class HoudiniClient {
|
|
16
17
|
url;
|
|
17
|
-
plugins;
|
|
18
18
|
throwOnError_operations;
|
|
19
|
+
cache = null;
|
|
20
|
+
throwOnError;
|
|
21
|
+
fetchParams;
|
|
22
|
+
pipeline;
|
|
23
|
+
extraPlugins;
|
|
19
24
|
proxies = {};
|
|
20
25
|
componentCache = {};
|
|
26
|
+
setCache(cache) {
|
|
27
|
+
this.cache = cache;
|
|
28
|
+
}
|
|
21
29
|
constructor({
|
|
22
30
|
url,
|
|
23
31
|
fetchParams,
|
|
@@ -31,23 +39,29 @@ class HoudiniClient {
|
|
|
31
39
|
);
|
|
32
40
|
}
|
|
33
41
|
this.throwOnError_operations = throwOnError?.operations ?? [];
|
|
34
|
-
|
|
42
|
+
let serverPort = globalThis.process?.env?.HOUDINI_PORT ?? "5173";
|
|
43
|
+
this.url = url ?? (globalThis.window ? "" : `https://localhost:${serverPort}`) + localApiEndpoint(getCurrentConfig());
|
|
44
|
+
this.throwOnError = throwOnError;
|
|
45
|
+
this.fetchParams = fetchParams;
|
|
46
|
+
this.pipeline = pipeline;
|
|
47
|
+
this.extraPlugins = plugins;
|
|
48
|
+
}
|
|
49
|
+
get plugins() {
|
|
50
|
+
return flatten(
|
|
35
51
|
[].concat(
|
|
36
|
-
throwOnError ? [throwOnErrorPlugin(throwOnError)] : [],
|
|
37
|
-
fetchParamsPlugin(fetchParams),
|
|
38
|
-
pipeline ?? [
|
|
39
|
-
queryPlugin,
|
|
40
|
-
mutationPlugin,
|
|
41
|
-
fragmentPlugin
|
|
52
|
+
this.throwOnError ? [throwOnErrorPlugin(this.throwOnError)] : [],
|
|
53
|
+
fetchParamsPlugin(this.fetchParams),
|
|
54
|
+
this.pipeline ?? [
|
|
55
|
+
queryPlugin(this.cache ?? cacheRef),
|
|
56
|
+
mutationPlugin(this.cache ?? cacheRef),
|
|
57
|
+
fragmentPlugin(this.cache ?? cacheRef)
|
|
42
58
|
].concat(
|
|
43
|
-
|
|
59
|
+
this.extraPlugins ?? [],
|
|
44
60
|
pluginsFromPlugins,
|
|
45
61
|
fetchPlugin()
|
|
46
62
|
)
|
|
47
63
|
)
|
|
48
64
|
);
|
|
49
|
-
let serverPort = globalThis.process?.env?.HOUDINI_PORT ?? "5173";
|
|
50
|
-
this.url = url ?? (globalThis.window ? "" : `https://localhost:${serverPort}`) + localApiEndpoint(getCurrentConfig());
|
|
51
65
|
}
|
|
52
66
|
observe({
|
|
53
67
|
enableCache = true,
|
|
@@ -59,6 +73,7 @@ class HoudiniClient {
|
|
|
59
73
|
plugins: createPluginHooks(this.plugins),
|
|
60
74
|
fetching,
|
|
61
75
|
enableCache,
|
|
76
|
+
cache: this.cache ?? void 0,
|
|
62
77
|
...rest
|
|
63
78
|
});
|
|
64
79
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const fragment: ClientPlugin;
|
|
1
|
+
import type { Cache } from '../../cache/cache';
|
|
2
|
+
export declare const fragment: (cache: Cache) => import("..").ClientPlugin;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import cache from "../../cache";
|
|
2
1
|
import { deepEquals } from "../../lib/deepEquals";
|
|
3
2
|
import { ArtifactKind, DataSource } from "../../lib/types";
|
|
4
3
|
import { documentPlugin } from "../utils";
|
|
5
|
-
const fragment = documentPlugin(ArtifactKind.Fragment, function() {
|
|
4
|
+
const fragment = (cache) => documentPlugin(ArtifactKind.Fragment, function() {
|
|
6
5
|
let subscriptionSpec = null;
|
|
7
6
|
let lastReference = null;
|
|
8
7
|
return {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Cache } from '../../cache/cache';
|
|
2
|
+
export declare const mutation: (cache: Cache) => import("..").ClientPlugin;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import cache from "../../cache";
|
|
2
1
|
import { marshalSelection } from "../../lib/scalars";
|
|
3
2
|
import { ArtifactKind } from "../../lib/types";
|
|
4
3
|
import { documentPlugin } from "../utils";
|
|
5
|
-
const mutation = documentPlugin(ArtifactKind.Mutation, () => {
|
|
4
|
+
const mutation = (cache) => documentPlugin(ArtifactKind.Mutation, () => {
|
|
6
5
|
return {
|
|
7
6
|
async start(ctx, { next, marshalVariables }) {
|
|
8
7
|
const layerOptimistic = cache._internal_unstable.storage.createLayer(true);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const query: ClientPlugin;
|
|
1
|
+
import type { Cache } from '../../cache/cache';
|
|
2
|
+
export declare const query: (cache: Cache) => import("..").ClientPlugin;
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
import cache from "../../cache";
|
|
2
1
|
import { ArtifactKind, DataSource } from "../../lib/types";
|
|
3
2
|
import { documentPlugin } from "../utils";
|
|
4
|
-
const query = documentPlugin(ArtifactKind.Query, function() {
|
|
3
|
+
const query = (cache) => documentPlugin(ArtifactKind.Query, function() {
|
|
5
4
|
let subscriptionSpec = null;
|
|
6
5
|
let lastVariables = null;
|
|
7
6
|
return {
|
|
8
7
|
start(ctx, { next }) {
|
|
8
|
+
const runtimeScalarPayload = {
|
|
9
|
+
session: ctx.session
|
|
10
|
+
};
|
|
9
11
|
ctx.variables = {
|
|
10
12
|
...lastVariables,
|
|
13
|
+
...Object.fromEntries(
|
|
14
|
+
Object.entries(ctx.artifact.input?.runtimeScalars ?? {}).map(
|
|
15
|
+
([field, type]) => {
|
|
16
|
+
const runtimeScalar = ctx.config.features?.runtimeScalars?.[type];
|
|
17
|
+
if (!runtimeScalar) {
|
|
18
|
+
return [field, type];
|
|
19
|
+
}
|
|
20
|
+
return [field, runtimeScalar.resolve(runtimeScalarPayload)];
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
),
|
|
11
24
|
...ctx.variables
|
|
12
25
|
};
|
|
13
26
|
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
|
|
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
|
-
|
|
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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ConfigFile } from './config';
|
|
2
|
-
import type
|
|
2
|
+
import { type FragmentArtifact, type MutationArtifact, type QueryArtifact, type SubscriptionArtifact, type SubscriptionSelection } from './types';
|
|
3
3
|
export declare function marshalSelection({ selection, data, }: {
|
|
4
4
|
selection: SubscriptionSelection;
|
|
5
5
|
data: any;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { getCurrentConfig } from "./config";
|
|
2
2
|
import { getFieldsForType } from "./selection";
|
|
3
|
+
import {
|
|
4
|
+
fragmentKey
|
|
5
|
+
} from "./types";
|
|
3
6
|
async function marshalSelection({
|
|
4
7
|
selection,
|
|
5
8
|
data
|
|
@@ -15,6 +18,9 @@ async function marshalSelection({
|
|
|
15
18
|
return Object.fromEntries(
|
|
16
19
|
await Promise.all(
|
|
17
20
|
Object.entries(data).map(async ([fieldName, value]) => {
|
|
21
|
+
if (fieldName === fragmentKey) {
|
|
22
|
+
return [fieldName, value];
|
|
23
|
+
}
|
|
18
24
|
const { type, selection: selection2 } = targetSelection[fieldName];
|
|
19
25
|
if (!type) {
|
|
20
26
|
return [fieldName, value];
|
|
@@ -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;
|
|
@@ -363,6 +367,14 @@ export type PageManifest = {
|
|
|
363
367
|
layouts: string[];
|
|
364
368
|
/** The filepath of the unit */
|
|
365
369
|
path: string;
|
|
370
|
+
/**
|
|
371
|
+
* The name and type of every route paramter that this page can use.
|
|
372
|
+
* null indicates the type is unknown (not constrained by a query)
|
|
373
|
+
**/
|
|
374
|
+
params: Record<string, {
|
|
375
|
+
type: string;
|
|
376
|
+
wrappers: string[];
|
|
377
|
+
} | null>;
|
|
366
378
|
};
|
|
367
379
|
export type QueryManifest = {
|
|
368
380
|
/** the name of the query */
|
|
@@ -373,6 +385,9 @@ export type QueryManifest = {
|
|
|
373
385
|
loading: boolean;
|
|
374
386
|
/** The filepath of the unit */
|
|
375
387
|
path: string;
|
|
376
|
-
/** The
|
|
377
|
-
variables: string
|
|
388
|
+
/** The name and GraphQL type for the variables that this query cares about */
|
|
389
|
+
variables: Record<string, {
|
|
390
|
+
wrappers: string[];
|
|
391
|
+
type: string;
|
|
392
|
+
}>;
|
|
378
393
|
};
|
|
@@ -42,10 +42,9 @@ function _serverHandler({
|
|
|
42
42
|
return yoga(request);
|
|
43
43
|
}
|
|
44
44
|
const authResponse = await handle_request({
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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) {
|
|
@@ -16,7 +16,9 @@ export type RouterPageManifest<_ComponentType> = {
|
|
|
16
16
|
default: QueryArtifact;
|
|
17
17
|
}>;
|
|
18
18
|
loading: boolean;
|
|
19
|
-
variables: string
|
|
19
|
+
variables: Record<string, {
|
|
20
|
+
type: string;
|
|
21
|
+
}>;
|
|
20
22
|
}>;
|
|
21
23
|
component: () => Promise<{
|
|
22
24
|
default: (props: any) => _ComponentType;
|