houdini 1.0.0-next.1 → 1.0.0-next.3
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/generate.d.ts +0 -1
- package/build/cmd-cjs/index.js +1400 -2836
- package/build/cmd-esm/index.js +1400 -2836
- package/build/codegen/generators/artifacts/fieldKey.d.ts +1 -1
- package/build/codegen/generators/artifacts/index.d.ts +1 -1
- package/build/codegen/generators/artifacts/indexFile.d.ts +1 -1
- package/build/codegen/generators/artifacts/inputs.d.ts +2 -2
- package/build/codegen/generators/artifacts/operations.d.ts +2 -2
- package/build/codegen/generators/artifacts/selection.d.ts +1 -1
- package/build/codegen/generators/artifacts/utils.d.ts +1 -1
- package/build/codegen/generators/definitions/enums.d.ts +1 -1
- package/build/codegen/generators/definitions/index.d.ts +1 -1
- package/build/codegen/generators/indexFile/index.d.ts +1 -1
- package/build/codegen/generators/persistedQueries/index.d.ts +1 -1
- package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -0
- package/build/codegen/generators/runtime/index.d.ts +1 -1
- package/build/codegen/generators/runtime/injectPlugins.d.ts +7 -0
- package/build/codegen/generators/runtime/pluginIndex.d.ts +5 -0
- package/build/codegen/generators/typescript/addReferencedInputTypes.d.ts +1 -1
- package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
- package/build/codegen/generators/typescript/{imperativeCache.d.ts → imperativeTypeDef.d.ts} +1 -1
- package/build/codegen/generators/typescript/index.d.ts +1 -1
- package/build/codegen/generators/typescript/inlineType.d.ts +1 -1
- package/build/codegen/generators/typescript/typeReference.d.ts +1 -1
- package/build/codegen/generators/typescript/types.d.ts +1 -1
- package/build/codegen/index.d.ts +1 -1
- package/build/codegen/transforms/addID.d.ts +1 -1
- package/build/codegen/transforms/composeQueries.d.ts +2 -2
- package/build/codegen/transforms/fragmentVariables.d.ts +3 -2
- package/build/codegen/transforms/list.d.ts +1 -1
- package/build/codegen/transforms/paginate.d.ts +1 -1
- package/build/codegen/transforms/schema.d.ts +1 -1
- package/build/codegen/transforms/typename.d.ts +1 -1
- package/build/codegen/utils/commonjs.d.ts +2 -0
- package/build/codegen/utils/flattenSelections.d.ts +2 -2
- package/build/codegen/utils/moduleExport.d.ts +1 -1
- package/build/codegen/utils/objectIdentificationSelection.d.ts +1 -1
- package/build/codegen/validators/noIDAlias.d.ts +1 -1
- package/build/codegen/validators/typeCheck.d.ts +1 -1
- package/build/codegen-cjs/index.js +1320 -2779
- package/build/codegen-esm/index.js +1320 -2779
- package/build/lib/config.d.ts +9 -4
- package/build/lib/fs.d.ts +1 -1
- package/build/lib/graphql.d.ts +1 -1
- package/build/lib/imports.d.ts +1 -1
- package/build/lib/types.d.ts +3 -3
- package/build/lib/walk.d.ts +8 -5
- package/build/lib-cjs/index.js +155 -1856
- package/build/lib-esm/index.js +155 -1856
- package/build/runtime/cache/cache.d.ts +10 -8
- package/build/runtime/cache/gc.d.ts +1 -1
- package/build/runtime/cache/lists.d.ts +3 -2
- package/build/runtime/cache/schema.d.ts +2 -2
- package/build/runtime/cache/stuff.d.ts +2 -2
- package/build/runtime/cache/subscription.d.ts +19 -11
- package/build/runtime/client/documentStore.d.ts +87 -0
- package/build/runtime/client/index.d.ts +25 -0
- package/build/runtime/client/plugins/cache.d.ts +8 -0
- package/build/runtime/client/plugins/fetch.d.ts +37 -0
- package/build/runtime/client/plugins/fetchParams.d.ts +9 -0
- package/build/runtime/client/plugins/index.d.ts +7 -0
- package/build/runtime/client/plugins/injectedPlugins.d.ts +3 -0
- package/build/runtime/client/plugins/mutation.d.ts +1 -0
- package/build/runtime/client/plugins/query.d.ts +2 -0
- package/build/runtime/client/plugins/subscription.d.ts +18 -0
- package/build/runtime/client/plugins/throwOnError.d.ts +7 -0
- package/build/runtime/client/utils/documentPlugins.d.ts +3 -0
- package/build/runtime/client/utils/index.d.ts +1 -0
- package/build/runtime/generated.d.ts +1 -0
- package/build/runtime/imports/config.d.ts +3 -0
- package/build/runtime/index.d.ts +3 -2
- package/build/runtime/lib/config.d.ts +26 -25
- package/build/runtime/lib/index.d.ts +1 -2
- package/build/runtime/lib/scalars.d.ts +6 -5
- package/build/runtime/lib/selection.d.ts +1 -1
- package/build/runtime/lib/store.d.ts +19 -0
- package/build/runtime/lib/types.d.ts +22 -9
- package/build/runtime/public/cache.d.ts +20 -7
- package/build/runtime/public/list.d.ts +2 -2
- package/build/runtime/public/record.d.ts +18 -18
- package/build/runtime/public/tests/test.d.ts +44 -1
- package/build/runtime/public/types.d.ts +8 -0
- package/build/runtime-cjs/cache/cache.d.ts +10 -8
- package/build/runtime-cjs/cache/cache.js +5 -11
- package/build/runtime-cjs/cache/gc.d.ts +1 -1
- package/build/runtime-cjs/cache/lists.d.ts +3 -2
- package/build/runtime-cjs/cache/lists.js +5 -2
- package/build/runtime-cjs/cache/schema.d.ts +2 -2
- package/build/runtime-cjs/cache/stuff.d.ts +2 -2
- package/build/runtime-cjs/cache/subscription.d.ts +19 -11
- package/build/runtime-cjs/cache/subscription.js +95 -56
- package/build/runtime-cjs/client/documentStore.d.ts +87 -0
- package/build/runtime-cjs/client/documentStore.js +360 -0
- package/build/runtime-cjs/client/index.d.ts +25 -0
- package/build/runtime-cjs/client/index.js +87 -0
- package/build/runtime-cjs/client/plugins/cache.d.ts +8 -0
- package/build/runtime-cjs/client/plugins/cache.js +99 -0
- package/build/runtime-cjs/client/plugins/fetch.d.ts +37 -0
- package/build/runtime-cjs/{lib/networkUtils.js → client/plugins/fetch.js} +95 -3
- package/build/runtime-cjs/client/plugins/fetchParams.d.ts +9 -0
- package/build/runtime-cjs/client/plugins/fetchParams.js +40 -0
- package/build/runtime-cjs/client/plugins/index.d.ts +7 -0
- package/build/runtime-cjs/client/plugins/index.js +24 -0
- package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +3 -0
- package/build/runtime-cjs/{lib/errors.js → client/plugins/injectedPlugins.js} +7 -15
- package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -0
- package/build/runtime-cjs/client/plugins/mutation.js +86 -0
- package/build/runtime-cjs/client/plugins/query.d.ts +2 -0
- package/build/runtime-cjs/client/plugins/query.js +83 -0
- package/build/runtime-cjs/client/plugins/subscription.d.ts +18 -0
- package/build/runtime-cjs/client/plugins/subscription.js +98 -0
- package/build/runtime-cjs/client/plugins/throwOnError.d.ts +7 -0
- package/build/runtime-cjs/client/plugins/throwOnError.js +47 -0
- package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -0
- package/build/runtime-cjs/client/utils/documentPlugins.js +56 -0
- package/build/runtime-cjs/client/utils/index.d.ts +1 -0
- package/build/runtime-cjs/client/utils/index.js +18 -0
- package/build/runtime-cjs/generated.d.ts +1 -0
- package/build/runtime-cjs/imports/config.d.ts +3 -0
- package/build/runtime-cjs/imports/config.js +26 -0
- package/build/runtime-cjs/index.d.ts +3 -2
- package/build/runtime-cjs/index.js +1 -0
- package/build/runtime-cjs/lib/config.d.ts +26 -25
- package/build/runtime-cjs/lib/config.js +5 -4
- package/build/runtime-cjs/lib/index.d.ts +1 -2
- package/build/runtime-cjs/lib/index.js +1 -2
- package/build/runtime-cjs/lib/scalars.d.ts +6 -5
- package/build/runtime-cjs/lib/scalars.js +20 -24
- package/build/runtime-cjs/lib/selection.d.ts +1 -1
- package/build/runtime-cjs/lib/store.d.ts +19 -0
- package/build/runtime-cjs/lib/store.js +81 -0
- package/build/runtime-cjs/lib/types.d.ts +22 -9
- package/build/runtime-cjs/public/cache.d.ts +20 -7
- package/build/runtime-cjs/public/cache.js +29 -32
- package/build/runtime-cjs/public/list.d.ts +2 -2
- package/build/runtime-cjs/public/list.js +6 -28
- package/build/runtime-cjs/public/record.d.ts +18 -18
- package/build/runtime-cjs/public/record.js +23 -189
- package/build/runtime-cjs/public/tests/test.d.ts +44 -1
- 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 +10 -8
- package/build/runtime-esm/cache/cache.js +5 -11
- package/build/runtime-esm/cache/gc.d.ts +1 -1
- package/build/runtime-esm/cache/lists.d.ts +3 -2
- package/build/runtime-esm/cache/lists.js +5 -2
- package/build/runtime-esm/cache/schema.d.ts +2 -2
- package/build/runtime-esm/cache/stuff.d.ts +2 -2
- package/build/runtime-esm/cache/subscription.d.ts +19 -11
- package/build/runtime-esm/cache/subscription.js +95 -56
- package/build/runtime-esm/client/documentStore.d.ts +87 -0
- package/build/runtime-esm/client/documentStore.js +336 -0
- package/build/runtime-esm/client/index.d.ts +25 -0
- package/build/runtime-esm/client/index.js +58 -0
- package/build/runtime-esm/client/plugins/cache.d.ts +8 -0
- package/build/runtime-esm/client/plugins/cache.js +69 -0
- package/build/runtime-esm/client/plugins/fetch.d.ts +37 -0
- package/build/runtime-esm/client/plugins/fetch.js +151 -0
- package/build/runtime-esm/client/plugins/fetchParams.d.ts +9 -0
- package/build/runtime-esm/client/plugins/fetchParams.js +16 -0
- package/build/runtime-esm/client/plugins/index.d.ts +7 -0
- package/build/runtime-esm/client/plugins/index.js +7 -0
- package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +3 -0
- package/build/runtime-esm/client/plugins/injectedPlugins.js +5 -0
- package/build/runtime-esm/client/plugins/mutation.d.ts +1 -0
- package/build/runtime-esm/client/plugins/mutation.js +56 -0
- package/build/runtime-esm/client/plugins/query.d.ts +2 -0
- package/build/runtime-esm/client/plugins/query.js +53 -0
- package/build/runtime-esm/client/plugins/subscription.d.ts +18 -0
- package/build/runtime-esm/client/plugins/subscription.js +74 -0
- package/build/runtime-esm/client/plugins/throwOnError.d.ts +7 -0
- package/build/runtime-esm/client/plugins/throwOnError.js +23 -0
- package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -0
- package/build/runtime-esm/client/utils/documentPlugins.js +32 -0
- package/build/runtime-esm/client/utils/index.d.ts +1 -0
- package/build/runtime-esm/client/utils/index.js +1 -0
- package/build/runtime-esm/generated.d.ts +1 -0
- package/build/runtime-esm/imports/config.d.ts +3 -0
- package/build/runtime-esm/imports/config.js +4 -0
- package/build/runtime-esm/index.d.ts +3 -2
- package/build/runtime-esm/index.js +1 -0
- package/build/runtime-esm/lib/config.d.ts +26 -25
- package/build/runtime-esm/lib/config.js +5 -4
- package/build/runtime-esm/lib/index.d.ts +1 -2
- package/build/runtime-esm/lib/index.js +1 -2
- package/build/runtime-esm/lib/scalars.d.ts +6 -5
- package/build/runtime-esm/lib/scalars.js +20 -24
- package/build/runtime-esm/lib/selection.d.ts +1 -1
- package/build/runtime-esm/lib/store.d.ts +19 -0
- package/build/runtime-esm/lib/store.js +57 -0
- package/build/runtime-esm/lib/types.d.ts +22 -9
- package/build/runtime-esm/public/cache.d.ts +20 -7
- package/build/runtime-esm/public/cache.js +28 -30
- package/build/runtime-esm/public/list.d.ts +2 -2
- package/build/runtime-esm/public/list.js +6 -28
- package/build/runtime-esm/public/record.d.ts +18 -18
- package/build/runtime-esm/public/record.js +22 -185
- package/build/runtime-esm/public/tests/test.d.ts +44 -1
- 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 +4 -3
- package/build/test-cjs/index.js +1334 -2766
- package/build/test-esm/index.js +1334 -2766
- package/build/vite/ast.d.ts +1 -1
- package/build/vite/houdini.d.ts +1 -1
- package/build/vite/imports.d.ts +3 -3
- package/build/vite/index.d.ts +1 -1
- package/build/vite/schema.d.ts +1 -1
- package/build/vite-cjs/index.js +1395 -2821
- package/build/vite-esm/index.js +1395 -2821
- package/package.json +1 -1
- package/build/runtime/lib/errors.d.ts +0 -3
- package/build/runtime/lib/network.d.ts +0 -79
- package/build/runtime/lib/networkUtils.d.ts +0 -8
- package/build/runtime-cjs/lib/errors.d.ts +0 -3
- package/build/runtime-cjs/lib/network.d.ts +0 -79
- package/build/runtime-cjs/lib/network.js +0 -200
- package/build/runtime-cjs/lib/networkUtils.d.ts +0 -8
- package/build/runtime-esm/lib/errors.d.ts +0 -3
- package/build/runtime-esm/lib/errors.js +0 -11
- package/build/runtime-esm/lib/network.d.ts +0 -79
- package/build/runtime-esm/lib/network.js +0 -170
- package/build/runtime-esm/lib/networkUtils.d.ts +0 -8
- package/build/runtime-esm/lib/networkUtils.js +0 -60
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DocumentStore } from "./documentStore";
|
|
2
|
+
import {
|
|
3
|
+
fetchParamsPlugin,
|
|
4
|
+
fetchPlugin,
|
|
5
|
+
mutationPlugin,
|
|
6
|
+
queryPlugin,
|
|
7
|
+
throwOnErrorPlugin
|
|
8
|
+
} from "./plugins";
|
|
9
|
+
import pluginsFromPlugins from "./plugins/injectedPlugins";
|
|
10
|
+
import { DocumentStore as DocumentStore2 } from "./documentStore";
|
|
11
|
+
import { fetchPlugin as fetchPlugin2, mutationPlugin as mutationPlugin2, queryPlugin as queryPlugin2, subscriptionPlugin } from "./plugins";
|
|
12
|
+
class HoudiniClient {
|
|
13
|
+
url;
|
|
14
|
+
#plugins;
|
|
15
|
+
constructor({ url, fetchParams, plugins, pipeline, throwOnError }) {
|
|
16
|
+
if (plugins && pipeline) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
"A client cannot be given a pipeline and a list of plugins at the same time."
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
this.#plugins = [].concat(
|
|
22
|
+
throwOnError ? [throwOnErrorPlugin(throwOnError)] : [],
|
|
23
|
+
fetchParamsPlugin(fetchParams),
|
|
24
|
+
pipeline ?? [
|
|
25
|
+
queryPlugin,
|
|
26
|
+
mutationPlugin
|
|
27
|
+
].concat(
|
|
28
|
+
plugins ?? [],
|
|
29
|
+
pluginsFromPlugins,
|
|
30
|
+
fetchPlugin()
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
this.url = url;
|
|
34
|
+
}
|
|
35
|
+
observe({
|
|
36
|
+
artifact,
|
|
37
|
+
cache = true,
|
|
38
|
+
initialValue,
|
|
39
|
+
fetching = false
|
|
40
|
+
}) {
|
|
41
|
+
return new DocumentStore({
|
|
42
|
+
client: this,
|
|
43
|
+
artifact,
|
|
44
|
+
plugins: this.#plugins,
|
|
45
|
+
cache,
|
|
46
|
+
initialValue,
|
|
47
|
+
fetching
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
DocumentStore2 as DocumentStore,
|
|
53
|
+
HoudiniClient,
|
|
54
|
+
fetchPlugin2 as fetchPlugin,
|
|
55
|
+
mutationPlugin2 as mutationPlugin,
|
|
56
|
+
queryPlugin2 as queryPlugin,
|
|
57
|
+
subscriptionPlugin
|
|
58
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import cache from '../../cache';
|
|
2
|
+
import type { Cache } from '../../cache/cache';
|
|
3
|
+
import type { ClientPlugin } from '../documentStore';
|
|
4
|
+
export declare const cachePolicyPlugin: ({ enabled, setFetching, cache: localCache, }: {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
setFetching: (val: boolean) => void;
|
|
7
|
+
cache?: Cache | undefined;
|
|
8
|
+
}) => ClientPlugin;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import cache from "../../cache";
|
|
2
|
+
import { ArtifactKind, CachePolicy, DataSource } from "../../lib/types";
|
|
3
|
+
const cachePolicyPlugin = ({
|
|
4
|
+
enabled,
|
|
5
|
+
setFetching,
|
|
6
|
+
cache: localCache = cache
|
|
7
|
+
}) => () => {
|
|
8
|
+
return {
|
|
9
|
+
network(ctx, { next, resolve, marshalVariables }) {
|
|
10
|
+
const { policy, artifact } = ctx;
|
|
11
|
+
let useCache = false;
|
|
12
|
+
if (enabled && artifact.kind === ArtifactKind.Query && !ctx.cacheParams?.disableRead) {
|
|
13
|
+
if (policy !== CachePolicy.NetworkOnly) {
|
|
14
|
+
const value = localCache.read({
|
|
15
|
+
selection: artifact.selection,
|
|
16
|
+
variables: marshalVariables(ctx)
|
|
17
|
+
});
|
|
18
|
+
const allowed = !value.partial || artifact.kind === ArtifactKind.Query && artifact.partial;
|
|
19
|
+
if (policy === CachePolicy.CacheOnly) {
|
|
20
|
+
return resolve(ctx, {
|
|
21
|
+
fetching: false,
|
|
22
|
+
variables: ctx.variables ?? null,
|
|
23
|
+
data: value.data,
|
|
24
|
+
errors: null,
|
|
25
|
+
source: DataSource.Cache,
|
|
26
|
+
partial: value.partial
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
useCache = !!(value.data !== null && allowed);
|
|
30
|
+
if (useCache) {
|
|
31
|
+
resolve(ctx, {
|
|
32
|
+
fetching: false,
|
|
33
|
+
variables: ctx.variables ?? null,
|
|
34
|
+
data: value.data,
|
|
35
|
+
errors: null,
|
|
36
|
+
source: DataSource.Cache,
|
|
37
|
+
partial: value.partial
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (useCache && !value.partial) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (enabled) {
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
localCache._internal_unstable.collectGarbage();
|
|
48
|
+
}, 0);
|
|
49
|
+
}
|
|
50
|
+
setFetching(!useCache);
|
|
51
|
+
return next(ctx);
|
|
52
|
+
},
|
|
53
|
+
afterNetwork(ctx, { resolve, value, marshalVariables }) {
|
|
54
|
+
if (value.source !== DataSource.Cache && enabled && value.data && !ctx.cacheParams?.disableWrite) {
|
|
55
|
+
localCache.write({
|
|
56
|
+
...ctx.cacheParams,
|
|
57
|
+
layer: ctx.cacheParams?.layer?.id,
|
|
58
|
+
selection: ctx.artifact.selection,
|
|
59
|
+
data: value.data,
|
|
60
|
+
variables: marshalVariables(ctx)
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
resolve(ctx, value);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
cachePolicyPlugin
|
|
69
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RequestPayload } from '../../lib/types';
|
|
2
|
+
import type { ClientPlugin } from '../documentStore';
|
|
3
|
+
export declare const fetchPlugin: (target?: RequestHandler | string) => ClientPlugin;
|
|
4
|
+
export type FetchContext = {
|
|
5
|
+
fetch: typeof globalThis.fetch;
|
|
6
|
+
metadata?: App.Metadata | null;
|
|
7
|
+
session: App.Session | null;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* ## Tip 👇
|
|
11
|
+
*
|
|
12
|
+
* To define types for your metadata, create a file `src/app.d.ts` containing the followingI:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* declare namespace App { *
|
|
16
|
+
* interface Metadata {}
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export type RequestHandlerArgs = FetchContext & FetchParams;
|
|
22
|
+
export type RequestHandler<_Data = any> = (args: RequestHandlerArgs) => Promise<RequestPayload<_Data>>;
|
|
23
|
+
export type FetchParams = {
|
|
24
|
+
text: string;
|
|
25
|
+
hash: string;
|
|
26
|
+
variables: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare function isExtractableFile(value: any): value is ExtractableFile;
|
|
31
|
+
type ExtractableFile = File | Blob;
|
|
32
|
+
/** @typedef {import("./isExtractableFile.mjs").default} isExtractableFile */
|
|
33
|
+
export declare function extractFiles(value: any): {
|
|
34
|
+
clone: any;
|
|
35
|
+
files: Map<any, any>;
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { DataSource } from "../../lib/types";
|
|
2
|
+
const fetchPlugin = (target) => {
|
|
3
|
+
return () => {
|
|
4
|
+
return {
|
|
5
|
+
async network(ctx, { client, resolve, marshalVariables }) {
|
|
6
|
+
const fetch = ctx.fetch ?? globalThis.fetch;
|
|
7
|
+
const fetchParams = {
|
|
8
|
+
text: ctx.text,
|
|
9
|
+
hash: ctx.hash,
|
|
10
|
+
variables: marshalVariables(ctx)
|
|
11
|
+
};
|
|
12
|
+
let fetchFn = defaultFetch(client.url, ctx.fetchParams);
|
|
13
|
+
if (target) {
|
|
14
|
+
if (typeof target === "string") {
|
|
15
|
+
fetchFn = defaultFetch(target, ctx.fetchParams);
|
|
16
|
+
} else {
|
|
17
|
+
fetchFn = target;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const result = await fetchFn({
|
|
21
|
+
fetch: (url, args) => {
|
|
22
|
+
const newArgs = handleMultipart(fetchParams, args) ?? args;
|
|
23
|
+
return fetch(url, newArgs);
|
|
24
|
+
},
|
|
25
|
+
metadata: ctx.metadata,
|
|
26
|
+
session: ctx.session || {},
|
|
27
|
+
...fetchParams
|
|
28
|
+
});
|
|
29
|
+
resolve(ctx, {
|
|
30
|
+
fetching: false,
|
|
31
|
+
variables: ctx.variables ?? null,
|
|
32
|
+
data: result.data,
|
|
33
|
+
errors: !result.errors || result.errors.length === 0 ? null : result.errors,
|
|
34
|
+
partial: false,
|
|
35
|
+
source: DataSource.Network
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const defaultFetch = (url, params) => {
|
|
42
|
+
if (!url) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"Could not find configured client url. Please specify one in your houdini.config.js file."
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return async ({ fetch, text, variables }) => {
|
|
48
|
+
const result = await fetch(url, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
body: JSON.stringify({ query: text, variables }),
|
|
51
|
+
...params,
|
|
52
|
+
headers: {
|
|
53
|
+
Accept: "application/graphql+json, application/json",
|
|
54
|
+
"Content-Type": "application/json",
|
|
55
|
+
...params?.headers
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return await result.json();
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
function handleMultipart(params, args) {
|
|
62
|
+
const { clone, files } = extractFiles({
|
|
63
|
+
query: params.text,
|
|
64
|
+
variables: params.variables
|
|
65
|
+
});
|
|
66
|
+
if (files.size) {
|
|
67
|
+
const req = args;
|
|
68
|
+
let headers = {};
|
|
69
|
+
if (req?.headers) {
|
|
70
|
+
const filtered = Object.entries(req?.headers).filter(([key, value]) => {
|
|
71
|
+
return !(key.toLowerCase() == "content-type" && value.toLowerCase() == "application/json");
|
|
72
|
+
});
|
|
73
|
+
headers = Object.fromEntries(filtered);
|
|
74
|
+
}
|
|
75
|
+
const form = new FormData();
|
|
76
|
+
const operationJSON = JSON.stringify(clone);
|
|
77
|
+
form.set("operations", operationJSON);
|
|
78
|
+
const map = {};
|
|
79
|
+
let i = 0;
|
|
80
|
+
files.forEach((paths) => {
|
|
81
|
+
map[++i] = paths;
|
|
82
|
+
});
|
|
83
|
+
form.set("map", JSON.stringify(map));
|
|
84
|
+
i = 0;
|
|
85
|
+
files.forEach((paths, file) => {
|
|
86
|
+
form.set(`${++i}`, file, file.name);
|
|
87
|
+
});
|
|
88
|
+
return { ...req, headers, body: form };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function isExtractableFile(value) {
|
|
92
|
+
return typeof File !== "undefined" && value instanceof File || typeof Blob !== "undefined" && value instanceof Blob;
|
|
93
|
+
}
|
|
94
|
+
function extractFiles(value) {
|
|
95
|
+
if (!arguments.length)
|
|
96
|
+
throw new TypeError("Argument 1 `value` is required.");
|
|
97
|
+
const clones = /* @__PURE__ */ new Map();
|
|
98
|
+
const files = /* @__PURE__ */ new Map();
|
|
99
|
+
function recurse(value2, path, recursed) {
|
|
100
|
+
if (isExtractableFile(value2)) {
|
|
101
|
+
const filePaths = files.get(value2);
|
|
102
|
+
filePaths ? filePaths.push(path) : files.set(value2, [path]);
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const valueIsList = Array.isArray(value2) || typeof FileList !== "undefined" && value2 instanceof FileList;
|
|
106
|
+
const valueIsPlainObject = isPlainObject(value2);
|
|
107
|
+
if (valueIsList || valueIsPlainObject) {
|
|
108
|
+
let clone = clones.get(value2);
|
|
109
|
+
const uncloned = !clone;
|
|
110
|
+
if (uncloned) {
|
|
111
|
+
clone = valueIsList ? [] : value2 instanceof Object ? {} : /* @__PURE__ */ Object.create(null);
|
|
112
|
+
clones.set(value2, clone);
|
|
113
|
+
}
|
|
114
|
+
if (!recursed.has(value2)) {
|
|
115
|
+
const pathPrefix = path ? `${path}.` : "";
|
|
116
|
+
const recursedDeeper = new Set(recursed).add(value2);
|
|
117
|
+
if (valueIsList) {
|
|
118
|
+
let index = 0;
|
|
119
|
+
for (const item of value2) {
|
|
120
|
+
const itemClone = recurse(item, pathPrefix + index++, recursedDeeper);
|
|
121
|
+
if (uncloned)
|
|
122
|
+
clone.push(itemClone);
|
|
123
|
+
}
|
|
124
|
+
} else
|
|
125
|
+
for (const key in value2) {
|
|
126
|
+
const propertyClone = recurse(value2[key], pathPrefix + key, recursedDeeper);
|
|
127
|
+
if (uncloned)
|
|
128
|
+
clone[key] = propertyClone;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return clone;
|
|
132
|
+
}
|
|
133
|
+
return value2;
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
clone: recurse(value, "", /* @__PURE__ */ new Set()),
|
|
137
|
+
files
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function isPlainObject(value) {
|
|
141
|
+
if (typeof value !== "object" || value === null) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
const prototype = Object.getPrototypeOf(value);
|
|
145
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
146
|
+
}
|
|
147
|
+
export {
|
|
148
|
+
extractFiles,
|
|
149
|
+
fetchPlugin,
|
|
150
|
+
isExtractableFile
|
|
151
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DocumentArtifact } from '../../lib/types';
|
|
2
|
+
import type { ClientPlugin, ClientPluginContext } from '../documentStore';
|
|
3
|
+
export type FetchParamFn = (ctx: FetchParamsInput) => Required<ClientPluginContext>['fetchParams'];
|
|
4
|
+
export declare const fetchParamsPlugin: (fn?: FetchParamFn) => ClientPlugin;
|
|
5
|
+
export type FetchParamsInput = Pick<ClientPluginContext, 'config' | 'policy' | 'variables' | 'metadata' | 'session' | 'stuff'> & {
|
|
6
|
+
text: string;
|
|
7
|
+
hash: string;
|
|
8
|
+
artifact: DocumentArtifact;
|
|
9
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const fetchParamsPlugin = (fn = () => ({})) => () => ({
|
|
2
|
+
beforeNetwork(ctx, { next, marshalVariables }) {
|
|
3
|
+
next({
|
|
4
|
+
...ctx,
|
|
5
|
+
fetchParams: fn({
|
|
6
|
+
...ctx,
|
|
7
|
+
variables: marshalVariables(ctx),
|
|
8
|
+
text: ctx.artifact.raw,
|
|
9
|
+
hash: ctx.artifact.hash
|
|
10
|
+
})
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
export {
|
|
15
|
+
fetchParamsPlugin
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mutationPlugin: import("..").ClientPlugin;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import cache from "../../cache";
|
|
2
|
+
import { marshalSelection } from "../../lib/scalars";
|
|
3
|
+
import { ArtifactKind } from "../../lib/types";
|
|
4
|
+
import { documentPlugin } from "../utils";
|
|
5
|
+
const mutationPlugin = documentPlugin(ArtifactKind.Mutation, () => {
|
|
6
|
+
return {
|
|
7
|
+
async start(ctx, { next, marshalVariables }) {
|
|
8
|
+
const layer = cache._internal_unstable.storage.createLayer(true);
|
|
9
|
+
const optimisticResponse = ctx.stuff.optimisticResponse;
|
|
10
|
+
let toNotify = [];
|
|
11
|
+
if (optimisticResponse) {
|
|
12
|
+
toNotify = cache.write({
|
|
13
|
+
selection: ctx.artifact.selection,
|
|
14
|
+
data: await marshalSelection({
|
|
15
|
+
selection: ctx.artifact.selection,
|
|
16
|
+
data: optimisticResponse
|
|
17
|
+
}),
|
|
18
|
+
variables: marshalVariables(ctx),
|
|
19
|
+
layer: layer.id
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
ctx.cacheParams = {
|
|
23
|
+
...ctx.cacheParams,
|
|
24
|
+
layer,
|
|
25
|
+
notifySubscribers: toNotify,
|
|
26
|
+
forceNotify: true
|
|
27
|
+
};
|
|
28
|
+
next(ctx);
|
|
29
|
+
},
|
|
30
|
+
afterNetwork(ctx, { resolve }) {
|
|
31
|
+
ctx.cacheParams?.layer?.clear();
|
|
32
|
+
resolve(ctx);
|
|
33
|
+
},
|
|
34
|
+
end(ctx, { resolve, value }) {
|
|
35
|
+
const hasErrors = value.errors && value.errors.length > 0;
|
|
36
|
+
if (hasErrors) {
|
|
37
|
+
ctx.cacheParams?.layer?.clear();
|
|
38
|
+
}
|
|
39
|
+
if (ctx.cacheParams?.layer) {
|
|
40
|
+
cache._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
|
|
41
|
+
}
|
|
42
|
+
resolve(ctx);
|
|
43
|
+
},
|
|
44
|
+
catch(ctx, { error }) {
|
|
45
|
+
if (ctx.cacheParams?.layer) {
|
|
46
|
+
const { layer } = ctx.cacheParams;
|
|
47
|
+
layer.clear();
|
|
48
|
+
cache._internal_unstable.storage.resolveLayer(layer.id);
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
export {
|
|
55
|
+
mutationPlugin
|
|
56
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import cache from "../../cache";
|
|
2
|
+
import { ArtifactKind, DataSource } from "../../lib/types";
|
|
3
|
+
import { documentPlugin } from "../utils";
|
|
4
|
+
const queryPlugin = documentPlugin(ArtifactKind.Query, function() {
|
|
5
|
+
let subscriptionSpec = null;
|
|
6
|
+
let lastVariables = null;
|
|
7
|
+
let artifactName = "";
|
|
8
|
+
return {
|
|
9
|
+
start(ctx, { next }) {
|
|
10
|
+
ctx.variables = {
|
|
11
|
+
...lastVariables,
|
|
12
|
+
...ctx.variables
|
|
13
|
+
};
|
|
14
|
+
next(ctx);
|
|
15
|
+
},
|
|
16
|
+
end(ctx, { resolve, marshalVariables, variablesChanged }) {
|
|
17
|
+
if (variablesChanged(ctx)) {
|
|
18
|
+
artifactName = ctx.artifact.name;
|
|
19
|
+
if (subscriptionSpec) {
|
|
20
|
+
cache.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
|
|
21
|
+
}
|
|
22
|
+
lastVariables = { ...marshalVariables(ctx) };
|
|
23
|
+
subscriptionSpec = {
|
|
24
|
+
rootType: ctx.artifact.rootType,
|
|
25
|
+
selection: ctx.artifact.selection,
|
|
26
|
+
variables: () => lastVariables,
|
|
27
|
+
set: (newValue) => {
|
|
28
|
+
console.log("setting from cache update");
|
|
29
|
+
resolve(ctx, {
|
|
30
|
+
data: newValue,
|
|
31
|
+
errors: null,
|
|
32
|
+
fetching: false,
|
|
33
|
+
partial: false,
|
|
34
|
+
source: DataSource.Cache,
|
|
35
|
+
variables: ctx.variables ?? null
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
cache.subscribe(subscriptionSpec, lastVariables ?? {});
|
|
40
|
+
}
|
|
41
|
+
resolve(ctx);
|
|
42
|
+
},
|
|
43
|
+
cleanup() {
|
|
44
|
+
if (subscriptionSpec) {
|
|
45
|
+
cache.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() ?? {});
|
|
46
|
+
lastVariables = null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
export {
|
|
52
|
+
queryPlugin
|
|
53
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GraphQLObject } from '../../lib/types';
|
|
2
|
+
import type { ClientPluginContext } from '../documentStore';
|
|
3
|
+
export declare function subscriptionPlugin(factory: SubscriptionHandler): import("../documentStore").ClientPlugin;
|
|
4
|
+
export type SubscriptionHandler = (ctx: ClientPluginContext) => {
|
|
5
|
+
subscribe: (payload: {
|
|
6
|
+
query: string;
|
|
7
|
+
variables?: {};
|
|
8
|
+
}, handlers: {
|
|
9
|
+
next: (payload: {
|
|
10
|
+
data?: GraphQLObject;
|
|
11
|
+
errors?: readonly {
|
|
12
|
+
message: string;
|
|
13
|
+
}[];
|
|
14
|
+
}) => void;
|
|
15
|
+
error: (data: {}) => void;
|
|
16
|
+
complete: () => void;
|
|
17
|
+
}) => () => void;
|
|
18
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { deepEquals } from "../../lib/deepEquals";
|
|
2
|
+
import { ArtifactKind, DataSource } from "../../lib/types";
|
|
3
|
+
import { documentPlugin } from "../utils";
|
|
4
|
+
function subscriptionPlugin(factory) {
|
|
5
|
+
return documentPlugin(ArtifactKind.Subscription, () => {
|
|
6
|
+
let clearSubscription = null;
|
|
7
|
+
let socketClient = null;
|
|
8
|
+
let check = null;
|
|
9
|
+
return {
|
|
10
|
+
start(ctx, { resolve, next, initialValue }) {
|
|
11
|
+
if (typeof globalThis.window === "undefined") {
|
|
12
|
+
resolve(ctx, initialValue);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
next(ctx);
|
|
16
|
+
},
|
|
17
|
+
network(ctx, { resolve, initialValue, variablesChanged, marshalVariables }) {
|
|
18
|
+
const checkValue = {
|
|
19
|
+
fetchParams: ctx.fetchParams ?? {},
|
|
20
|
+
session: ctx.session ?? {},
|
|
21
|
+
metadata: ctx.metadata ?? {}
|
|
22
|
+
};
|
|
23
|
+
const changed = variablesChanged(ctx);
|
|
24
|
+
const sessionChange = !deepEquals(check, checkValue);
|
|
25
|
+
if (!changed && !sessionChange) {
|
|
26
|
+
resolve(ctx, initialValue);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
check = checkValue;
|
|
30
|
+
clearSubscription?.();
|
|
31
|
+
if (!socketClient || sessionChange) {
|
|
32
|
+
socketClient = factory(ctx);
|
|
33
|
+
}
|
|
34
|
+
clearSubscription = socketClient.subscribe(
|
|
35
|
+
{
|
|
36
|
+
query: ctx.artifact.raw,
|
|
37
|
+
variables: marshalVariables(ctx)
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
next: ({ data, errors }) => {
|
|
41
|
+
resolve(ctx, {
|
|
42
|
+
data: data ?? null,
|
|
43
|
+
errors: [...errors ?? []],
|
|
44
|
+
fetching: false,
|
|
45
|
+
partial: true,
|
|
46
|
+
source: DataSource.Network,
|
|
47
|
+
variables: ctx.variables ?? null
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
error(data) {
|
|
51
|
+
clearSubscription?.();
|
|
52
|
+
resolve(ctx, {
|
|
53
|
+
partial: true,
|
|
54
|
+
source: DataSource.Network,
|
|
55
|
+
data: null,
|
|
56
|
+
errors: [data],
|
|
57
|
+
fetching: false,
|
|
58
|
+
variables: ctx.variables ?? null
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
complete() {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
},
|
|
66
|
+
cleanup() {
|
|
67
|
+
clearSubscription?.();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
subscriptionPlugin
|
|
74
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { QueryResult } from '../../lib';
|
|
2
|
+
import type { ClientPlugin } from '../documentStore';
|
|
3
|
+
export type ThrowOnErrorParams = {
|
|
4
|
+
operations: ('all' | 'query' | 'mutation' | 'subscription')[];
|
|
5
|
+
error?: (errors: NonNullable<QueryResult<any, any>['errors']>) => unknown;
|
|
6
|
+
};
|
|
7
|
+
export declare const throwOnErrorPlugin: ({ operations, error }: ThrowOnErrorParams) => ClientPlugin;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ArtifactKind } from "../../lib";
|
|
2
|
+
const throwOnErrorPlugin = ({ operations, error }) => () => {
|
|
3
|
+
const all = operations.includes("all");
|
|
4
|
+
const throwOnKind = (kind) => all || {
|
|
5
|
+
[ArtifactKind.Query]: operations.includes("query"),
|
|
6
|
+
[ArtifactKind.Mutation]: operations.includes("mutation"),
|
|
7
|
+
[ArtifactKind.Fragment]: false,
|
|
8
|
+
[ArtifactKind.Subscription]: operations.includes("subscription")
|
|
9
|
+
}[kind];
|
|
10
|
+
return {
|
|
11
|
+
async end(ctx, { value, resolve }) {
|
|
12
|
+
if (value.errors && value.errors.length > 0 && throwOnKind(ctx.artifact.kind)) {
|
|
13
|
+
const result = await (error ?? defaultErrorFn)(value.errors);
|
|
14
|
+
throw result;
|
|
15
|
+
}
|
|
16
|
+
resolve(ctx);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const defaultErrorFn = async (errors) => new Error(errors.map((error) => error.message).join(". ") + ".");
|
|
21
|
+
export {
|
|
22
|
+
throwOnErrorPlugin
|
|
23
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const documentPlugin = (kind, source) => {
|
|
2
|
+
return () => {
|
|
3
|
+
const sourceHandlers = source();
|
|
4
|
+
const enterWrapper = (handler) => {
|
|
5
|
+
return !handler ? void 0 : (ctx, handlers) => {
|
|
6
|
+
if (ctx.artifact.kind !== kind) {
|
|
7
|
+
return handlers.next(ctx);
|
|
8
|
+
}
|
|
9
|
+
return handler(ctx, handlers);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const exitWrapper = (handler) => {
|
|
13
|
+
return !handler ? void 0 : (ctx, handlers) => {
|
|
14
|
+
if (ctx.artifact.kind !== kind) {
|
|
15
|
+
return handlers.resolve(ctx);
|
|
16
|
+
}
|
|
17
|
+
return handler(ctx, handlers);
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
start: enterWrapper(sourceHandlers.start),
|
|
22
|
+
network: enterWrapper(sourceHandlers.network),
|
|
23
|
+
afterNetwork: exitWrapper(sourceHandlers.afterNetwork),
|
|
24
|
+
end: exitWrapper(sourceHandlers.end),
|
|
25
|
+
catch: sourceHandlers.catch ? (ctx, handlers) => sourceHandlers.catch(ctx, handlers) : void 0,
|
|
26
|
+
cleanup: (...args) => sourceHandlers.cleanup?.(...args)
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
documentPlugin
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './documentPlugins';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./documentPlugins";
|