@isograph/react 0.0.0-main-55364d41 → 0.0.0-main-1cd3db6d
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/dist/cache.js +40 -8
- package/dist/index.d.ts +8 -3
- package/package.json +3 -3
- package/src/cache.ts +50 -8
- package/src/index.tsx +11 -4
package/dist/cache.js
CHANGED
@@ -215,21 +215,55 @@ function getParentRecordKey(astNode, variables) {
|
|
215
215
|
const fieldParameters = astNode.arguments;
|
216
216
|
if (fieldParameters != null) {
|
217
217
|
for (const fieldParameter of fieldParameters) {
|
218
|
-
|
219
|
-
const valueToUse = variables[variableName];
|
220
|
-
parentRecordKey += `${exports.FIRST_SPLIT_KEY}${argumentName}${exports.SECOND_SPLIT_KEY}${valueToUse}`;
|
218
|
+
parentRecordKey += getStoreKeyChunkForArgument(fieldParameter, variables);
|
221
219
|
}
|
222
220
|
}
|
223
221
|
return parentRecordKey;
|
224
222
|
}
|
225
223
|
exports.getParentRecordKey = getParentRecordKey;
|
224
|
+
function getStoreKeyChunkForArgumentValue(argumentValue, variables) {
|
225
|
+
switch (argumentValue.kind) {
|
226
|
+
case "Literal": {
|
227
|
+
return argumentValue.value;
|
228
|
+
break;
|
229
|
+
}
|
230
|
+
case "Variable": {
|
231
|
+
return variables[argumentValue.name];
|
232
|
+
break;
|
233
|
+
}
|
234
|
+
default: {
|
235
|
+
// TODO configure eslint to allow unused vars starting with _
|
236
|
+
let _ = argumentValue;
|
237
|
+
throw new Error("Unexpected case");
|
238
|
+
}
|
239
|
+
}
|
240
|
+
}
|
241
|
+
function getStoreKeyChunkForArgument(argument, variables) {
|
242
|
+
const chunk = getStoreKeyChunkForArgumentValue(argument[1], variables);
|
243
|
+
return `${exports.FIRST_SPLIT_KEY}${argument[0]}${exports.SECOND_SPLIT_KEY}${chunk}`;
|
244
|
+
}
|
226
245
|
function getNetworkResponseKey(astNode) {
|
227
246
|
let networkResponseKey = astNode.fieldName;
|
228
247
|
const fieldParameters = astNode.arguments;
|
229
248
|
if (fieldParameters != null) {
|
230
249
|
for (const fieldParameter of fieldParameters) {
|
231
|
-
const
|
232
|
-
|
250
|
+
const [argumentName, argumentValue] = fieldParameter;
|
251
|
+
let argumentValueChunk;
|
252
|
+
switch (argumentValue.kind) {
|
253
|
+
case "Literal": {
|
254
|
+
argumentValueChunk = "l_" + argumentValue.value;
|
255
|
+
break;
|
256
|
+
}
|
257
|
+
case "Variable": {
|
258
|
+
argumentValueChunk = "v_" + argumentValue.name;
|
259
|
+
break;
|
260
|
+
}
|
261
|
+
default: {
|
262
|
+
let _ = argumentValue;
|
263
|
+
throw new Error("Unexpected case");
|
264
|
+
}
|
265
|
+
}
|
266
|
+
networkResponseKey += `${exports.FIRST_SPLIT_KEY}${argumentName}${exports.SECOND_SPLIT_KEY}${argumentValueChunk}`;
|
233
267
|
}
|
234
268
|
}
|
235
269
|
return networkResponseKey;
|
@@ -254,9 +288,7 @@ function getDataIdOfNetworkResponse(parentRecordId, dataToNormalize, astNode, va
|
|
254
288
|
return storeKey;
|
255
289
|
}
|
256
290
|
for (const fieldParameter of fieldParameters) {
|
257
|
-
|
258
|
-
const valueToUse = variables[variableName];
|
259
|
-
storeKey += `${exports.FIRST_SPLIT_KEY}${argumentName}${exports.SECOND_SPLIT_KEY}${valueToUse}`;
|
291
|
+
storeKey += getStoreKeyChunkForArgument(fieldParameter, variables);
|
260
292
|
}
|
261
293
|
return storeKey;
|
262
294
|
}
|
package/dist/index.d.ts
CHANGED
@@ -77,9 +77,14 @@ export type RefetchQueryArtifactWrapper = {
|
|
77
77
|
allowedVariables: string[];
|
78
78
|
};
|
79
79
|
export type Arguments = Argument[];
|
80
|
-
export type Argument =
|
81
|
-
|
82
|
-
|
80
|
+
export type Argument = [ArgumentName, ArgumentValue];
|
81
|
+
export type ArgumentName = string;
|
82
|
+
export type ArgumentValue = {
|
83
|
+
kind: "Variable";
|
84
|
+
name: string;
|
85
|
+
} | {
|
86
|
+
kind: "Literal";
|
87
|
+
value: any;
|
83
88
|
};
|
84
89
|
export type FragmentReference<TReadFromStore extends Object, TResolverProps, TResolverResult> = {
|
85
90
|
kind: "FragmentReference";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@isograph/react",
|
3
|
-
"version": "0.0.0-main-
|
3
|
+
"version": "0.0.0-main-1cd3db6d",
|
4
4
|
"description": "Use Isograph with React",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -15,8 +15,8 @@
|
|
15
15
|
"prepack": "yarn run test && yarn run compile"
|
16
16
|
},
|
17
17
|
"dependencies": {
|
18
|
-
"@isograph/disposable-types": "0.0.0-main-
|
19
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
18
|
+
"@isograph/disposable-types": "0.0.0-main-1cd3db6d",
|
19
|
+
"@isograph/react-disposable-state": "0.0.0-main-1cd3db6d",
|
20
20
|
"react": "^18.2.0"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
package/src/cache.ts
CHANGED
@@ -5,6 +5,8 @@ import {
|
|
5
5
|
} from "@isograph/react-disposable-state";
|
6
6
|
import { PromiseWrapper, wrapPromise } from "./PromiseWrapper";
|
7
7
|
import {
|
8
|
+
Argument,
|
9
|
+
ArgumentValue,
|
8
10
|
IsographEntrypoint,
|
9
11
|
NormalizationAst,
|
10
12
|
NormalizationLinkedField,
|
@@ -412,15 +414,42 @@ export function getParentRecordKey(
|
|
412
414
|
const fieldParameters = astNode.arguments;
|
413
415
|
if (fieldParameters != null) {
|
414
416
|
for (const fieldParameter of fieldParameters) {
|
415
|
-
|
416
|
-
const valueToUse = variables[variableName];
|
417
|
-
parentRecordKey += `${FIRST_SPLIT_KEY}${argumentName}${SECOND_SPLIT_KEY}${valueToUse}`;
|
417
|
+
parentRecordKey += getStoreKeyChunkForArgument(fieldParameter, variables);
|
418
418
|
}
|
419
419
|
}
|
420
420
|
|
421
421
|
return parentRecordKey;
|
422
422
|
}
|
423
423
|
|
424
|
+
function getStoreKeyChunkForArgumentValue(
|
425
|
+
argumentValue: ArgumentValue,
|
426
|
+
variables: { [index: string]: string }
|
427
|
+
) {
|
428
|
+
switch (argumentValue.kind) {
|
429
|
+
case "Literal": {
|
430
|
+
return argumentValue.value;
|
431
|
+
break;
|
432
|
+
}
|
433
|
+
case "Variable": {
|
434
|
+
return variables[argumentValue.name];
|
435
|
+
break;
|
436
|
+
}
|
437
|
+
default: {
|
438
|
+
// TODO configure eslint to allow unused vars starting with _
|
439
|
+
let _: never = argumentValue;
|
440
|
+
throw new Error("Unexpected case");
|
441
|
+
}
|
442
|
+
}
|
443
|
+
}
|
444
|
+
|
445
|
+
function getStoreKeyChunkForArgument(
|
446
|
+
argument: Argument,
|
447
|
+
variables: { [index: string]: string }
|
448
|
+
) {
|
449
|
+
const chunk = getStoreKeyChunkForArgumentValue(argument[1], variables);
|
450
|
+
return `${FIRST_SPLIT_KEY}${argument[0]}${SECOND_SPLIT_KEY}${chunk}`;
|
451
|
+
}
|
452
|
+
|
424
453
|
function getNetworkResponseKey(
|
425
454
|
astNode: NormalizationLinkedField | NormalizationScalarField
|
426
455
|
): string {
|
@@ -428,8 +457,23 @@ function getNetworkResponseKey(
|
|
428
457
|
const fieldParameters = astNode.arguments;
|
429
458
|
if (fieldParameters != null) {
|
430
459
|
for (const fieldParameter of fieldParameters) {
|
431
|
-
const
|
432
|
-
|
460
|
+
const [argumentName, argumentValue] = fieldParameter;
|
461
|
+
let argumentValueChunk;
|
462
|
+
switch (argumentValue.kind) {
|
463
|
+
case "Literal": {
|
464
|
+
argumentValueChunk = "l_" + argumentValue.value;
|
465
|
+
break;
|
466
|
+
}
|
467
|
+
case "Variable": {
|
468
|
+
argumentValueChunk = "v_" + argumentValue.name;
|
469
|
+
break;
|
470
|
+
}
|
471
|
+
default: {
|
472
|
+
let _: never = argumentValue;
|
473
|
+
throw new Error("Unexpected case");
|
474
|
+
}
|
475
|
+
}
|
476
|
+
networkResponseKey += `${FIRST_SPLIT_KEY}${argumentName}${SECOND_SPLIT_KEY}${argumentValueChunk}`;
|
433
477
|
}
|
434
478
|
}
|
435
479
|
return networkResponseKey;
|
@@ -466,9 +510,7 @@ function getDataIdOfNetworkResponse(
|
|
466
510
|
}
|
467
511
|
|
468
512
|
for (const fieldParameter of fieldParameters) {
|
469
|
-
|
470
|
-
const valueToUse = variables[variableName];
|
471
|
-
storeKey += `${FIRST_SPLIT_KEY}${argumentName}${SECOND_SPLIT_KEY}${valueToUse}`;
|
513
|
+
storeKey += getStoreKeyChunkForArgument(fieldParameter, variables);
|
472
514
|
}
|
473
515
|
return storeKey;
|
474
516
|
}
|
package/src/index.tsx
CHANGED
@@ -139,10 +139,17 @@ export type RefetchQueryArtifactWrapper = {
|
|
139
139
|
};
|
140
140
|
|
141
141
|
export type Arguments = Argument[];
|
142
|
-
export type Argument =
|
143
|
-
|
144
|
-
|
145
|
-
|
142
|
+
export type Argument = [ArgumentName, ArgumentValue];
|
143
|
+
export type ArgumentName = string;
|
144
|
+
export type ArgumentValue =
|
145
|
+
| {
|
146
|
+
kind: "Variable";
|
147
|
+
name: string;
|
148
|
+
}
|
149
|
+
| {
|
150
|
+
kind: "Literal";
|
151
|
+
value: any;
|
152
|
+
};
|
146
153
|
|
147
154
|
export type FragmentReference<
|
148
155
|
TReadFromStore extends Object,
|