houdini 0.17.14 → 0.18.1
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 +442 -203
- package/build/cmd-esm/index.js +442 -203
- package/build/codegen/utils/flattenSelections.d.ts +3 -1
- package/build/codegen-cjs/index.js +409 -182
- package/build/codegen-esm/index.js +409 -182
- package/build/lib/config.d.ts +8 -3
- package/build/lib-cjs/index.js +145 -83
- package/build/lib-esm/index.js +145 -83
- 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 +42 -25
- 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 +42 -25
- 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 +489 -197
- package/build/test-esm/index.js +489 -197
- package/build/vite-cjs/index.js +442 -195
- package/build/vite-esm/index.js +442 -195
- package/package.json +3 -3
- 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");
|
|
@@ -135,10 +136,12 @@ class CacheInternal {
|
|
|
135
136
|
this.lists = lists;
|
|
136
137
|
this.cache = cache;
|
|
137
138
|
this.lifetimes = lifetimes;
|
|
139
|
+
this._disabled = typeof globalThis.window === "undefined";
|
|
138
140
|
try {
|
|
139
|
-
|
|
141
|
+
if (process.env.HOUDINI_TEST === "true") {
|
|
142
|
+
this._disabled = false;
|
|
143
|
+
}
|
|
140
144
|
} catch {
|
|
141
|
-
this._disabled = typeof globalThis.window === "undefined";
|
|
142
145
|
}
|
|
143
146
|
}
|
|
144
147
|
setConfig(config) {
|
|
@@ -158,8 +161,9 @@ class CacheInternal {
|
|
|
158
161
|
if (this._disabled) {
|
|
159
162
|
return [];
|
|
160
163
|
}
|
|
164
|
+
let targetSelection = (0, import_selection.getFieldsForType)(selection, data["__typename"]);
|
|
161
165
|
for (const [field, value] of Object.entries(data)) {
|
|
162
|
-
if (!selection || !
|
|
166
|
+
if (!selection || !targetSelection[field]) {
|
|
163
167
|
throw new Error(
|
|
164
168
|
"Could not find field listing in selection for " + field + " @ " + JSON.stringify(selection)
|
|
165
169
|
);
|
|
@@ -167,11 +171,11 @@ class CacheInternal {
|
|
|
167
171
|
let {
|
|
168
172
|
type: linkedType,
|
|
169
173
|
keyRaw,
|
|
170
|
-
|
|
174
|
+
selection: fieldSelection,
|
|
171
175
|
operations,
|
|
172
176
|
abstract: isAbstract,
|
|
173
177
|
update
|
|
174
|
-
} =
|
|
178
|
+
} = targetSelection[field];
|
|
175
179
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
176
180
|
const currentSubscribers = this.subscriptions.get(parent, key);
|
|
177
181
|
const { value: previousValue, displayLayers } = this.storage.get(parent, key);
|
|
@@ -179,7 +183,7 @@ class CacheInternal {
|
|
|
179
183
|
if (displayLayer) {
|
|
180
184
|
this.lifetimes.resetLifetime(parent, key);
|
|
181
185
|
}
|
|
182
|
-
if (!
|
|
186
|
+
if (!fieldSelection) {
|
|
183
187
|
let newValue = value;
|
|
184
188
|
if (Array.isArray(value) && applyUpdates && update) {
|
|
185
189
|
if (update === "append") {
|
|
@@ -199,7 +203,7 @@ class CacheInternal {
|
|
|
199
203
|
}
|
|
200
204
|
const previousLinks = (0, import_stuff.flattenList)([previousValue]);
|
|
201
205
|
for (const link of previousLinks) {
|
|
202
|
-
this.subscriptions.remove(link,
|
|
206
|
+
this.subscriptions.remove(link, fieldSelection, currentSubscribers, variables);
|
|
203
207
|
}
|
|
204
208
|
layer.writeLink(parent, key, null);
|
|
205
209
|
toNotify.push(...currentSubscribers);
|
|
@@ -225,14 +229,14 @@ class CacheInternal {
|
|
|
225
229
|
if (previousValue && typeof previousValue === "string") {
|
|
226
230
|
this.subscriptions.remove(
|
|
227
231
|
previousValue,
|
|
228
|
-
|
|
232
|
+
fieldSelection,
|
|
229
233
|
currentSubscribers,
|
|
230
234
|
variables
|
|
231
235
|
);
|
|
232
236
|
}
|
|
233
237
|
this.subscriptions.addMany({
|
|
234
238
|
parent: linkedID,
|
|
235
|
-
selection:
|
|
239
|
+
selection: fieldSelection,
|
|
236
240
|
subscribers: currentSubscribers,
|
|
237
241
|
variables,
|
|
238
242
|
parentType: linkedType
|
|
@@ -242,14 +246,14 @@ class CacheInternal {
|
|
|
242
246
|
if (linkedID) {
|
|
243
247
|
this.writeSelection({
|
|
244
248
|
root,
|
|
245
|
-
selection:
|
|
249
|
+
selection: fieldSelection,
|
|
246
250
|
parent: linkedID,
|
|
247
251
|
data: value,
|
|
248
252
|
variables,
|
|
249
253
|
toNotify,
|
|
250
254
|
applyUpdates,
|
|
251
255
|
layer,
|
|
252
|
-
forceNotify
|
|
256
|
+
forceNotify
|
|
253
257
|
});
|
|
254
258
|
}
|
|
255
259
|
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
|
|
@@ -278,7 +282,7 @@ class CacheInternal {
|
|
|
278
282
|
key,
|
|
279
283
|
linkedType,
|
|
280
284
|
variables,
|
|
281
|
-
fields,
|
|
285
|
+
fields: fieldSelection,
|
|
282
286
|
layer,
|
|
283
287
|
forceNotify
|
|
284
288
|
});
|
|
@@ -328,7 +332,7 @@ class CacheInternal {
|
|
|
328
332
|
if (linkedIDs.includes(lostID) || !lostID) {
|
|
329
333
|
continue;
|
|
330
334
|
}
|
|
331
|
-
this.subscriptions.remove(lostID,
|
|
335
|
+
this.subscriptions.remove(lostID, fieldSelection, currentSubscribers, variables);
|
|
332
336
|
}
|
|
333
337
|
if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
|
|
334
338
|
layer.writeLink(parent, key, linkedIDs);
|
|
@@ -339,7 +343,7 @@ class CacheInternal {
|
|
|
339
343
|
}
|
|
340
344
|
this.subscriptions.addMany({
|
|
341
345
|
parent: id,
|
|
342
|
-
selection:
|
|
346
|
+
selection: fieldSelection,
|
|
343
347
|
subscribers: currentSubscribers,
|
|
344
348
|
variables,
|
|
345
349
|
parentType: linkedType
|
|
@@ -364,9 +368,14 @@ class CacheInternal {
|
|
|
364
368
|
}
|
|
365
369
|
const targets = Array.isArray(value) ? value : [value];
|
|
366
370
|
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
|
-
|
|
371
|
+
if (operation.action === "insert" && target instanceof Object && fieldSelection && operation.list) {
|
|
372
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).addToList(
|
|
373
|
+
fieldSelection,
|
|
374
|
+
target,
|
|
375
|
+
variables,
|
|
376
|
+
operation.position || "last"
|
|
377
|
+
);
|
|
378
|
+
} else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
|
|
370
379
|
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
|
|
371
380
|
} else if (operation.action === "delete" && operation.type) {
|
|
372
381
|
if (typeof target !== "string") {
|
|
@@ -377,8 +386,13 @@ class CacheInternal {
|
|
|
377
386
|
continue;
|
|
378
387
|
}
|
|
379
388
|
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(
|
|
389
|
+
} else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
|
|
390
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
|
|
391
|
+
fieldSelection,
|
|
392
|
+
target,
|
|
393
|
+
variables,
|
|
394
|
+
operation.position || "last"
|
|
395
|
+
);
|
|
382
396
|
}
|
|
383
397
|
}
|
|
384
398
|
}
|
|
@@ -398,9 +412,12 @@ class CacheInternal {
|
|
|
398
412
|
let hasData = false;
|
|
399
413
|
let partial = false;
|
|
400
414
|
let cascadeNull = false;
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
415
|
+
const typename = this.storage.get(parent, "__typename").value;
|
|
416
|
+
let targetSelection = (0, import_selection.getFieldsForType)(selection, typename);
|
|
417
|
+
for (const [
|
|
418
|
+
attributeName,
|
|
419
|
+
{ type, keyRaw, selection: fieldSelection, nullable, list }
|
|
420
|
+
] of Object.entries(targetSelection)) {
|
|
404
421
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
405
422
|
const { value } = this.storage.get(parent, key);
|
|
406
423
|
let nextStep = stepsFromConnection;
|
|
@@ -423,7 +440,7 @@ class CacheInternal {
|
|
|
423
440
|
if (typeof value !== "undefined") {
|
|
424
441
|
hasData = true;
|
|
425
442
|
}
|
|
426
|
-
} else if (!
|
|
443
|
+
} else if (!fieldSelection) {
|
|
427
444
|
const fnUnmarshal = this.config?.scalars?.[type]?.unmarshal;
|
|
428
445
|
if (fnUnmarshal) {
|
|
429
446
|
target[attributeName] = fnUnmarshal(value);
|
|
@@ -433,7 +450,7 @@ class CacheInternal {
|
|
|
433
450
|
hasData = true;
|
|
434
451
|
} else if (Array.isArray(value)) {
|
|
435
452
|
const listValue = this.hydrateNestedList({
|
|
436
|
-
fields,
|
|
453
|
+
fields: fieldSelection,
|
|
437
454
|
variables,
|
|
438
455
|
linkedList: value,
|
|
439
456
|
stepsFromConnection: nextStep
|
|
@@ -448,7 +465,7 @@ class CacheInternal {
|
|
|
448
465
|
} else {
|
|
449
466
|
const objectFields = this.getSelection({
|
|
450
467
|
parent: value,
|
|
451
|
-
selection:
|
|
468
|
+
selection: fieldSelection,
|
|
452
469
|
variables,
|
|
453
470
|
stepsFromConnection: nextStep
|
|
454
471
|
});
|
|
@@ -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 = {
|