houdini 0.17.13 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cmd-cjs/index.js +438 -201
- package/build/cmd-esm/index.js +438 -201
- package/build/codegen/utils/flattenSelections.d.ts +3 -1
- package/build/codegen-cjs/index.js +405 -180
- package/build/codegen-esm/index.js +405 -180
- package/build/lib/config.d.ts +8 -3
- package/build/lib-cjs/index.js +141 -81
- package/build/lib-esm/index.js +141 -81
- package/build/runtime/cache/subscription.d.ts +3 -3
- package/build/runtime/lib/config.d.ts +2 -1
- package/build/runtime/lib/scalars.d.ts +2 -2
- package/build/runtime/lib/selection.d.ts +2 -0
- package/build/runtime/lib/types.d.ts +26 -16
- package/build/runtime-cjs/cache/cache.js +38 -23
- package/build/runtime-cjs/cache/lists.js +40 -26
- package/build/runtime-cjs/cache/subscription.d.ts +3 -3
- package/build/runtime-cjs/cache/subscription.js +23 -21
- package/build/runtime-cjs/lib/config.d.ts +2 -1
- package/build/runtime-cjs/lib/scalars.d.ts +2 -2
- package/build/runtime-cjs/lib/scalars.js +9 -6
- package/build/runtime-cjs/lib/selection.d.ts +2 -0
- package/build/runtime-cjs/lib/selection.js +39 -0
- package/build/runtime-cjs/lib/types.d.ts +26 -16
- package/build/runtime-esm/cache/cache.js +38 -23
- package/build/runtime-esm/cache/lists.js +40 -26
- package/build/runtime-esm/cache/subscription.d.ts +3 -3
- package/build/runtime-esm/cache/subscription.js +23 -21
- package/build/runtime-esm/lib/config.d.ts +2 -1
- package/build/runtime-esm/lib/scalars.d.ts +2 -2
- package/build/runtime-esm/lib/scalars.js +9 -6
- package/build/runtime-esm/lib/selection.d.ts +2 -0
- package/build/runtime-esm/lib/selection.js +15 -0
- package/build/runtime-esm/lib/types.d.ts +26 -16
- package/build/test/index.d.ts +1 -2
- package/build/test-cjs/index.js +485 -195
- package/build/test-esm/index.js +485 -195
- package/build/vite-cjs/index.js +438 -193
- package/build/vite-esm/index.js +438 -193
- package/package.json +2 -2
- package/build/runtime-cjs/cache/tests/availability.test.js +0 -357
- package/build/runtime-cjs/cache/tests/gc.test.js +0 -271
- package/build/runtime-cjs/cache/tests/keys.test.js +0 -34
- package/build/runtime-cjs/cache/tests/list.test.js +0 -3390
- package/build/runtime-cjs/cache/tests/readwrite.test.js +0 -1076
- package/build/runtime-cjs/cache/tests/scalars.test.js +0 -181
- package/build/runtime-cjs/cache/tests/storage.test.js +0 -280
- package/build/runtime-cjs/cache/tests/subscriptions.test.js +0 -1469
- package/build/runtime-cjs/lib/scalars.test.js +0 -736
- package/build/runtime-esm/cache/tests/availability.test.js +0 -356
- package/build/runtime-esm/cache/tests/gc.test.js +0 -270
- package/build/runtime-esm/cache/tests/keys.test.js +0 -33
- package/build/runtime-esm/cache/tests/list.test.js +0 -3389
- package/build/runtime-esm/cache/tests/readwrite.test.js +0 -1075
- package/build/runtime-esm/cache/tests/scalars.test.js +0 -180
- package/build/runtime-esm/cache/tests/storage.test.js +0 -279
- package/build/runtime-esm/cache/tests/subscriptions.test.js +0 -1468
- package/build/runtime-esm/lib/scalars.test.js +0 -735
|
@@ -24,6 +24,7 @@ __export(cache_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(cache_exports);
|
|
25
25
|
var import_config = require("../lib/config");
|
|
26
26
|
var import_deepEquals = require("../lib/deepEquals");
|
|
27
|
+
var import_selection = require("../lib/selection");
|
|
27
28
|
var import_gc = require("./gc");
|
|
28
29
|
var import_lists = require("./lists");
|
|
29
30
|
var import_storage = require("./storage");
|
|
@@ -158,8 +159,9 @@ class CacheInternal {
|
|
|
158
159
|
if (this._disabled) {
|
|
159
160
|
return [];
|
|
160
161
|
}
|
|
162
|
+
let targetSelection = (0, import_selection.getFieldsForType)(selection, data["__typename"]);
|
|
161
163
|
for (const [field, value] of Object.entries(data)) {
|
|
162
|
-
if (!selection || !
|
|
164
|
+
if (!selection || !targetSelection[field]) {
|
|
163
165
|
throw new Error(
|
|
164
166
|
"Could not find field listing in selection for " + field + " @ " + JSON.stringify(selection)
|
|
165
167
|
);
|
|
@@ -167,11 +169,11 @@ class CacheInternal {
|
|
|
167
169
|
let {
|
|
168
170
|
type: linkedType,
|
|
169
171
|
keyRaw,
|
|
170
|
-
|
|
172
|
+
selection: fieldSelection,
|
|
171
173
|
operations,
|
|
172
174
|
abstract: isAbstract,
|
|
173
175
|
update
|
|
174
|
-
} =
|
|
176
|
+
} = targetSelection[field];
|
|
175
177
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
176
178
|
const currentSubscribers = this.subscriptions.get(parent, key);
|
|
177
179
|
const { value: previousValue, displayLayers } = this.storage.get(parent, key);
|
|
@@ -179,7 +181,7 @@ class CacheInternal {
|
|
|
179
181
|
if (displayLayer) {
|
|
180
182
|
this.lifetimes.resetLifetime(parent, key);
|
|
181
183
|
}
|
|
182
|
-
if (!
|
|
184
|
+
if (!fieldSelection) {
|
|
183
185
|
let newValue = value;
|
|
184
186
|
if (Array.isArray(value) && applyUpdates && update) {
|
|
185
187
|
if (update === "append") {
|
|
@@ -199,7 +201,7 @@ class CacheInternal {
|
|
|
199
201
|
}
|
|
200
202
|
const previousLinks = (0, import_stuff.flattenList)([previousValue]);
|
|
201
203
|
for (const link of previousLinks) {
|
|
202
|
-
this.subscriptions.remove(link,
|
|
204
|
+
this.subscriptions.remove(link, fieldSelection, currentSubscribers, variables);
|
|
203
205
|
}
|
|
204
206
|
layer.writeLink(parent, key, null);
|
|
205
207
|
toNotify.push(...currentSubscribers);
|
|
@@ -225,14 +227,14 @@ class CacheInternal {
|
|
|
225
227
|
if (previousValue && typeof previousValue === "string") {
|
|
226
228
|
this.subscriptions.remove(
|
|
227
229
|
previousValue,
|
|
228
|
-
|
|
230
|
+
fieldSelection,
|
|
229
231
|
currentSubscribers,
|
|
230
232
|
variables
|
|
231
233
|
);
|
|
232
234
|
}
|
|
233
235
|
this.subscriptions.addMany({
|
|
234
236
|
parent: linkedID,
|
|
235
|
-
selection:
|
|
237
|
+
selection: fieldSelection,
|
|
236
238
|
subscribers: currentSubscribers,
|
|
237
239
|
variables,
|
|
238
240
|
parentType: linkedType
|
|
@@ -242,14 +244,14 @@ class CacheInternal {
|
|
|
242
244
|
if (linkedID) {
|
|
243
245
|
this.writeSelection({
|
|
244
246
|
root,
|
|
245
|
-
selection:
|
|
247
|
+
selection: fieldSelection,
|
|
246
248
|
parent: linkedID,
|
|
247
249
|
data: value,
|
|
248
250
|
variables,
|
|
249
251
|
toNotify,
|
|
250
252
|
applyUpdates,
|
|
251
253
|
layer,
|
|
252
|
-
forceNotify
|
|
254
|
+
forceNotify
|
|
253
255
|
});
|
|
254
256
|
}
|
|
255
257
|
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
|
|
@@ -278,7 +280,7 @@ class CacheInternal {
|
|
|
278
280
|
key,
|
|
279
281
|
linkedType,
|
|
280
282
|
variables,
|
|
281
|
-
fields,
|
|
283
|
+
fields: fieldSelection,
|
|
282
284
|
layer,
|
|
283
285
|
forceNotify
|
|
284
286
|
});
|
|
@@ -328,7 +330,7 @@ class CacheInternal {
|
|
|
328
330
|
if (linkedIDs.includes(lostID) || !lostID) {
|
|
329
331
|
continue;
|
|
330
332
|
}
|
|
331
|
-
this.subscriptions.remove(lostID,
|
|
333
|
+
this.subscriptions.remove(lostID, fieldSelection, currentSubscribers, variables);
|
|
332
334
|
}
|
|
333
335
|
if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
|
|
334
336
|
layer.writeLink(parent, key, linkedIDs);
|
|
@@ -339,7 +341,7 @@ class CacheInternal {
|
|
|
339
341
|
}
|
|
340
342
|
this.subscriptions.addMany({
|
|
341
343
|
parent: id,
|
|
342
|
-
selection:
|
|
344
|
+
selection: fieldSelection,
|
|
343
345
|
subscribers: currentSubscribers,
|
|
344
346
|
variables,
|
|
345
347
|
parentType: linkedType
|
|
@@ -364,9 +366,14 @@ class CacheInternal {
|
|
|
364
366
|
}
|
|
365
367
|
const targets = Array.isArray(value) ? value : [value];
|
|
366
368
|
for (const target of targets) {
|
|
367
|
-
if (operation.action === "insert" && target instanceof Object &&
|
|
368
|
-
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).addToList(
|
|
369
|
-
|
|
369
|
+
if (operation.action === "insert" && target instanceof Object && fieldSelection && operation.list) {
|
|
370
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).addToList(
|
|
371
|
+
fieldSelection,
|
|
372
|
+
target,
|
|
373
|
+
variables,
|
|
374
|
+
operation.position || "last"
|
|
375
|
+
);
|
|
376
|
+
} else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
|
|
370
377
|
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
|
|
371
378
|
} else if (operation.action === "delete" && operation.type) {
|
|
372
379
|
if (typeof target !== "string") {
|
|
@@ -377,8 +384,13 @@ class CacheInternal {
|
|
|
377
384
|
continue;
|
|
378
385
|
}
|
|
379
386
|
this.cache.delete(targetID);
|
|
380
|
-
} else if (operation.action === "toggle" && target instanceof Object &&
|
|
381
|
-
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
|
|
387
|
+
} else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
|
|
388
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
|
|
389
|
+
fieldSelection,
|
|
390
|
+
target,
|
|
391
|
+
variables,
|
|
392
|
+
operation.position || "last"
|
|
393
|
+
);
|
|
382
394
|
}
|
|
383
395
|
}
|
|
384
396
|
}
|
|
@@ -398,9 +410,12 @@ class CacheInternal {
|
|
|
398
410
|
let hasData = false;
|
|
399
411
|
let partial = false;
|
|
400
412
|
let cascadeNull = false;
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
413
|
+
const typename = this.storage.get(parent, "__typename").value;
|
|
414
|
+
let targetSelection = (0, import_selection.getFieldsForType)(selection, typename);
|
|
415
|
+
for (const [
|
|
416
|
+
attributeName,
|
|
417
|
+
{ type, keyRaw, selection: fieldSelection, nullable, list }
|
|
418
|
+
] of Object.entries(targetSelection)) {
|
|
404
419
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
405
420
|
const { value } = this.storage.get(parent, key);
|
|
406
421
|
let nextStep = stepsFromConnection;
|
|
@@ -423,7 +438,7 @@ class CacheInternal {
|
|
|
423
438
|
if (typeof value !== "undefined") {
|
|
424
439
|
hasData = true;
|
|
425
440
|
}
|
|
426
|
-
} else if (!
|
|
441
|
+
} else if (!fieldSelection) {
|
|
427
442
|
const fnUnmarshal = this.config?.scalars?.[type]?.unmarshal;
|
|
428
443
|
if (fnUnmarshal) {
|
|
429
444
|
target[attributeName] = fnUnmarshal(value);
|
|
@@ -433,7 +448,7 @@ class CacheInternal {
|
|
|
433
448
|
hasData = true;
|
|
434
449
|
} else if (Array.isArray(value)) {
|
|
435
450
|
const listValue = this.hydrateNestedList({
|
|
436
|
-
fields,
|
|
451
|
+
fields: fieldSelection,
|
|
437
452
|
variables,
|
|
438
453
|
linkedList: value,
|
|
439
454
|
stepsFromConnection: nextStep
|
|
@@ -448,7 +463,7 @@ class CacheInternal {
|
|
|
448
463
|
} else {
|
|
449
464
|
const objectFields = this.getSelection({
|
|
450
465
|
parent: value,
|
|
451
|
-
selection:
|
|
466
|
+
selection: fieldSelection,
|
|
452
467
|
variables,
|
|
453
468
|
stepsFromConnection: nextStep
|
|
454
469
|
});
|
|
@@ -167,23 +167,32 @@ class List {
|
|
|
167
167
|
let insertData = data;
|
|
168
168
|
if (this.connection) {
|
|
169
169
|
insertSelection = {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
keyRaw: "edges",
|
|
176
|
-
type: "ConnectionEdge",
|
|
177
|
-
update: where === "first" ? "prepend" : "append",
|
|
170
|
+
fields: {
|
|
171
|
+
newEntry: {
|
|
172
|
+
keyRaw: this.key,
|
|
173
|
+
type: "Connection",
|
|
174
|
+
selection: {
|
|
178
175
|
fields: {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
176
|
+
edges: {
|
|
177
|
+
keyRaw: "edges",
|
|
178
|
+
type: "ConnectionEdge",
|
|
179
|
+
update: where === "first" ? "prepend" : "append",
|
|
180
|
+
selection: {
|
|
181
|
+
fields: {
|
|
182
|
+
node: {
|
|
183
|
+
type: listType,
|
|
184
|
+
keyRaw: "node",
|
|
185
|
+
selection: {
|
|
186
|
+
...selection,
|
|
187
|
+
fields: {
|
|
188
|
+
...selection.fields,
|
|
189
|
+
__typename: {
|
|
190
|
+
keyRaw: "__typename",
|
|
191
|
+
type: "String"
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
187
196
|
}
|
|
188
197
|
}
|
|
189
198
|
}
|
|
@@ -199,15 +208,20 @@ class List {
|
|
|
199
208
|
};
|
|
200
209
|
} else {
|
|
201
210
|
insertSelection = {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
fields: {
|
|
212
|
+
newEntries: {
|
|
213
|
+
keyRaw: this.key,
|
|
214
|
+
type: listType,
|
|
215
|
+
update: where === "first" ? "prepend" : "append",
|
|
216
|
+
selection: {
|
|
217
|
+
...selection,
|
|
218
|
+
fields: {
|
|
219
|
+
...selection.fields,
|
|
220
|
+
__typename: {
|
|
221
|
+
keyRaw: "__typename",
|
|
222
|
+
type: "String"
|
|
223
|
+
}
|
|
224
|
+
}
|
|
211
225
|
}
|
|
212
226
|
}
|
|
213
227
|
}
|
|
@@ -267,7 +281,7 @@ class List {
|
|
|
267
281
|
const subscribers = this.cache._internal_unstable.subscriptions.get(this.recordID, this.key);
|
|
268
282
|
this.cache._internal_unstable.subscriptions.remove(
|
|
269
283
|
targetID,
|
|
270
|
-
this.connection ? this.selection.edges.
|
|
284
|
+
this.connection ? this.selection.fields.edges.selection : this.selection,
|
|
271
285
|
subscribers,
|
|
272
286
|
variables
|
|
273
287
|
);
|
|
@@ -16,10 +16,10 @@ export declare class InMemorySubscriptions {
|
|
|
16
16
|
[key: string]: GraphQLValue;
|
|
17
17
|
};
|
|
18
18
|
}): void;
|
|
19
|
-
addFieldSubscription({ id, key,
|
|
19
|
+
addFieldSubscription({ id, key, field, spec, parentType, variables, }: {
|
|
20
20
|
id: string;
|
|
21
21
|
key: string;
|
|
22
|
-
|
|
22
|
+
field: Required<SubscriptionSelection>['fields'][string];
|
|
23
23
|
spec: SubscriptionSpec;
|
|
24
24
|
parentType: string;
|
|
25
25
|
variables: GraphQLObject;
|
|
@@ -32,7 +32,7 @@ export declare class InMemorySubscriptions {
|
|
|
32
32
|
parentType: string;
|
|
33
33
|
}): void;
|
|
34
34
|
get(id: string, field: string): SubscriptionSpec[];
|
|
35
|
-
remove(id: string,
|
|
35
|
+
remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
|
|
36
36
|
private removeSubscribers;
|
|
37
37
|
removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
|
|
38
38
|
}
|
|
@@ -21,6 +21,7 @@ __export(subscription_exports, {
|
|
|
21
21
|
InMemorySubscriptions: () => InMemorySubscriptions
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(subscription_exports);
|
|
24
|
+
var import_selection = require("../lib/selection");
|
|
24
25
|
var import_stuff = require("./stuff");
|
|
25
26
|
class InMemorySubscriptions {
|
|
26
27
|
cache;
|
|
@@ -37,18 +38,20 @@ class InMemorySubscriptions {
|
|
|
37
38
|
variables,
|
|
38
39
|
parentType
|
|
39
40
|
}) {
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
42
|
+
let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
|
|
43
|
+
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
44
|
+
const { keyRaw, selection: innerSelection, type } = fieldSelection;
|
|
42
45
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
43
46
|
this.addFieldSubscription({
|
|
44
47
|
id: parent,
|
|
45
48
|
key,
|
|
46
|
-
|
|
49
|
+
field: fieldSelection,
|
|
47
50
|
spec,
|
|
48
51
|
parentType: parentType || spec.rootType,
|
|
49
52
|
variables
|
|
50
53
|
});
|
|
51
|
-
if (
|
|
54
|
+
if (innerSelection) {
|
|
52
55
|
const { value: linkedRecord } = this.cache._internal_unstable.storage.get(
|
|
53
56
|
parent,
|
|
54
57
|
key
|
|
@@ -61,7 +64,7 @@ class InMemorySubscriptions {
|
|
|
61
64
|
this.add({
|
|
62
65
|
parent: child,
|
|
63
66
|
spec,
|
|
64
|
-
selection:
|
|
67
|
+
selection: innerSelection,
|
|
65
68
|
variables,
|
|
66
69
|
parentType: type
|
|
67
70
|
});
|
|
@@ -72,7 +75,7 @@ class InMemorySubscriptions {
|
|
|
72
75
|
addFieldSubscription({
|
|
73
76
|
id,
|
|
74
77
|
key,
|
|
75
|
-
|
|
78
|
+
field,
|
|
76
79
|
spec,
|
|
77
80
|
parentType,
|
|
78
81
|
variables
|
|
@@ -99,8 +102,8 @@ class InMemorySubscriptions {
|
|
|
99
102
|
const counts = this.referenceCounts[id][key];
|
|
100
103
|
counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
|
|
101
104
|
this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
|
|
102
|
-
const {
|
|
103
|
-
if (
|
|
105
|
+
const { selection, list, filters } = field;
|
|
106
|
+
if (selection && list) {
|
|
104
107
|
this.cache._internal_unstable.lists.add({
|
|
105
108
|
name: list.name,
|
|
106
109
|
connection: list.connection,
|
|
@@ -108,7 +111,7 @@ class InMemorySubscriptions {
|
|
|
108
111
|
recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
|
|
109
112
|
listType: list.type,
|
|
110
113
|
key,
|
|
111
|
-
selection
|
|
114
|
+
selection,
|
|
112
115
|
filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
|
|
113
116
|
return {
|
|
114
117
|
...acc,
|
|
@@ -125,20 +128,21 @@ class InMemorySubscriptions {
|
|
|
125
128
|
subscribers,
|
|
126
129
|
parentType
|
|
127
130
|
}) {
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
let targetSelection = (0, import_selection.getFieldsForType)(selection, parentType);
|
|
132
|
+
for (const fieldSelection of Object.values(targetSelection)) {
|
|
133
|
+
const { type: linkedType, keyRaw, selection: innerSelection } = fieldSelection;
|
|
130
134
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
131
135
|
for (const spec of subscribers) {
|
|
132
136
|
this.addFieldSubscription({
|
|
133
137
|
id: parent,
|
|
134
138
|
key,
|
|
135
|
-
|
|
139
|
+
field: fieldSelection,
|
|
136
140
|
spec,
|
|
137
141
|
parentType,
|
|
138
142
|
variables
|
|
139
143
|
});
|
|
140
144
|
}
|
|
141
|
-
if (
|
|
145
|
+
if (innerSelection) {
|
|
142
146
|
const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
|
|
143
147
|
const children = !Array.isArray(link) ? [link] : (0, import_stuff.flattenList)(link);
|
|
144
148
|
for (const linkedRecord of children) {
|
|
@@ -147,7 +151,7 @@ class InMemorySubscriptions {
|
|
|
147
151
|
}
|
|
148
152
|
this.addMany({
|
|
149
153
|
parent: linkedRecord,
|
|
150
|
-
selection:
|
|
154
|
+
selection: innerSelection,
|
|
151
155
|
variables,
|
|
152
156
|
subscribers,
|
|
153
157
|
parentType: linkedType
|
|
@@ -159,22 +163,20 @@ class InMemorySubscriptions {
|
|
|
159
163
|
get(id, field) {
|
|
160
164
|
return this.subscribers[id]?.[field] || [];
|
|
161
165
|
}
|
|
162
|
-
remove(id,
|
|
166
|
+
remove(id, selection, targets, variables, visited = []) {
|
|
163
167
|
visited.push(id);
|
|
164
168
|
const linkedIDs = [];
|
|
165
|
-
for (const
|
|
166
|
-
const key = (0, import_stuff.evaluateKey)(
|
|
169
|
+
for (const fieldSelection of Object.values(selection.fields || {})) {
|
|
170
|
+
const key = (0, import_stuff.evaluateKey)(fieldSelection.keyRaw, variables);
|
|
167
171
|
this.removeSubscribers(id, key, targets);
|
|
168
|
-
if (!selection
|
|
172
|
+
if (!fieldSelection.selection?.fields) {
|
|
169
173
|
continue;
|
|
170
174
|
}
|
|
171
|
-
if (selection.list) {
|
|
172
|
-
}
|
|
173
175
|
const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
|
|
174
176
|
const links = !Array.isArray(previousValue) ? [previousValue] : (0, import_stuff.flattenList)(previousValue);
|
|
175
177
|
for (const link of links) {
|
|
176
178
|
if (link !== null) {
|
|
177
|
-
linkedIDs.push([link, selection
|
|
179
|
+
linkedIDs.push([link, fieldSelection.selection || {}]);
|
|
178
180
|
}
|
|
179
181
|
}
|
|
180
182
|
}
|
|
@@ -87,8 +87,9 @@ export declare type ConfigFile = {
|
|
|
87
87
|
logLevel?: string;
|
|
88
88
|
/**
|
|
89
89
|
* A flag to specify the default fragment masking behavior.
|
|
90
|
+
* @default `enable`
|
|
90
91
|
*/
|
|
91
|
-
|
|
92
|
+
defaultFragmentMasking?: 'enable' | 'disable';
|
|
92
93
|
/**
|
|
93
94
|
* Configures the houdini plugin's schema polling behavior. By default, houdini will poll your APIs
|
|
94
95
|
* during development in order to keep it's definition of your schema up to date. The schemaPollingInterval
|
|
@@ -2,12 +2,12 @@ import { ConfigFile } from './config';
|
|
|
2
2
|
import { MutationArtifact, QueryArtifact, SubscriptionArtifact, SubscriptionSelection } from './types';
|
|
3
3
|
export declare function marshalSelection({ selection, data, }: {
|
|
4
4
|
selection: SubscriptionSelection;
|
|
5
|
-
data:
|
|
5
|
+
data: any;
|
|
6
6
|
}): Promise<{} | null | undefined>;
|
|
7
7
|
export declare function marshalInputs<T>({ artifact, input, rootType, }: {
|
|
8
8
|
artifact: QueryArtifact | MutationArtifact | SubscriptionArtifact;
|
|
9
9
|
input: unknown;
|
|
10
10
|
rootType?: string;
|
|
11
11
|
}): Promise<{} | null | undefined>;
|
|
12
|
-
export declare function unmarshalSelection(config: ConfigFile, selection: SubscriptionSelection, data:
|
|
12
|
+
export declare function unmarshalSelection(config: ConfigFile, selection: SubscriptionSelection, data: any): {} | null | undefined;
|
|
13
13
|
export declare function isScalar(config: ConfigFile, type: string): boolean;
|
|
@@ -25,6 +25,7 @@ __export(scalars_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(scalars_exports);
|
|
27
27
|
var import_config = require("./config");
|
|
28
|
+
var import_selection = require("./selection");
|
|
28
29
|
async function marshalSelection({
|
|
29
30
|
selection,
|
|
30
31
|
data
|
|
@@ -36,15 +37,16 @@ async function marshalSelection({
|
|
|
36
37
|
if (Array.isArray(data)) {
|
|
37
38
|
return await Promise.all(data.map((val) => marshalSelection({ selection, data: val })));
|
|
38
39
|
}
|
|
40
|
+
const targetSelection = (0, import_selection.getFieldsForType)(selection, data["__typename"]);
|
|
39
41
|
return Object.fromEntries(
|
|
40
42
|
await Promise.all(
|
|
41
43
|
Object.entries(data).map(async ([fieldName, value]) => {
|
|
42
|
-
const { type,
|
|
44
|
+
const { type, selection: selection2 } = targetSelection[fieldName];
|
|
43
45
|
if (!type) {
|
|
44
46
|
return [fieldName, value];
|
|
45
47
|
}
|
|
46
|
-
if (
|
|
47
|
-
return [fieldName, await marshalSelection({ selection:
|
|
48
|
+
if (selection2) {
|
|
49
|
+
return [fieldName, await marshalSelection({ selection: selection2, data: value })];
|
|
48
50
|
}
|
|
49
51
|
if (config.scalars?.[type]) {
|
|
50
52
|
const marshalFn = config.scalars[type].marshal;
|
|
@@ -110,16 +112,17 @@ function unmarshalSelection(config, selection, data) {
|
|
|
110
112
|
if (Array.isArray(data)) {
|
|
111
113
|
return data.map((val) => unmarshalSelection(config, selection, val));
|
|
112
114
|
}
|
|
115
|
+
const targetSelection = (0, import_selection.getFieldsForType)(selection, data["__typename"]);
|
|
113
116
|
return Object.fromEntries(
|
|
114
117
|
Object.entries(data).map(([fieldName, value]) => {
|
|
115
|
-
const { type,
|
|
118
|
+
const { type, selection: selection2 } = targetSelection[fieldName];
|
|
116
119
|
if (!type) {
|
|
117
120
|
return [fieldName, value];
|
|
118
121
|
}
|
|
119
|
-
if (
|
|
122
|
+
if (selection2) {
|
|
120
123
|
return [
|
|
121
124
|
fieldName,
|
|
122
|
-
unmarshalSelection(config,
|
|
125
|
+
unmarshalSelection(config, selection2, value)
|
|
123
126
|
];
|
|
124
127
|
}
|
|
125
128
|
if (value === null) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var selection_exports = {};
|
|
20
|
+
__export(selection_exports, {
|
|
21
|
+
getFieldsForType: () => getFieldsForType
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(selection_exports);
|
|
24
|
+
function getFieldsForType(selection, __typename) {
|
|
25
|
+
let targetSelection = selection.fields || {};
|
|
26
|
+
if (selection.abstractFields && __typename) {
|
|
27
|
+
const mappedType = selection.abstractFields.typeMap[__typename];
|
|
28
|
+
if (mappedType) {
|
|
29
|
+
targetSelection = selection.abstractFields.fields[mappedType];
|
|
30
|
+
} else if (selection.abstractFields.fields[__typename]) {
|
|
31
|
+
targetSelection = selection.abstractFields.fields[__typename];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return targetSelection;
|
|
35
|
+
}
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
getFieldsForType
|
|
39
|
+
});
|
|
@@ -107,25 +107,35 @@ export declare type GraphQLObject = {
|
|
|
107
107
|
};
|
|
108
108
|
export declare type GraphQLValue = number | string | boolean | null | GraphQLObject | GraphQLValue[] | undefined;
|
|
109
109
|
export declare type SubscriptionSelection = {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
nullable?: boolean;
|
|
113
|
-
keyRaw: string;
|
|
114
|
-
operations?: MutationOperation[];
|
|
115
|
-
list?: {
|
|
116
|
-
name: string;
|
|
117
|
-
connection: boolean;
|
|
110
|
+
fields?: {
|
|
111
|
+
[fieldName: string]: {
|
|
118
112
|
type: string;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
113
|
+
nullable?: boolean;
|
|
114
|
+
keyRaw: string;
|
|
115
|
+
operations?: MutationOperation[];
|
|
116
|
+
list?: {
|
|
117
|
+
name: string;
|
|
118
|
+
connection: boolean;
|
|
119
|
+
type: string;
|
|
120
|
+
};
|
|
121
|
+
update?: RefetchUpdateMode;
|
|
122
|
+
filters?: {
|
|
123
|
+
[key: string]: {
|
|
124
|
+
kind: 'Boolean' | 'String' | 'Float' | 'Int' | 'Variable';
|
|
125
|
+
value: string | number | boolean;
|
|
126
|
+
};
|
|
125
127
|
};
|
|
128
|
+
selection?: SubscriptionSelection;
|
|
129
|
+
abstract?: boolean;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
abstractFields?: {
|
|
133
|
+
fields: {
|
|
134
|
+
[typeName: string]: SubscriptionSelection['fields'];
|
|
135
|
+
};
|
|
136
|
+
typeMap: {
|
|
137
|
+
[typeName: string]: string;
|
|
126
138
|
};
|
|
127
|
-
fields?: SubscriptionSelection;
|
|
128
|
-
abstract?: boolean;
|
|
129
139
|
};
|
|
130
140
|
};
|
|
131
141
|
export declare type SubscriptionSpec = {
|