houdini 1.0.0-next.2 → 1.0.0-next.21
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/README.md +4 -1
- package/build/cmd-cjs/index.js +5366 -2772
- package/build/cmd-esm/index.js +5340 -2746
- package/build/codegen/generators/artifacts/index.d.ts +2 -2
- package/build/codegen/generators/artifacts/indexFile.d.ts +2 -2
- package/build/codegen/generators/artifacts/selection.d.ts +5 -5
- package/build/codegen/generators/artifacts/utils.d.ts +0 -1
- package/build/codegen/generators/indexFile/index.d.ts +2 -2
- package/build/codegen/generators/persistedQueries/index.d.ts +2 -2
- package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -2
- package/build/codegen/generators/runtime/index.d.ts +2 -2
- package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
- package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
- package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +2 -0
- package/build/codegen/generators/typescript/index.d.ts +2 -2
- package/build/codegen/generators/typescript/typeReference.d.ts +4 -2
- package/build/codegen/generators/typescript/types.d.ts +0 -1
- package/build/codegen/index.d.ts +2 -2
- package/build/codegen/transforms/addID.d.ts +2 -2
- package/build/codegen/transforms/composeQueries.d.ts +4 -4
- package/build/codegen/transforms/fragmentVariables.d.ts +3 -2
- package/build/codegen/transforms/list.d.ts +2 -2
- package/build/codegen/transforms/paginate.d.ts +2 -2
- package/build/codegen/transforms/schema.d.ts +2 -2
- package/build/codegen/transforms/typename.d.ts +2 -2
- package/build/codegen/utils/flattenSelections.d.ts +1 -1
- package/build/codegen/validators/noIDAlias.d.ts +2 -2
- package/build/codegen/validators/plugins.d.ts +2 -2
- package/build/codegen/validators/typeCheck.d.ts +2 -2
- package/build/codegen/validators/uniqueNames.d.ts +2 -2
- package/build/codegen-cjs/index.js +4694 -2137
- package/build/codegen-esm/index.js +4682 -2125
- package/build/lib/config.d.ts +15 -96
- package/build/lib/deepMerge.d.ts +1 -0
- package/build/lib/graphql.d.ts +5 -2
- package/build/lib/index.d.ts +2 -0
- package/build/lib/path.d.ts +1 -1
- package/build/lib/pipeline.d.ts +1 -1
- package/build/lib/plugin.d.ts +2 -0
- package/build/lib/types.d.ts +257 -6
- package/build/lib/walk.d.ts +4 -1
- package/build/lib-cjs/index.js +4108 -928
- package/build/lib-esm/index.js +4078 -907
- package/build/runtime/cache/cache.d.ts +28 -11
- package/build/runtime/cache/lists.d.ts +1 -0
- package/build/runtime/cache/staleManager.d.ts +30 -0
- package/build/runtime/cache/storage.d.ts +23 -20
- package/build/runtime/cache/stuff.d.ts +0 -2
- package/build/runtime/cache/subscription.d.ts +2 -1
- package/build/runtime/client/documentStore.d.ts +20 -17
- package/build/runtime/client/index.d.ts +13 -11
- 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 +2 -2
- 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 +2 -3
- package/build/runtime/client/plugins/throwOnError.d.ts +1 -1
- package/build/runtime/client/utils/documentPlugins.d.ts +3 -3
- package/build/runtime/generated.d.ts +1 -0
- package/build/runtime/imports/pluginConfig.d.ts +3 -0
- package/build/runtime/index.d.ts +1 -1
- package/build/runtime/lib/config.d.ts +27 -24
- package/build/runtime/lib/flatten.d.ts +2 -0
- package/build/runtime/lib/index.d.ts +1 -0
- package/build/runtime/lib/key.d.ts +6 -0
- package/build/runtime/lib/scalars.d.ts +3 -3
- package/build/runtime/lib/types.d.ts +47 -47
- package/build/runtime/public/cache.d.ts +26 -6
- package/build/runtime/public/record.d.ts +26 -17
- package/build/runtime/public/tests/test.d.ts +52 -10
- package/build/runtime/public/types.d.ts +8 -0
- package/build/runtime-cjs/cache/cache.d.ts +28 -11
- package/build/runtime-cjs/cache/cache.js +97 -22
- package/build/runtime-cjs/cache/gc.js +9 -0
- package/build/runtime-cjs/cache/lists.d.ts +1 -0
- package/build/runtime-cjs/cache/lists.js +9 -6
- package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
- package/build/runtime-cjs/cache/staleManager.js +95 -0
- package/build/runtime-cjs/cache/storage.d.ts +23 -20
- package/build/runtime-cjs/cache/storage.js +11 -13
- 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.d.ts +2 -1
- package/build/runtime-cjs/cache/subscription.js +11 -7
- package/build/runtime-cjs/client/documentStore.d.ts +20 -17
- package/build/runtime-cjs/client/documentStore.js +13 -9
- package/build/runtime-cjs/client/index.d.ts +13 -11
- package/build/runtime-cjs/client/index.js +48 -19
- package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/cache.js +12 -10
- package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/fetch.js +10 -9
- package/build/runtime-cjs/client/plugins/fetchParams.d.ts +2 -2
- package/build/runtime-cjs/client/plugins/fetchParams.js +9 -4
- 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 +5 -5
- package/build/runtime-cjs/client/plugins/subscription.d.ts +2 -3
- package/build/runtime-cjs/client/plugins/subscription.js +7 -5
- 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 +3 -3
- package/build/runtime-cjs/generated.d.ts +1 -0
- package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-cjs/imports/pluginConfig.js +27 -0
- package/build/runtime-cjs/index.d.ts +1 -1
- package/build/runtime-cjs/lib/config.d.ts +27 -24
- package/build/runtime-cjs/lib/config.js +11 -1
- package/build/runtime-cjs/lib/flatten.d.ts +2 -0
- package/build/runtime-cjs/lib/flatten.js +41 -0
- package/build/runtime-cjs/lib/index.d.ts +1 -0
- package/build/runtime-cjs/lib/index.js +1 -0
- package/build/runtime-cjs/lib/key.d.ts +6 -0
- package/build/runtime-cjs/lib/key.js +41 -0
- package/build/runtime-cjs/lib/scalars.d.ts +3 -3
- package/build/runtime-cjs/lib/scalars.js +13 -2
- package/build/runtime-cjs/lib/types.d.ts +47 -47
- package/build/runtime-cjs/lib/types.js +26 -30
- package/build/runtime-cjs/public/cache.d.ts +26 -6
- package/build/runtime-cjs/public/cache.js +32 -32
- package/build/runtime-cjs/public/list.js +6 -28
- package/build/runtime-cjs/public/record.d.ts +26 -17
- package/build/runtime-cjs/public/record.js +27 -187
- package/build/runtime-cjs/public/tests/test.d.ts +52 -10
- package/build/runtime-cjs/public/tests/test.js +27 -2
- package/build/runtime-cjs/public/types.d.ts +8 -0
- package/build/runtime-esm/cache/cache.d.ts +28 -11
- package/build/runtime-esm/cache/cache.js +99 -24
- package/build/runtime-esm/cache/gc.js +9 -0
- package/build/runtime-esm/cache/lists.d.ts +1 -0
- package/build/runtime-esm/cache/lists.js +9 -6
- package/build/runtime-esm/cache/staleManager.d.ts +30 -0
- package/build/runtime-esm/cache/staleManager.js +71 -0
- package/build/runtime-esm/cache/storage.d.ts +23 -20
- package/build/runtime-esm/cache/storage.js +11 -13
- 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.d.ts +2 -1
- package/build/runtime-esm/cache/subscription.js +12 -8
- package/build/runtime-esm/client/documentStore.d.ts +20 -17
- package/build/runtime-esm/client/documentStore.js +14 -10
- package/build/runtime-esm/client/index.d.ts +13 -11
- package/build/runtime-esm/client/index.js +49 -21
- package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
- package/build/runtime-esm/client/plugins/cache.js +11 -9
- package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
- package/build/runtime-esm/client/plugins/fetch.js +9 -8
- package/build/runtime-esm/client/plugins/fetchParams.d.ts +2 -2
- package/build/runtime-esm/client/plugins/fetchParams.js +8 -3
- 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 +4 -4
- package/build/runtime-esm/client/plugins/subscription.d.ts +2 -3
- package/build/runtime-esm/client/plugins/subscription.js +6 -4
- 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 +3 -3
- package/build/runtime-esm/generated.d.ts +1 -0
- package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-esm/imports/pluginConfig.js +5 -0
- package/build/runtime-esm/index.d.ts +1 -1
- package/build/runtime-esm/lib/config.d.ts +27 -24
- package/build/runtime-esm/lib/config.js +11 -1
- package/build/runtime-esm/lib/flatten.d.ts +2 -0
- package/build/runtime-esm/lib/flatten.js +17 -0
- package/build/runtime-esm/lib/index.d.ts +1 -0
- package/build/runtime-esm/lib/index.js +1 -0
- package/build/runtime-esm/lib/key.d.ts +6 -0
- package/build/runtime-esm/lib/key.js +17 -0
- package/build/runtime-esm/lib/scalars.d.ts +3 -3
- package/build/runtime-esm/lib/scalars.js +13 -2
- package/build/runtime-esm/lib/types.d.ts +47 -47
- package/build/runtime-esm/lib/types.js +26 -30
- package/build/runtime-esm/public/cache.d.ts +26 -6
- package/build/runtime-esm/public/cache.js +31 -30
- package/build/runtime-esm/public/list.js +6 -28
- package/build/runtime-esm/public/record.d.ts +26 -17
- package/build/runtime-esm/public/record.js +26 -183
- package/build/runtime-esm/public/tests/test.d.ts +52 -10
- package/build/runtime-esm/public/tests/test.js +26 -1
- package/build/runtime-esm/public/types.d.ts +8 -0
- package/build/test/index.d.ts +3 -3
- package/build/test-cjs/index.js +5007 -2465
- package/build/test-esm/index.js +4995 -2453
- package/build/vite/houdini.d.ts +2 -0
- package/build/vite-cjs/index.js +5344 -2744
- package/build/vite-esm/index.js +5319 -2719
- package/package.json +6 -5
- package/build/codegen/generators/typescript/imperativeCache.d.ts +0 -2
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { flatten } from "../lib/flatten";
|
|
1
2
|
import { DocumentStore } from "./documentStore";
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
fetch as fetchPlugin,
|
|
5
|
+
mutation as mutationPlugin,
|
|
6
|
+
query as queryPlugin,
|
|
7
|
+
throwOnError as throwOnErrorPlugin,
|
|
8
|
+
fetchParams as fetchParamsPlugin
|
|
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,43 @@ 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
|
+
if (typeof plugin !== "function") {
|
|
57
|
+
throw new Error("Encountered client plugin that's not a function");
|
|
58
|
+
}
|
|
59
|
+
const result = plugin();
|
|
60
|
+
if (!result) {
|
|
61
|
+
return hooks;
|
|
62
|
+
}
|
|
63
|
+
if (!Array.isArray(result)) {
|
|
64
|
+
return hooks.concat(result);
|
|
65
|
+
}
|
|
66
|
+
for (const value of result) {
|
|
67
|
+
if (!value) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === "function") {
|
|
71
|
+
return hooks.concat(createPluginHooks([value]));
|
|
72
|
+
}
|
|
73
|
+
hooks.push(value);
|
|
74
|
+
}
|
|
75
|
+
return hooks;
|
|
76
|
+
}, []);
|
|
77
|
+
}
|
|
51
78
|
export {
|
|
52
79
|
DocumentStore2 as DocumentStore,
|
|
53
80
|
HoudiniClient,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
81
|
+
createPluginHooks,
|
|
82
|
+
fetch,
|
|
83
|
+
mutation,
|
|
84
|
+
query,
|
|
85
|
+
subscription
|
|
58
86
|
};
|
|
@@ -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,12 +1,12 @@
|
|
|
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
|
|
7
7
|
}) => () => {
|
|
8
8
|
return {
|
|
9
|
-
network(ctx, { next, resolve, marshalVariables }) {
|
|
9
|
+
network(ctx, { initialValue, next, resolve, marshalVariables }) {
|
|
10
10
|
const { policy, artifact } = ctx;
|
|
11
11
|
let useCache = false;
|
|
12
12
|
if (enabled && artifact.kind === ArtifactKind.Query && !ctx.cacheParams?.disableRead) {
|
|
@@ -19,25 +19,27 @@ const cachePolicyPlugin = ({
|
|
|
19
19
|
if (policy === CachePolicy.CacheOnly) {
|
|
20
20
|
return resolve(ctx, {
|
|
21
21
|
fetching: false,
|
|
22
|
-
variables: ctx.variables ??
|
|
23
|
-
data: value.data,
|
|
22
|
+
variables: ctx.variables ?? {},
|
|
23
|
+
data: allowed ? value.data : initialValue.data,
|
|
24
24
|
errors: null,
|
|
25
25
|
source: DataSource.Cache,
|
|
26
|
-
partial: value.partial
|
|
26
|
+
partial: allowed ? value.partial : false,
|
|
27
|
+
stale: value.stale
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
30
|
useCache = !!(value.data !== null && allowed);
|
|
30
31
|
if (useCache) {
|
|
31
32
|
resolve(ctx, {
|
|
32
33
|
fetching: false,
|
|
33
|
-
variables: ctx.variables ??
|
|
34
|
+
variables: ctx.variables ?? {},
|
|
34
35
|
data: value.data,
|
|
35
36
|
errors: null,
|
|
36
37
|
source: DataSource.Cache,
|
|
37
|
-
partial: value.partial
|
|
38
|
+
partial: value.partial,
|
|
39
|
+
stale: value.stale
|
|
38
40
|
});
|
|
39
41
|
}
|
|
40
|
-
if (useCache && !value.partial) {
|
|
42
|
+
if (useCache && !value.partial && !value.stale) {
|
|
41
43
|
return;
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -65,5 +67,5 @@ const cachePolicyPlugin = ({
|
|
|
65
67
|
};
|
|
66
68
|
};
|
|
67
69
|
export {
|
|
68
|
-
|
|
70
|
+
cachePolicy
|
|
69
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 || {},
|
|
@@ -28,10 +28,11 @@ const fetchPlugin = (target) => {
|
|
|
28
28
|
});
|
|
29
29
|
resolve(ctx, {
|
|
30
30
|
fetching: false,
|
|
31
|
-
variables: ctx.variables ??
|
|
31
|
+
variables: ctx.variables ?? {},
|
|
32
32
|
data: result.data,
|
|
33
33
|
errors: !result.errors || result.errors.length === 0 ? null : result.errors,
|
|
34
34
|
partial: false,
|
|
35
|
+
stale: false,
|
|
35
36
|
source: DataSource.Network
|
|
36
37
|
});
|
|
37
38
|
}
|
|
@@ -41,11 +42,11 @@ const fetchPlugin = (target) => {
|
|
|
41
42
|
const defaultFetch = (url, params) => {
|
|
42
43
|
if (!url) {
|
|
43
44
|
throw new Error(
|
|
44
|
-
"Could not find configured client url. Please specify one in your
|
|
45
|
+
"Could not find configured client url. Please specify one in your HoudiniClient constructor."
|
|
45
46
|
);
|
|
46
47
|
}
|
|
47
|
-
return async ({ fetch, text, variables }) => {
|
|
48
|
-
const result = await
|
|
48
|
+
return async ({ fetch: fetch2, text, variables }) => {
|
|
49
|
+
const result = await fetch2(url, {
|
|
49
50
|
method: "POST",
|
|
50
51
|
body: JSON.stringify({ query: text, variables }),
|
|
51
52
|
...params,
|
|
@@ -146,6 +147,6 @@ function isPlainObject(value) {
|
|
|
146
147
|
}
|
|
147
148
|
export {
|
|
148
149
|
extractFiles,
|
|
149
|
-
|
|
150
|
+
fetch,
|
|
150
151
|
isExtractableFile
|
|
151
152
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
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;
|
|
8
|
-
|
|
8
|
+
document: DocumentArtifact;
|
|
9
9
|
};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
const
|
|
1
|
+
const fetchParams = (fn = () => ({})) => () => ({
|
|
2
2
|
beforeNetwork(ctx, { next, marshalVariables }) {
|
|
3
3
|
next({
|
|
4
4
|
...ctx,
|
|
5
5
|
fetchParams: fn({
|
|
6
|
-
|
|
6
|
+
config: ctx.config,
|
|
7
|
+
policy: ctx.policy,
|
|
8
|
+
metadata: ctx.metadata,
|
|
9
|
+
session: ctx.session,
|
|
10
|
+
stuff: ctx.stuff,
|
|
11
|
+
document: ctx.artifact,
|
|
7
12
|
variables: marshalVariables(ctx),
|
|
8
13
|
text: ctx.artifact.raw,
|
|
9
14
|
hash: ctx.artifact.hash
|
|
@@ -12,5 +17,5 @@ const fetchParamsPlugin = (fn = () => ({})) => () => ({
|
|
|
12
17
|
}
|
|
13
18
|
});
|
|
14
19
|
export {
|
|
15
|
-
|
|
20
|
+
fetchParams
|
|
16
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 = "";
|
|
@@ -25,14 +25,14 @@ const queryPlugin = documentPlugin(ArtifactKind.Query, function() {
|
|
|
25
25
|
selection: ctx.artifact.selection,
|
|
26
26
|
variables: () => lastVariables,
|
|
27
27
|
set: (newValue) => {
|
|
28
|
-
console.log("setting from cache update");
|
|
29
28
|
resolve(ctx, {
|
|
30
29
|
data: newValue,
|
|
31
30
|
errors: null,
|
|
32
31
|
fetching: false,
|
|
33
32
|
partial: false,
|
|
33
|
+
stale: false,
|
|
34
34
|
source: DataSource.Cache,
|
|
35
|
-
variables: ctx.variables ??
|
|
35
|
+
variables: ctx.variables ?? {}
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
};
|
|
@@ -49,5 +49,5 @@ const queryPlugin = documentPlugin(ArtifactKind.Query, function() {
|
|
|
49
49
|
};
|
|
50
50
|
});
|
|
51
51
|
export {
|
|
52
|
-
|
|
52
|
+
query
|
|
53
53
|
};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type { GraphQLObject } from '../../lib/types';
|
|
2
1
|
import type { ClientPluginContext } from '../documentStore';
|
|
3
|
-
export declare function
|
|
2
|
+
export declare function subscription(factory: SubscriptionHandler): import("../documentStore").ClientPlugin;
|
|
4
3
|
export type SubscriptionHandler = (ctx: ClientPluginContext) => {
|
|
5
4
|
subscribe: (payload: {
|
|
6
5
|
query: string;
|
|
7
6
|
variables?: {};
|
|
8
7
|
}, handlers: {
|
|
9
8
|
next: (payload: {
|
|
10
|
-
data?:
|
|
9
|
+
data?: {} | null;
|
|
11
10
|
errors?: readonly {
|
|
12
11
|
message: string;
|
|
13
12
|
}[];
|
|
@@ -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;
|
|
@@ -43,19 +43,21 @@ function subscriptionPlugin(factory) {
|
|
|
43
43
|
errors: [...errors ?? []],
|
|
44
44
|
fetching: false,
|
|
45
45
|
partial: true,
|
|
46
|
+
stale: false,
|
|
46
47
|
source: DataSource.Network,
|
|
47
|
-
variables: ctx.variables ??
|
|
48
|
+
variables: ctx.variables ?? {}
|
|
48
49
|
});
|
|
49
50
|
},
|
|
50
51
|
error(data) {
|
|
51
52
|
clearSubscription?.();
|
|
52
53
|
resolve(ctx, {
|
|
53
54
|
partial: true,
|
|
55
|
+
stale: false,
|
|
54
56
|
source: DataSource.Network,
|
|
55
57
|
data: null,
|
|
56
58
|
errors: [data],
|
|
57
59
|
fetching: false,
|
|
58
|
-
variables: ctx.variables ??
|
|
60
|
+
variables: ctx.variables ?? {}
|
|
59
61
|
});
|
|
60
62
|
},
|
|
61
63
|
complete() {
|
|
@@ -70,5 +72,5 @@ function subscriptionPlugin(factory) {
|
|
|
70
72
|
});
|
|
71
73
|
}
|
|
72
74
|
export {
|
|
73
|
-
|
|
75
|
+
subscription
|
|
74
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
|
-
import type {
|
|
2
|
-
import type { ClientPlugin } from '../documentStore';
|
|
3
|
-
export declare const documentPlugin: (kind:
|
|
1
|
+
import type { ArtifactKinds } from '../../lib/types';
|
|
2
|
+
import type { ClientPlugin, ClientHooks } from '../documentStore';
|
|
3
|
+
export declare const documentPlugin: (kind: ArtifactKinds, source: () => ClientHooks) => ClientPlugin;
|
|
@@ -3,6 +3,6 @@ import type { CacheTypeDef } from './generated';
|
|
|
3
3
|
import { Cache } from './public';
|
|
4
4
|
export * from './client';
|
|
5
5
|
export * from './lib';
|
|
6
|
-
export declare function graphql(str:
|
|
6
|
+
export declare function graphql<_Payload>(str: TemplateStringsArray): _Payload;
|
|
7
7
|
export declare const cache: Cache<CacheTypeDef>;
|
|
8
8
|
export declare function getCache(): InternalCache;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GraphQLSchema } from 'graphql';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CachePolicies } from './types';
|
|
3
3
|
export declare function getMockConfig(): ConfigFile | null;
|
|
4
4
|
export declare function setMockConfig(config: ConfigFile | null): void;
|
|
5
5
|
export declare function defaultConfigValues(file: ConfigFile): ConfigFile;
|
|
@@ -31,10 +31,6 @@ export type ConfigFile = {
|
|
|
31
31
|
* FYI: `schemaPath` or `schema` should be defined
|
|
32
32
|
*/
|
|
33
33
|
schema?: string | GraphQLSchema;
|
|
34
|
-
/**
|
|
35
|
-
* A url to use to pull the schema. For more information: https://www.houdinigraphql.com/api/cli#generate
|
|
36
|
-
*/
|
|
37
|
-
apiUrl?: string | ((env: Record<string, string | undefined>) => string);
|
|
38
34
|
/**
|
|
39
35
|
* An object describing custom scalars for your project. For more information: https://www.houdinigraphql.com/api/config#custom-scalars
|
|
40
36
|
*/
|
|
@@ -43,11 +39,6 @@ export type ConfigFile = {
|
|
|
43
39
|
* A path that the generator will use to write schema.graphql and documents.gql files containing all of the internal fragment and directive definitions used in the project.
|
|
44
40
|
*/
|
|
45
41
|
definitionsPath?: string;
|
|
46
|
-
/**
|
|
47
|
-
* One of "kit" or "svelte". Used to tell the preprocessor what kind of loading paradigm to generate for you. (default: `kit`)
|
|
48
|
-
* @deprecated please follow the steps here: http://www.houdinigraphql.com/guides/release-notes#0170
|
|
49
|
-
*/
|
|
50
|
-
framework?: 'kit' | 'svelte';
|
|
51
42
|
/**
|
|
52
43
|
* One of "esm" or "commonjs". Tells the artifact generator what kind of modules to create. (default: `esm`)
|
|
53
44
|
*/
|
|
@@ -59,11 +50,15 @@ export type ConfigFile = {
|
|
|
59
50
|
/**
|
|
60
51
|
* The default cache policy to use for queries. For more information: https://www.houdinigraphql.com/guides/caching-data
|
|
61
52
|
*/
|
|
62
|
-
defaultCachePolicy?:
|
|
53
|
+
defaultCachePolicy?: CachePolicies;
|
|
63
54
|
/**
|
|
64
55
|
* Specifies whether or not the cache should always use partial data. For more information: https://www.houdinigraphql.com/guides/caching-data#partial-data
|
|
65
56
|
*/
|
|
66
57
|
defaultPartial?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Specifies after how long a data goes stale in miliseconds. (default: `undefined`)
|
|
60
|
+
*/
|
|
61
|
+
defaultLifetime?: number;
|
|
67
62
|
/**
|
|
68
63
|
* Specifies whether mutations should append or prepend list. For more information: https://www.houdinigraphql.com/api/graphql (default: `append`)
|
|
69
64
|
*/
|
|
@@ -90,20 +85,9 @@ export type ConfigFile = {
|
|
|
90
85
|
*/
|
|
91
86
|
defaultFragmentMasking?: 'enable' | 'disable';
|
|
92
87
|
/**
|
|
93
|
-
*
|
|
94
|
-
* during development in order to keep it's definition of your schema up to date. The schemaPollingInterval
|
|
95
|
-
* config value sets the amount of time between each request in milliseconds (default 2 seconds).
|
|
96
|
-
* To limit the schema introspection to just on the start of the server, set schemaPollingInterval to 0.
|
|
97
|
-
* To disable the schema introspection, set schemaPollingInterval to null.
|
|
98
|
-
*/
|
|
99
|
-
schemaPollInterval?: number | null;
|
|
100
|
-
/**
|
|
101
|
-
* An object containing the environment variables you want passed onto the api when polling for a new schema.
|
|
102
|
-
* The keys dictate the header names. If the value is a string, the corresponding environment variable will be used
|
|
103
|
-
* directly. If the value is a function, the current environment will be passed to your function so you can perform any
|
|
104
|
-
* logic you need
|
|
88
|
+
* Configure the dev environment to watch a remote schema for changes
|
|
105
89
|
*/
|
|
106
|
-
|
|
90
|
+
watchSchema?: WatchSchemaConfig;
|
|
107
91
|
/**
|
|
108
92
|
* An object describing the plugins enabled for the project
|
|
109
93
|
*/
|
|
@@ -133,6 +117,25 @@ export type TypeConfig = {
|
|
|
133
117
|
};
|
|
134
118
|
};
|
|
135
119
|
};
|
|
120
|
+
export type WatchSchemaConfig = {
|
|
121
|
+
/**
|
|
122
|
+
* A url to use to pull the schema. For more information: https://www.houdinigraphql.com/api/cli#generate
|
|
123
|
+
*/
|
|
124
|
+
url: string | ((env: Record<string, string | undefined>) => string);
|
|
125
|
+
/**
|
|
126
|
+
* sets the amount of time between each request in milliseconds (default 2 seconds).
|
|
127
|
+
* To limit the schema introspection to just on the start of the server, set interval to 0.
|
|
128
|
+
* To disable the schema introspection, set interval to null.
|
|
129
|
+
*/
|
|
130
|
+
interval?: number | null;
|
|
131
|
+
/**
|
|
132
|
+
* An object containing the environment variables you want passed onto the api when polling for a new schema.
|
|
133
|
+
* The keys dictate the header names. If the value is a string, the corresponding environment variable will be used
|
|
134
|
+
* directly. If the value is a function, the current environment will be passed to your function so you can perform any
|
|
135
|
+
* logic you need
|
|
136
|
+
*/
|
|
137
|
+
headers?: Record<string, string | ((env: Record<string, string | undefined>) => string)> | ((env: Record<string, string | undefined>) => Record<string, string>);
|
|
138
|
+
};
|
|
136
139
|
export type ScalarSpec = {
|
|
137
140
|
type: string;
|
|
138
141
|
marshal?: (val: any) => any;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import config from "../imports/config";
|
|
2
|
+
import pluginConfigs from "../imports/pluginConfig";
|
|
2
3
|
let mockConfig = null;
|
|
3
4
|
function getMockConfig() {
|
|
4
5
|
return mockConfig;
|
|
@@ -33,12 +34,21 @@ function computeID(configFile, type, data) {
|
|
|
33
34
|
}
|
|
34
35
|
return id.slice(0, -2);
|
|
35
36
|
}
|
|
37
|
+
let _configFile = null;
|
|
36
38
|
function getCurrentConfig() {
|
|
37
39
|
const mockConfig2 = getMockConfig();
|
|
38
40
|
if (mockConfig2) {
|
|
39
41
|
return mockConfig2;
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
if (_configFile) {
|
|
44
|
+
return _configFile;
|
|
45
|
+
}
|
|
46
|
+
let configFile = defaultConfigValues(config);
|
|
47
|
+
for (const pluginConfig of pluginConfigs) {
|
|
48
|
+
configFile = pluginConfig(configFile);
|
|
49
|
+
}
|
|
50
|
+
_configFile = configFile;
|
|
51
|
+
return configFile;
|
|
42
52
|
}
|
|
43
53
|
export {
|
|
44
54
|
computeID,
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const computeKey = ({ field, args }) => {
|
|
2
|
+
const keys = Object.keys(args ?? {});
|
|
3
|
+
keys.sort();
|
|
4
|
+
return args && keys.length > 0 ? `${field}(${keys.map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(args[key])}`).join(", ")})` : field;
|
|
5
|
+
};
|
|
6
|
+
const stringifyObjectWithNoQuotesOnKeys = (obj_from_json) => {
|
|
7
|
+
if (Array.isArray(obj_from_json)) {
|
|
8
|
+
return `[${obj_from_json.map((obj) => `${stringifyObjectWithNoQuotesOnKeys(obj)}`).join(", ")}]`;
|
|
9
|
+
}
|
|
10
|
+
if (typeof obj_from_json !== "object" || obj_from_json instanceof Date || obj_from_json === null) {
|
|
11
|
+
return JSON.stringify(obj_from_json).replace(/"([^"]+)":/g, "$1: ");
|
|
12
|
+
}
|
|
13
|
+
return `{${Object.keys(obj_from_json).map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(obj_from_json[key])}`).join(", ")}}`;
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
computeKey
|
|
17
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { ConfigFile } from './config';
|
|
2
|
-
import type { MutationArtifact, QueryArtifact, SubscriptionArtifact, SubscriptionSelection } from './types';
|
|
2
|
+
import type { FragmentArtifact, MutationArtifact, QueryArtifact, SubscriptionArtifact, SubscriptionSelection } from './types';
|
|
3
3
|
export declare function marshalSelection({ selection, data, }: {
|
|
4
4
|
selection: SubscriptionSelection;
|
|
5
5
|
data: any;
|
|
6
6
|
}): Promise<{} | null | undefined>;
|
|
7
7
|
export declare function marshalInputs<T>({ artifact, input, config, rootType, }: {
|
|
8
|
-
artifact: QueryArtifact | MutationArtifact | SubscriptionArtifact;
|
|
8
|
+
artifact: QueryArtifact | MutationArtifact | SubscriptionArtifact | FragmentArtifact;
|
|
9
9
|
input: unknown;
|
|
10
10
|
rootType?: string;
|
|
11
11
|
config: ConfigFile;
|
|
12
12
|
}): {} | null | undefined;
|
|
13
13
|
export declare function unmarshalSelection(config: ConfigFile, selection: SubscriptionSelection, data: any): {} | null | undefined;
|
|
14
14
|
export declare function isScalar(config: ConfigFile, type: string): boolean;
|
|
15
|
-
export declare function parseScalar(config: ConfigFile, type: string, value
|
|
15
|
+
export declare function parseScalar(config: ConfigFile, type: string, value?: string): string | number | boolean | undefined;
|