houdini 1.0.0-next.1 → 1.0.0-next.2
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 +398 -2024
- package/build/cmd-esm/index.js +398 -2024
- 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/imperativeCache.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 +2 -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 +330 -1977
- package/build/codegen-esm/index.js +330 -1977
- package/build/lib/config.d.ts +8 -3
- 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 +4 -4
- package/build/lib-cjs/index.js +145 -1846
- package/build/lib-esm/index.js +145 -1846
- 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 +2 -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/imports/config.d.ts +3 -0
- package/build/runtime/index.d.ts +2 -1
- package/build/runtime/lib/config.d.ts +5 -3
- package/build/runtime/lib/index.d.ts +1 -2
- package/build/runtime/lib/scalars.d.ts +5 -4
- 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 +2 -2
- package/build/runtime/public/list.d.ts +2 -2
- package/build/runtime/public/record.d.ts +1 -1
- package/build/runtime/public/tests/test.d.ts +1 -1
- 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 +2 -2
- package/build/runtime-cjs/cache/lists.js +2 -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/imports/config.d.ts +3 -0
- package/build/runtime-cjs/imports/config.js +26 -0
- package/build/runtime-cjs/index.d.ts +2 -1
- package/build/runtime-cjs/index.js +1 -0
- package/build/runtime-cjs/lib/config.d.ts +5 -3
- 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 +5 -4
- 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 +2 -2
- package/build/runtime-cjs/public/list.d.ts +2 -2
- package/build/runtime-cjs/public/list.js +2 -2
- package/build/runtime-cjs/public/record.d.ts +1 -1
- package/build/runtime-cjs/public/record.js +4 -4
- package/build/runtime-cjs/public/tests/test.d.ts +1 -1
- 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 +2 -2
- package/build/runtime-esm/cache/lists.js +2 -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/imports/config.d.ts +3 -0
- package/build/runtime-esm/imports/config.js +4 -0
- package/build/runtime-esm/index.d.ts +2 -1
- package/build/runtime-esm/index.js +1 -0
- package/build/runtime-esm/lib/config.d.ts +5 -3
- 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 +5 -4
- 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 +2 -2
- package/build/runtime-esm/public/list.d.ts +2 -2
- package/build/runtime-esm/public/list.js +1 -1
- package/build/runtime-esm/public/record.d.ts +1 -1
- package/build/runtime-esm/public/record.js +1 -1
- package/build/runtime-esm/public/tests/test.d.ts +1 -1
- package/build/test/index.d.ts +4 -3
- package/build/test-cjs/index.js +336 -1955
- package/build/test-esm/index.js +336 -1955
- 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 +396 -2010
- package/build/vite-esm/index.js +396 -2010
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SubscriptionSelection, ListWhen, SubscriptionSpec } from '../lib/types';
|
|
2
|
-
import { Cache } from './cache';
|
|
1
|
+
import type { SubscriptionSelection, ListWhen, SubscriptionSpec } from '../lib/types';
|
|
2
|
+
import type { Cache } from './cache';
|
|
3
3
|
export declare class ListManager {
|
|
4
4
|
rootID: string;
|
|
5
5
|
cache: Cache;
|
|
@@ -282,11 +282,11 @@ class List {
|
|
|
282
282
|
this.cache._internal_unstable.subscriptions.remove(
|
|
283
283
|
targetID,
|
|
284
284
|
this.connection ? this.selection.fields.edges.selection : this.selection,
|
|
285
|
-
subscribers,
|
|
285
|
+
subscribers.map((sub) => sub[0]),
|
|
286
286
|
variables
|
|
287
287
|
);
|
|
288
288
|
this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
|
|
289
|
-
for (const spec of subscribers) {
|
|
289
|
+
for (const [spec] of subscribers) {
|
|
290
290
|
spec.set(
|
|
291
291
|
this.cache._internal_unstable.getSelection({
|
|
292
292
|
parent: spec.parentID || this.manager.rootID,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GraphQLValue } from '../lib/types';
|
|
2
|
-
import { LinkedList } from './cache';
|
|
1
|
+
import type { GraphQLValue } from '../lib/types';
|
|
2
|
+
import type { LinkedList } from './cache';
|
|
3
3
|
export declare function flattenList<T>(source: LinkedList<T>): T[];
|
|
4
4
|
export declare function evaluateKey(key: string, variables?: {
|
|
5
5
|
[key: string]: GraphQLValue;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
|
|
2
|
+
import type { Cache } from './cache';
|
|
3
|
+
export type FieldSelection = [
|
|
4
|
+
SubscriptionSpec,
|
|
5
|
+
Required<SubscriptionSelection>['fields'] | undefined
|
|
6
|
+
];
|
|
4
7
|
export declare class InMemorySubscriptions {
|
|
5
8
|
private cache;
|
|
6
9
|
constructor(cache: Cache);
|
|
@@ -16,22 +19,27 @@ export declare class InMemorySubscriptions {
|
|
|
16
19
|
[key: string]: GraphQLValue;
|
|
17
20
|
};
|
|
18
21
|
}): void;
|
|
19
|
-
addFieldSubscription({ id, key,
|
|
22
|
+
addFieldSubscription({ id, key, selection, }: {
|
|
20
23
|
id: string;
|
|
21
24
|
key: string;
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
selection: FieldSelection;
|
|
26
|
+
}): void;
|
|
27
|
+
registerList({ list, id, key, parentType, selection, filters, variables, }: {
|
|
28
|
+
list: Required<Required<SubscriptionSelection>['fields'][string]>['list'];
|
|
29
|
+
selection: SubscriptionSelection;
|
|
30
|
+
id: string;
|
|
24
31
|
parentType: string;
|
|
25
|
-
|
|
32
|
+
key: string;
|
|
33
|
+
filters: Required<SubscriptionSelection>['fields'][string]['filters'];
|
|
34
|
+
variables: Record<string, any>;
|
|
26
35
|
}): void;
|
|
27
|
-
addMany({ parent,
|
|
36
|
+
addMany({ parent, variables, subscribers, parentType, }: {
|
|
28
37
|
parent: string;
|
|
29
|
-
selection: SubscriptionSelection;
|
|
30
38
|
variables: {};
|
|
31
|
-
subscribers:
|
|
39
|
+
subscribers: FieldSelection[];
|
|
32
40
|
parentType: string;
|
|
33
41
|
}): void;
|
|
34
|
-
get(id: string, field: string):
|
|
42
|
+
get(id: string, field: string): FieldSelection[];
|
|
35
43
|
remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
|
|
36
44
|
private removeSubscribers;
|
|
37
45
|
removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
|
|
@@ -41,16 +41,29 @@ class InMemorySubscriptions {
|
|
|
41
41
|
const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
42
42
|
let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
|
|
43
43
|
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
44
|
-
const { keyRaw, selection: innerSelection, type } = fieldSelection;
|
|
44
|
+
const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
|
|
45
45
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
46
|
+
let targetSelection2;
|
|
47
|
+
if (innerSelection) {
|
|
48
|
+
const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
49
|
+
targetSelection2 = (0, import_selection.getFieldsForType)(innerSelection, __typename2);
|
|
50
|
+
}
|
|
46
51
|
this.addFieldSubscription({
|
|
47
52
|
id: parent,
|
|
48
53
|
key,
|
|
49
|
-
|
|
50
|
-
spec,
|
|
51
|
-
parentType: parentType || spec.rootType,
|
|
52
|
-
variables
|
|
54
|
+
selection: [spec, targetSelection2]
|
|
53
55
|
});
|
|
56
|
+
if (list) {
|
|
57
|
+
this.registerList({
|
|
58
|
+
list,
|
|
59
|
+
filters,
|
|
60
|
+
id: parent,
|
|
61
|
+
key,
|
|
62
|
+
variables,
|
|
63
|
+
selection: innerSelection,
|
|
64
|
+
parentType: parentType || spec.rootType
|
|
65
|
+
});
|
|
66
|
+
}
|
|
54
67
|
if (innerSelection) {
|
|
55
68
|
const { value: linkedRecord } = this.cache._internal_unstable.storage.get(
|
|
56
69
|
parent,
|
|
@@ -75,11 +88,9 @@ class InMemorySubscriptions {
|
|
|
75
88
|
addFieldSubscription({
|
|
76
89
|
id,
|
|
77
90
|
key,
|
|
78
|
-
|
|
79
|
-
spec,
|
|
80
|
-
parentType,
|
|
81
|
-
variables
|
|
91
|
+
selection
|
|
82
92
|
}) {
|
|
93
|
+
const spec = selection[0];
|
|
83
94
|
if (!this.subscribers[id]) {
|
|
84
95
|
this.subscribers[id] = {};
|
|
85
96
|
}
|
|
@@ -90,8 +101,8 @@ class InMemorySubscriptions {
|
|
|
90
101
|
this.keyVersions[key] = /* @__PURE__ */ new Set();
|
|
91
102
|
}
|
|
92
103
|
this.keyVersions[key].add(key);
|
|
93
|
-
if (!this.subscribers[id][key].map(({ set }) => set).includes(spec.set)) {
|
|
94
|
-
this.subscribers[id][key].push(spec);
|
|
104
|
+
if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
|
|
105
|
+
this.subscribers[id][key].push([spec, selection[1]]);
|
|
95
106
|
}
|
|
96
107
|
if (!this.referenceCounts[id]) {
|
|
97
108
|
this.referenceCounts[id] = {};
|
|
@@ -102,61 +113,87 @@ class InMemorySubscriptions {
|
|
|
102
113
|
const counts = this.referenceCounts[id][key];
|
|
103
114
|
counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
|
|
104
115
|
this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
|
|
105
|
-
const { selection
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
const { selection: innerSelection } = selection[1]?.[key] ?? {};
|
|
117
|
+
}
|
|
118
|
+
registerList({
|
|
119
|
+
list,
|
|
120
|
+
id,
|
|
121
|
+
key,
|
|
122
|
+
parentType,
|
|
123
|
+
selection,
|
|
124
|
+
filters,
|
|
125
|
+
variables
|
|
126
|
+
}) {
|
|
127
|
+
this.cache._internal_unstable.lists.add({
|
|
128
|
+
name: list.name,
|
|
129
|
+
connection: list.connection,
|
|
130
|
+
recordID: id,
|
|
131
|
+
recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
|
|
132
|
+
listType: list.type,
|
|
133
|
+
key,
|
|
134
|
+
selection,
|
|
135
|
+
filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
|
|
136
|
+
return {
|
|
137
|
+
...acc,
|
|
138
|
+
[key2]: kind !== "Variable" ? value : variables[value]
|
|
139
|
+
};
|
|
140
|
+
}, {})
|
|
141
|
+
});
|
|
123
142
|
}
|
|
124
143
|
addMany({
|
|
125
144
|
parent,
|
|
126
|
-
selection,
|
|
127
145
|
variables,
|
|
128
146
|
subscribers,
|
|
129
147
|
parentType
|
|
130
148
|
}) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
149
|
+
for (const [spec, targetSelection] of subscribers) {
|
|
150
|
+
for (const selection of Object.values(targetSelection ?? {})) {
|
|
151
|
+
const {
|
|
152
|
+
type: linkedType,
|
|
153
|
+
keyRaw,
|
|
154
|
+
selection: innerSelection,
|
|
155
|
+
list,
|
|
156
|
+
filters
|
|
157
|
+
} = selection;
|
|
158
|
+
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
159
|
+
const fieldSelection = innerSelection ? (0, import_selection.getFieldsForType)(innerSelection, parentType) : void 0;
|
|
136
160
|
this.addFieldSubscription({
|
|
137
161
|
id: parent,
|
|
138
162
|
key,
|
|
139
|
-
|
|
140
|
-
spec,
|
|
141
|
-
parentType,
|
|
142
|
-
variables
|
|
163
|
+
selection: [spec, fieldSelection]
|
|
143
164
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
this.addMany({
|
|
153
|
-
parent: linkedRecord,
|
|
154
|
-
selection: innerSelection,
|
|
165
|
+
if (list) {
|
|
166
|
+
this.registerList({
|
|
167
|
+
list,
|
|
168
|
+
filters,
|
|
169
|
+
id: parent,
|
|
170
|
+
key,
|
|
155
171
|
variables,
|
|
156
|
-
|
|
157
|
-
parentType:
|
|
172
|
+
selection: innerSelection,
|
|
173
|
+
parentType: parentType || spec.rootType
|
|
158
174
|
});
|
|
159
175
|
}
|
|
176
|
+
const childSelection = selection.selection;
|
|
177
|
+
if (childSelection) {
|
|
178
|
+
const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
|
|
179
|
+
const children = !Array.isArray(link) ? [link] : (0, import_stuff.flattenList)(link);
|
|
180
|
+
for (const linkedRecord of children) {
|
|
181
|
+
if (!linkedRecord) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const __typename = this.cache._internal_unstable.storage.get(
|
|
185
|
+
linkedRecord,
|
|
186
|
+
"__typename"
|
|
187
|
+
).value;
|
|
188
|
+
let targetSelection2 = (0, import_selection.getFieldsForType)(childSelection, __typename);
|
|
189
|
+
this.addMany({
|
|
190
|
+
parent: linkedRecord,
|
|
191
|
+
variables,
|
|
192
|
+
subscribers: subscribers.map(([sub]) => [sub, targetSelection2]),
|
|
193
|
+
parentType: linkedType
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
160
197
|
}
|
|
161
198
|
}
|
|
162
199
|
}
|
|
@@ -166,10 +203,12 @@ class InMemorySubscriptions {
|
|
|
166
203
|
remove(id, selection, targets, variables, visited = []) {
|
|
167
204
|
visited.push(id);
|
|
168
205
|
const linkedIDs = [];
|
|
169
|
-
|
|
206
|
+
const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
|
|
207
|
+
let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
|
|
208
|
+
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
170
209
|
const key = (0, import_stuff.evaluateKey)(fieldSelection.keyRaw, variables);
|
|
171
210
|
this.removeSubscribers(id, key, targets);
|
|
172
|
-
if (!fieldSelection.selection
|
|
211
|
+
if (!fieldSelection.selection) {
|
|
173
212
|
continue;
|
|
174
213
|
}
|
|
175
214
|
const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
|
|
@@ -200,14 +239,14 @@ class InMemorySubscriptions {
|
|
|
200
239
|
}
|
|
201
240
|
if (this.subscribers[id]) {
|
|
202
241
|
this.subscribers[id][fieldName] = this.get(id, fieldName).filter(
|
|
203
|
-
({ set }) => !targets.includes(set)
|
|
242
|
+
([{ set }]) => !targets.includes(set)
|
|
204
243
|
);
|
|
205
244
|
}
|
|
206
245
|
}
|
|
207
246
|
removeAllSubscribers(id, targets, visited = []) {
|
|
208
247
|
visited.push(id);
|
|
209
248
|
for (const field of Object.keys(this.subscribers[id] || [])) {
|
|
210
|
-
const subscribers = targets || this.subscribers[id][field];
|
|
249
|
+
const subscribers = targets || this.subscribers[id][field].map(([spec]) => spec);
|
|
211
250
|
this.removeSubscribers(id, field, subscribers);
|
|
212
251
|
const { value, kind } = this.cache._internal_unstable.storage.get(id, field);
|
|
213
252
|
if (kind === "scalar") {
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { HoudiniClient } from '.';
|
|
2
|
+
import type { Layer } from '../cache/storage';
|
|
3
|
+
import type { ConfigFile } from '../lib/config';
|
|
4
|
+
import { Writable } from '../lib/store';
|
|
5
|
+
import type { CachePolicy, DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec } from '../lib/types';
|
|
6
|
+
export declare class DocumentStore<_Data extends GraphQLObject, _Input extends Record<string, any>> extends Writable<QueryResult<_Data, _Input>> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
|
|
9
|
+
artifact: DocumentArtifact;
|
|
10
|
+
plugins?: ClientPlugin[];
|
|
11
|
+
pipeline?: ClientPlugin[];
|
|
12
|
+
client: HoudiniClient;
|
|
13
|
+
cache?: boolean;
|
|
14
|
+
initialValue?: _Data | null;
|
|
15
|
+
fetching?: boolean;
|
|
16
|
+
});
|
|
17
|
+
send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, }?: {
|
|
18
|
+
fetch?: Fetch;
|
|
19
|
+
variables?: Record<string, any> | null;
|
|
20
|
+
metadata?: App.Metadata | null;
|
|
21
|
+
session?: App.Session | null;
|
|
22
|
+
policy?: CachePolicy;
|
|
23
|
+
stuff?: Partial<App.Stuff>;
|
|
24
|
+
cacheParams?: ClientPluginContext['cacheParams'];
|
|
25
|
+
setup?: boolean;
|
|
26
|
+
}): Promise<QueryResult<_Data, _Input>>;
|
|
27
|
+
}
|
|
28
|
+
declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
|
|
29
|
+
export type ClientPlugin = () => {
|
|
30
|
+
start?: ClientPluginEnterPhase;
|
|
31
|
+
beforeNetwork?: ClientPluginEnterPhase;
|
|
32
|
+
network?: ClientPluginEnterPhase;
|
|
33
|
+
afterNetwork?: ClientPluginExitPhase;
|
|
34
|
+
end?: ClientPluginExitPhase;
|
|
35
|
+
cleanup?(ctx: ClientPluginContext): void | Promise<void>;
|
|
36
|
+
catch?(ctx: ClientPluginContext, args: ClientPluginErrorHandlers): void | Promise<void>;
|
|
37
|
+
};
|
|
38
|
+
export type Fetch = typeof globalThis.fetch;
|
|
39
|
+
export type ClientPluginContext = {
|
|
40
|
+
config: ConfigFile;
|
|
41
|
+
text: string;
|
|
42
|
+
hash: string;
|
|
43
|
+
artifact: DocumentArtifact;
|
|
44
|
+
policy?: CachePolicy;
|
|
45
|
+
fetch?: Fetch;
|
|
46
|
+
variables?: Record<string, any>;
|
|
47
|
+
metadata?: App.Metadata | null;
|
|
48
|
+
session?: App.Session | null;
|
|
49
|
+
fetchParams?: RequestInit;
|
|
50
|
+
cacheParams?: {
|
|
51
|
+
layer?: Layer;
|
|
52
|
+
notifySubscribers?: SubscriptionSpec[];
|
|
53
|
+
forceNotify?: boolean;
|
|
54
|
+
disableWrite?: boolean;
|
|
55
|
+
disableRead?: boolean;
|
|
56
|
+
applyUpdates?: boolean;
|
|
57
|
+
};
|
|
58
|
+
stuff: App.Stuff;
|
|
59
|
+
};
|
|
60
|
+
type ClientPluginPhase<Handlers> = (ctx: ClientPluginContext, handlers: Handlers) => void | Promise<void>;
|
|
61
|
+
export type ClientPluginEnterPhase = ClientPluginPhase<ClientPluginEnterHandlers>;
|
|
62
|
+
export type ClientPluginExitPhase = ClientPluginPhase<ClientPluginExitHandlers>;
|
|
63
|
+
export type ClientPluginEnterHandlers = {
|
|
64
|
+
initialValue: QueryResult;
|
|
65
|
+
/** A reference to the houdini client to access any configuration values */
|
|
66
|
+
client: HoudiniClient;
|
|
67
|
+
/** Move onto the next step using the provided context. */
|
|
68
|
+
next(ctx: ClientPluginContext): void;
|
|
69
|
+
/** Terminate the current chain */
|
|
70
|
+
resolve(ctx: ClientPluginContext, data: QueryResult): void;
|
|
71
|
+
/** Update the stores state without resolving the promise */
|
|
72
|
+
updateState(updater: (old: QueryResult) => QueryResult): void;
|
|
73
|
+
/** Return true if the variables have changed */
|
|
74
|
+
variablesChanged: (ctx: ClientPluginContext) => boolean;
|
|
75
|
+
/** Returns the marshaled variables for the operation */
|
|
76
|
+
marshalVariables: typeof marshalVariables;
|
|
77
|
+
};
|
|
78
|
+
/** Exit handlers are the same as enter handles but don't need to resolve with a specific value */
|
|
79
|
+
export type ClientPluginExitHandlers = Omit<ClientPluginEnterHandlers, 'resolve'> & {
|
|
80
|
+
resolve: (ctx: ClientPluginContext, data?: QueryResult) => void;
|
|
81
|
+
value: QueryResult;
|
|
82
|
+
};
|
|
83
|
+
/** Exit handlers are the same as enter handles but don't need to resolve with a specific value */
|
|
84
|
+
export type ClientPluginErrorHandlers = ClientPluginEnterHandlers & {
|
|
85
|
+
error: unknown;
|
|
86
|
+
};
|
|
87
|
+
export {};
|