houdini 1.0.0-next.7 → 1.0.0-next.9
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 +93 -66
- package/build/cmd-esm/index.js +66 -39
- package/build/codegen/generators/typescript/typeReference.d.ts +4 -2
- package/build/codegen/generators/typescript/types.d.ts +0 -1
- package/build/codegen-cjs/index.js +67 -39
- package/build/codegen-esm/index.js +54 -26
- package/build/lib/config.d.ts +2 -1
- package/build/lib/path.d.ts +1 -1
- package/build/lib-cjs/index.js +40 -37
- package/build/lib-esm/index.js +14 -11
- package/build/runtime/cache/cache.d.ts +6 -6
- package/build/runtime/cache/storage.d.ts +5 -5
- package/build/runtime/cache/stuff.d.ts +0 -2
- package/build/runtime/client/documentStore.d.ts +4 -3
- package/build/runtime/client/index.d.ts +6 -5
- package/build/runtime/client/plugins/cache.d.ts +1 -1
- package/build/runtime/client/plugins/fetch.d.ts +1 -1
- package/build/runtime/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime/client/plugins/mutation.d.ts +1 -1
- package/build/runtime/client/plugins/query.d.ts +1 -1
- package/build/runtime/client/plugins/subscription.d.ts +1 -1
- package/build/runtime/client/plugins/throwOnError.d.ts +1 -1
- package/build/runtime/client/utils/documentPlugins.d.ts +2 -2
- package/build/runtime/lib/flatten.d.ts +2 -0
- package/build/runtime/lib/types.d.ts +2 -0
- package/build/runtime/public/record.d.ts +1 -2
- package/build/runtime-cjs/cache/cache.d.ts +6 -6
- package/build/runtime-cjs/cache/cache.js +6 -5
- package/build/runtime-cjs/cache/lists.js +3 -3
- package/build/runtime-cjs/cache/storage.d.ts +5 -5
- package/build/runtime-cjs/cache/storage.js +2 -2
- package/build/runtime-cjs/cache/stuff.d.ts +0 -2
- package/build/runtime-cjs/cache/stuff.js +2 -19
- package/build/runtime-cjs/cache/subscription.js +5 -4
- package/build/runtime-cjs/client/documentStore.d.ts +4 -3
- package/build/runtime-cjs/client/documentStore.js +4 -4
- package/build/runtime-cjs/client/index.d.ts +6 -5
- package/build/runtime-cjs/client/index.js +45 -19
- package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/cache.js +3 -3
- package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/fetch.js +7 -7
- package/build/runtime-cjs/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/fetchParams.js +3 -3
- package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/mutation.js +3 -3
- package/build/runtime-cjs/client/plugins/query.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/query.js +3 -3
- package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/subscription.js +3 -3
- package/build/runtime-cjs/client/plugins/throwOnError.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/throwOnError.js +3 -3
- package/build/runtime-cjs/client/utils/documentPlugins.d.ts +2 -2
- package/build/runtime-cjs/lib/flatten.d.ts +2 -0
- package/build/runtime-cjs/lib/flatten.js +41 -0
- package/build/runtime-cjs/lib/types.d.ts +2 -0
- package/build/runtime-cjs/public/cache.js +2 -2
- package/build/runtime-cjs/public/record.d.ts +1 -2
- package/build/runtime-cjs/public/record.js +1 -2
- package/build/runtime-esm/cache/cache.d.ts +6 -6
- package/build/runtime-esm/cache/cache.js +7 -6
- package/build/runtime-esm/cache/lists.js +3 -3
- package/build/runtime-esm/cache/storage.d.ts +5 -5
- package/build/runtime-esm/cache/storage.js +2 -2
- package/build/runtime-esm/cache/stuff.d.ts +0 -2
- package/build/runtime-esm/cache/stuff.js +1 -17
- package/build/runtime-esm/cache/subscription.js +6 -5
- package/build/runtime-esm/client/documentStore.d.ts +4 -3
- package/build/runtime-esm/client/documentStore.js +5 -5
- package/build/runtime-esm/client/index.d.ts +6 -5
- package/build/runtime-esm/client/index.js +46 -21
- package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
- package/build/runtime-esm/client/plugins/cache.js +2 -2
- package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
- package/build/runtime-esm/client/plugins/fetch.js +6 -6
- package/build/runtime-esm/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime-esm/client/plugins/fetchParams.js +2 -2
- package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime-esm/client/plugins/mutation.d.ts +1 -1
- package/build/runtime-esm/client/plugins/mutation.js +2 -2
- package/build/runtime-esm/client/plugins/query.d.ts +1 -1
- package/build/runtime-esm/client/plugins/query.js +2 -2
- package/build/runtime-esm/client/plugins/subscription.d.ts +1 -1
- package/build/runtime-esm/client/plugins/subscription.js +2 -2
- package/build/runtime-esm/client/plugins/throwOnError.d.ts +1 -1
- package/build/runtime-esm/client/plugins/throwOnError.js +2 -2
- package/build/runtime-esm/client/utils/documentPlugins.d.ts +2 -2
- package/build/runtime-esm/lib/flatten.d.ts +2 -0
- package/build/runtime-esm/lib/flatten.js +17 -0
- package/build/runtime-esm/lib/types.d.ts +2 -0
- package/build/runtime-esm/public/cache.js +2 -2
- package/build/runtime-esm/public/record.d.ts +1 -2
- package/build/runtime-esm/public/record.js +1 -2
- package/build/test-cjs/index.js +67 -39
- package/build/test-esm/index.js +54 -26
- package/build/vite-cjs/index.js +90 -58
- package/build/vite-esm/index.js +64 -32
- package/package.json +4 -4
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { flatten } from "../lib/flatten";
|
|
1
2
|
import { DocumentStore } from "./documentStore";
|
|
2
3
|
import {
|
|
3
|
-
fetchParamsPlugin,
|
|
4
|
-
fetchPlugin,
|
|
5
|
-
mutationPlugin,
|
|
6
|
-
queryPlugin,
|
|
7
|
-
throwOnErrorPlugin
|
|
4
|
+
fetchParams as fetchParamsPlugin,
|
|
5
|
+
fetch as fetchPlugin,
|
|
6
|
+
mutation as mutationPlugin,
|
|
7
|
+
query as queryPlugin,
|
|
8
|
+
throwOnError as throwOnErrorPlugin
|
|
8
9
|
} from "./plugins";
|
|
9
10
|
import pluginsFromPlugins from "./plugins/injectedPlugins";
|
|
10
11
|
import { DocumentStore as DocumentStore2 } from "./documentStore";
|
|
11
|
-
import {
|
|
12
|
+
import { fetch, mutation, query, subscription } from "./plugins";
|
|
12
13
|
class HoudiniClient {
|
|
13
14
|
url;
|
|
14
15
|
#plugins;
|
|
@@ -18,16 +19,18 @@ class HoudiniClient {
|
|
|
18
19
|
"A client cannot be given a pipeline and a list of plugins at the same time."
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
|
-
this.#plugins =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
this.#plugins = flatten(
|
|
23
|
+
[].concat(
|
|
24
|
+
throwOnError ? [throwOnErrorPlugin(throwOnError)] : [],
|
|
25
|
+
fetchParamsPlugin(fetchParams),
|
|
26
|
+
pipeline ?? [
|
|
27
|
+
queryPlugin,
|
|
28
|
+
mutationPlugin
|
|
29
|
+
].concat(
|
|
30
|
+
plugins ?? [],
|
|
31
|
+
pluginsFromPlugins,
|
|
32
|
+
fetchPlugin()
|
|
33
|
+
)
|
|
31
34
|
)
|
|
32
35
|
);
|
|
33
36
|
this.url = url;
|
|
@@ -41,18 +44,40 @@ class HoudiniClient {
|
|
|
41
44
|
return new DocumentStore({
|
|
42
45
|
client: this,
|
|
43
46
|
artifact,
|
|
44
|
-
plugins: this.#plugins,
|
|
47
|
+
plugins: createPluginHooks(this.#plugins),
|
|
45
48
|
cache,
|
|
46
49
|
initialValue,
|
|
47
50
|
fetching
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
53
|
}
|
|
54
|
+
function createPluginHooks(plugins) {
|
|
55
|
+
return plugins.reduce((hooks, plugin) => {
|
|
56
|
+
const result = plugin();
|
|
57
|
+
if (!result) {
|
|
58
|
+
return hooks;
|
|
59
|
+
}
|
|
60
|
+
if (!Array.isArray(result)) {
|
|
61
|
+
return hooks.concat(result);
|
|
62
|
+
}
|
|
63
|
+
for (const value of result) {
|
|
64
|
+
if (!value) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (typeof value === "function") {
|
|
68
|
+
return hooks.concat(createPluginHooks([value]));
|
|
69
|
+
}
|
|
70
|
+
hooks.push(value);
|
|
71
|
+
}
|
|
72
|
+
return hooks;
|
|
73
|
+
}, []);
|
|
74
|
+
}
|
|
51
75
|
export {
|
|
52
76
|
DocumentStore2 as DocumentStore,
|
|
53
77
|
HoudiniClient,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
createPluginHooks,
|
|
79
|
+
fetch,
|
|
80
|
+
mutation,
|
|
81
|
+
query,
|
|
82
|
+
subscription
|
|
58
83
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import cache from '../../cache';
|
|
2
2
|
import type { Cache } from '../../cache/cache';
|
|
3
3
|
import type { ClientPlugin } from '../documentStore';
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const cachePolicy: ({ enabled, setFetching, cache: localCache, }: {
|
|
5
5
|
enabled: boolean;
|
|
6
6
|
setFetching: (val: boolean) => void;
|
|
7
7
|
cache?: Cache | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cache from "../../cache";
|
|
2
2
|
import { ArtifactKind, CachePolicy, DataSource } from "../../lib/types";
|
|
3
|
-
const
|
|
3
|
+
const cachePolicy = ({
|
|
4
4
|
enabled,
|
|
5
5
|
setFetching,
|
|
6
6
|
cache: localCache = cache
|
|
@@ -67,5 +67,5 @@ const cachePolicyPlugin = ({
|
|
|
67
67
|
};
|
|
68
68
|
};
|
|
69
69
|
export {
|
|
70
|
-
|
|
70
|
+
cachePolicy
|
|
71
71
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RequestPayload } from '../../lib/types';
|
|
2
2
|
import type { ClientPlugin } from '../documentStore';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const fetch: (target?: RequestHandler | string) => ClientPlugin;
|
|
4
4
|
export type FetchContext = {
|
|
5
5
|
fetch: typeof globalThis.fetch;
|
|
6
6
|
metadata?: App.Metadata | null;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DataSource } from "../../lib/types";
|
|
2
|
-
const
|
|
2
|
+
const fetch = (target) => {
|
|
3
3
|
return () => {
|
|
4
4
|
return {
|
|
5
5
|
async network(ctx, { client, resolve, marshalVariables }) {
|
|
6
|
-
const
|
|
6
|
+
const fetch2 = ctx.fetch ?? globalThis.fetch;
|
|
7
7
|
const fetchParams = {
|
|
8
8
|
text: ctx.text,
|
|
9
9
|
hash: ctx.hash,
|
|
@@ -20,7 +20,7 @@ const fetchPlugin = (target) => {
|
|
|
20
20
|
const result = await fetchFn({
|
|
21
21
|
fetch: (url, args) => {
|
|
22
22
|
const newArgs = handleMultipart(fetchParams, args) ?? args;
|
|
23
|
-
return
|
|
23
|
+
return fetch2(url, newArgs);
|
|
24
24
|
},
|
|
25
25
|
metadata: ctx.metadata,
|
|
26
26
|
session: ctx.session || {},
|
|
@@ -45,8 +45,8 @@ const defaultFetch = (url, params) => {
|
|
|
45
45
|
"Could not find configured client url. Please specify one in your houdini.config.js file."
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
|
-
return async ({ fetch, text, variables }) => {
|
|
49
|
-
const result = await
|
|
48
|
+
return async ({ fetch: fetch2, text, variables }) => {
|
|
49
|
+
const result = await fetch2(url, {
|
|
50
50
|
method: "POST",
|
|
51
51
|
body: JSON.stringify({ query: text, variables }),
|
|
52
52
|
...params,
|
|
@@ -147,6 +147,6 @@ function isPlainObject(value) {
|
|
|
147
147
|
}
|
|
148
148
|
export {
|
|
149
149
|
extractFiles,
|
|
150
|
-
|
|
150
|
+
fetch,
|
|
151
151
|
isExtractableFile
|
|
152
152
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DocumentArtifact } from '../../lib/types';
|
|
2
2
|
import type { ClientPlugin, ClientPluginContext } from '../documentStore';
|
|
3
3
|
export type FetchParamFn = (ctx: FetchParamsInput) => Required<ClientPluginContext>['fetchParams'];
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const fetchParams: (fn?: FetchParamFn) => ClientPlugin;
|
|
5
5
|
export type FetchParamsInput = Pick<ClientPluginContext, 'config' | 'policy' | 'variables' | 'metadata' | 'session' | 'stuff'> & {
|
|
6
6
|
text: string;
|
|
7
7
|
hash: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const fetchParams = (fn = () => ({})) => () => ({
|
|
2
2
|
beforeNetwork(ctx, { next, marshalVariables }) {
|
|
3
3
|
next({
|
|
4
4
|
...ctx,
|
|
@@ -17,5 +17,5 @@ const fetchParamsPlugin = (fn = () => ({})) => () => ({
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
export {
|
|
20
|
-
|
|
20
|
+
fetchParams
|
|
21
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const mutation: import("..").ClientPlugin;
|
|
@@ -2,7 +2,7 @@ import cache from "../../cache";
|
|
|
2
2
|
import { marshalSelection } from "../../lib/scalars";
|
|
3
3
|
import { ArtifactKind } from "../../lib/types";
|
|
4
4
|
import { documentPlugin } from "../utils";
|
|
5
|
-
const
|
|
5
|
+
const mutation = documentPlugin(ArtifactKind.Mutation, () => {
|
|
6
6
|
return {
|
|
7
7
|
async start(ctx, { next, marshalVariables }) {
|
|
8
8
|
const layer = cache._internal_unstable.storage.createLayer(true);
|
|
@@ -52,5 +52,5 @@ const mutationPlugin = documentPlugin(ArtifactKind.Mutation, () => {
|
|
|
52
52
|
};
|
|
53
53
|
});
|
|
54
54
|
export {
|
|
55
|
-
|
|
55
|
+
mutation
|
|
56
56
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ClientPlugin } from '../documentStore';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const query: ClientPlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import cache from "../../cache";
|
|
2
2
|
import { ArtifactKind, DataSource } from "../../lib/types";
|
|
3
3
|
import { documentPlugin } from "../utils";
|
|
4
|
-
const
|
|
4
|
+
const query = documentPlugin(ArtifactKind.Query, function() {
|
|
5
5
|
let subscriptionSpec = null;
|
|
6
6
|
let lastVariables = null;
|
|
7
7
|
let artifactName = "";
|
|
@@ -49,5 +49,5 @@ const queryPlugin = documentPlugin(ArtifactKind.Query, function() {
|
|
|
49
49
|
};
|
|
50
50
|
});
|
|
51
51
|
export {
|
|
52
|
-
|
|
52
|
+
query
|
|
53
53
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClientPluginContext } from '../documentStore';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function subscription(factory: SubscriptionHandler): import("../documentStore").ClientPlugin;
|
|
3
3
|
export type SubscriptionHandler = (ctx: ClientPluginContext) => {
|
|
4
4
|
subscribe: (payload: {
|
|
5
5
|
query: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { deepEquals } from "../../lib/deepEquals";
|
|
2
2
|
import { ArtifactKind, DataSource } from "../../lib/types";
|
|
3
3
|
import { documentPlugin } from "../utils";
|
|
4
|
-
function
|
|
4
|
+
function subscription(factory) {
|
|
5
5
|
return documentPlugin(ArtifactKind.Subscription, () => {
|
|
6
6
|
let clearSubscription = null;
|
|
7
7
|
let socketClient = null;
|
|
@@ -72,5 +72,5 @@ function subscriptionPlugin(factory) {
|
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
export {
|
|
75
|
-
|
|
75
|
+
subscription
|
|
76
76
|
};
|
|
@@ -4,4 +4,4 @@ export type ThrowOnErrorParams = {
|
|
|
4
4
|
operations: ('all' | 'query' | 'mutation' | 'subscription')[];
|
|
5
5
|
error?: (errors: NonNullable<QueryResult<any, any>['errors']>) => unknown;
|
|
6
6
|
};
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const throwOnError: ({ operations, error }: ThrowOnErrorParams) => ClientPlugin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArtifactKind } from "../../lib";
|
|
2
|
-
const
|
|
2
|
+
const throwOnError = ({ operations, error }) => () => {
|
|
3
3
|
const all = operations.includes("all");
|
|
4
4
|
const throwOnKind = (kind) => all || {
|
|
5
5
|
[ArtifactKind.Query]: operations.includes("query"),
|
|
@@ -19,5 +19,5 @@ const throwOnErrorPlugin = ({ operations, error }) => () => {
|
|
|
19
19
|
};
|
|
20
20
|
const defaultErrorFn = async (errors) => new Error(errors.map((error) => error.message).join(". ") + ".");
|
|
21
21
|
export {
|
|
22
|
-
|
|
22
|
+
throwOnError
|
|
23
23
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ArtifactKind } from '../../lib/types';
|
|
2
|
-
import type { ClientPlugin } from '../documentStore';
|
|
3
|
-
export declare const documentPlugin: (kind: ArtifactKind, source:
|
|
2
|
+
import type { ClientPlugin, ClientHooks } from '../documentStore';
|
|
3
|
+
export declare const documentPlugin: (kind: ArtifactKind, source: () => ClientHooks) => ClientPlugin;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function flatten(source) {
|
|
2
|
+
if (!source) {
|
|
3
|
+
return [];
|
|
4
|
+
}
|
|
5
|
+
return source.reduce((acc, element) => {
|
|
6
|
+
if (!element) {
|
|
7
|
+
return acc;
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(element)) {
|
|
10
|
+
return acc.concat(flatten(element));
|
|
11
|
+
}
|
|
12
|
+
return acc.concat(element);
|
|
13
|
+
}, []);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
flatten
|
|
17
|
+
};
|
|
@@ -64,8 +64,8 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
|
|
|
64
64
|
});
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
markStale(type, options
|
|
68
|
-
return this._internal_unstable.markTypeStale(type,
|
|
67
|
+
markStale(type, options) {
|
|
68
|
+
return this._internal_unstable.markTypeStale(type ? { ...options, type } : void 0);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
export {
|
|
@@ -34,8 +34,7 @@ export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<De
|
|
|
34
34
|
* @param field
|
|
35
35
|
* @param when
|
|
36
36
|
*/
|
|
37
|
-
markStale<Field extends TypeFieldNames<Def, Type>>(
|
|
38
|
-
field?: Field;
|
|
37
|
+
markStale<Field extends TypeFieldNames<Def, Type>>(field?: Field, { when, }?: {
|
|
39
38
|
when?: ArgType<Def, Type, Field>;
|
|
40
39
|
}): void;
|
|
41
40
|
}
|