@isograph/react 0.0.0-main-5474b973 → 0.0.0-main-ce52cee9
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/FragmentReference.d.ts +2 -2
- package/dist/IsographEnvironment.d.ts +4 -8
- package/dist/IsographEnvironment.js +1 -0
- package/dist/cache.d.ts +4 -6
- package/dist/read.js +1 -0
- package/dist/useImperativeReference.d.ts +2 -4
- package/dist/useLazyReference.d.ts +2 -4
- package/package.json +3 -3
- package/src/FragmentReference.ts +2 -2
- package/src/IsographEnvironment.tsx +5 -4
- package/src/cache.ts +12 -15
- package/src/garbageCollection.ts +2 -1
- package/src/read.ts +6 -5
- package/src/useImperativeReference.ts +3 -3
- package/src/useLazyReference.ts +2 -2
@@ -1,9 +1,9 @@
|
|
1
1
|
import { DataId } from './IsographEnvironment';
|
2
2
|
import { RefetchQueryNormalizationArtifactWrapper } from './entrypoint';
|
3
3
|
import { TopLevelReaderArtifact } from './reader';
|
4
|
-
export type
|
4
|
+
export type VariableValue = string | number | boolean | null | object;
|
5
5
|
export type Variables = {
|
6
|
-
readonly [index: string]:
|
6
|
+
readonly [index: string]: VariableValue;
|
7
7
|
};
|
8
8
|
export type FragmentReference<TReadFromStore extends Object, TClientFieldValue> = {
|
9
9
|
readonly kind: 'FragmentReference';
|
@@ -2,7 +2,7 @@
|
|
2
2
|
import { ParentCache } from '@isograph/react-disposable-state';
|
3
3
|
import { RetainedQuery } from './garbageCollection';
|
4
4
|
import { WithEncounteredRecords } from './read';
|
5
|
-
import { FragmentReference } from './FragmentReference';
|
5
|
+
import { FragmentReference, Variables } from './FragmentReference';
|
6
6
|
export type ComponentOrFieldName = string;
|
7
7
|
export type StringifiedArgs = string;
|
8
8
|
type ComponentCache = {
|
@@ -41,10 +41,8 @@ export type IsographEnvironment = {
|
|
41
41
|
};
|
42
42
|
export type MissingFieldHandler = (storeRecord: StoreRecord, root: DataId, fieldName: string, arguments_: {
|
43
43
|
[index: string]: any;
|
44
|
-
} | null, variables:
|
45
|
-
|
46
|
-
} | null) => Link | undefined;
|
47
|
-
export type IsographNetworkFunction = (queryText: string, variables: object) => Promise<any>;
|
44
|
+
} | null, variables: Variables | null) => Link | undefined;
|
45
|
+
export type IsographNetworkFunction = (queryText: string, variables: Variables) => Promise<any>;
|
48
46
|
export type Link = {
|
49
47
|
readonly __link: DataId;
|
50
48
|
};
|
@@ -65,9 +63,7 @@ export declare function createIsographStore(): {
|
|
65
63
|
};
|
66
64
|
export declare function defaultMissingFieldHandler(_storeRecord: StoreRecord, _root: DataId, fieldName: string, arguments_: {
|
67
65
|
[index: string]: any;
|
68
|
-
} | null, variables:
|
69
|
-
[index: string]: any;
|
70
|
-
} | null): Link | undefined;
|
66
|
+
} | null, variables: Variables | null): Link | undefined;
|
71
67
|
export declare function assertLink(link: DataTypeValue): Link | null | undefined;
|
72
68
|
export declare function getLink(maybeLink: DataTypeValue): Link | null;
|
73
69
|
export {};
|
@@ -29,6 +29,7 @@ function defaultMissingFieldHandler(_storeRecord, _root, fieldName, arguments_,
|
|
29
29
|
const value = variables === null || variables === void 0 ? void 0 : variables[variable];
|
30
30
|
// TODO can we handle explicit nulls here too? Probably, after wrapping in objects
|
31
31
|
if (value != null) {
|
32
|
+
// @ts-expect-error
|
32
33
|
return { __link: value };
|
33
34
|
}
|
34
35
|
}
|
package/dist/cache.d.ts
CHANGED
@@ -4,7 +4,7 @@ import { type IsographEnvironment } from './IsographEnvironment';
|
|
4
4
|
import { IsographEntrypoint, NormalizationLinkedField, NormalizationScalarField, RefetchQueryNormalizationArtifact } from './entrypoint';
|
5
5
|
import { ReaderLinkedField, ReaderScalarField } from './reader';
|
6
6
|
import { WithEncounteredRecords } from './read';
|
7
|
-
import { FragmentReference } from './FragmentReference';
|
7
|
+
import { FragmentReference, Variables } from './FragmentReference';
|
8
8
|
declare global {
|
9
9
|
interface Window {
|
10
10
|
__LOG: boolean;
|
@@ -16,13 +16,11 @@ declare global {
|
|
16
16
|
* results.
|
17
17
|
*/
|
18
18
|
export declare function stableCopy<T>(value: T): T;
|
19
|
-
export declare function getOrCreateCacheForArtifact<TReadFromStore extends Object, TClientFieldValue>(environment: IsographEnvironment, artifact: IsographEntrypoint<TReadFromStore, TClientFieldValue>, variables:
|
20
|
-
export declare function makeNetworkRequest<T>(environment: IsographEnvironment, artifact: RefetchQueryNormalizationArtifact | IsographEntrypoint<any, any>, variables:
|
19
|
+
export declare function getOrCreateCacheForArtifact<TReadFromStore extends Object, TClientFieldValue>(environment: IsographEnvironment, artifact: IsographEntrypoint<TReadFromStore, TClientFieldValue>, variables: Variables): ParentCache<PromiseWrapper<TClientFieldValue>>;
|
20
|
+
export declare function makeNetworkRequest<T>(environment: IsographEnvironment, artifact: RefetchQueryNormalizationArtifact | IsographEntrypoint<any, any>, variables: Variables): ItemCleanupPair<PromiseWrapper<T>>;
|
21
21
|
export declare function subscribeToAnyChange(environment: IsographEnvironment, callback: () => void): () => void;
|
22
22
|
export declare function subscribe<TReadFromStore extends Object>(environment: IsographEnvironment, encounteredDataAndRecords: WithEncounteredRecords<TReadFromStore>, fragmentReference: FragmentReference<TReadFromStore, any>, callback: (newEncounteredDataAndRecords: WithEncounteredRecords<TReadFromStore>) => void): () => void;
|
23
23
|
export declare function onNextChange(environment: IsographEnvironment): Promise<void>;
|
24
|
-
export declare function getParentRecordKey(astNode: NormalizationLinkedField | NormalizationScalarField | ReaderLinkedField | ReaderScalarField, variables:
|
25
|
-
[index: string]: string;
|
26
|
-
}): string;
|
24
|
+
export declare function getParentRecordKey(astNode: NormalizationLinkedField | NormalizationScalarField | ReaderLinkedField | ReaderScalarField, variables: Variables): string;
|
27
25
|
export declare const FIRST_SPLIT_KEY = "____";
|
28
26
|
export declare const SECOND_SPLIT_KEY = "___";
|
package/dist/read.js
CHANGED
@@ -219,6 +219,7 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, mutab
|
|
219
219
|
function filterVariables(variables, allowedVariables) {
|
220
220
|
const result = {};
|
221
221
|
for (const key of allowedVariables) {
|
222
|
+
// @ts-expect-error
|
222
223
|
result[key] = variables[key];
|
223
224
|
}
|
224
225
|
return result;
|
@@ -1,9 +1,7 @@
|
|
1
1
|
import { UnassignedState } from '@isograph/react-disposable-state';
|
2
2
|
import { IsographEntrypoint } from './entrypoint';
|
3
|
-
import { FragmentReference } from './FragmentReference';
|
3
|
+
import { FragmentReference, Variables } from './FragmentReference';
|
4
4
|
export declare function useImperativeReference<TReadFromStore extends Object, TClientFieldValue>(entrypoint: IsographEntrypoint<TReadFromStore, TClientFieldValue>): {
|
5
5
|
queryReference: FragmentReference<TReadFromStore, TClientFieldValue> | UnassignedState;
|
6
|
-
loadQueryReference: (variables:
|
7
|
-
[index: string]: string;
|
8
|
-
}) => void;
|
6
|
+
loadQueryReference: (variables: Variables) => void;
|
9
7
|
};
|
@@ -1,7 +1,5 @@
|
|
1
|
-
import { FragmentReference,
|
1
|
+
import { FragmentReference, Variables } from './FragmentReference';
|
2
2
|
import { IsographEntrypoint } from './entrypoint';
|
3
|
-
export declare function useLazyReference<TReadFromStore extends Object, TClientFieldValue>(entrypoint: IsographEntrypoint<TReadFromStore, TClientFieldValue>, variables: {
|
4
|
-
[key: string]: Variable;
|
5
|
-
}): {
|
3
|
+
export declare function useLazyReference<TReadFromStore extends Object, TClientFieldValue>(entrypoint: IsographEntrypoint<TReadFromStore, TClientFieldValue>, variables: Variables): {
|
6
4
|
queryReference: FragmentReference<TReadFromStore, TClientFieldValue>;
|
7
5
|
};
|
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-ce52cee9",
|
4
4
|
"description": "Use Isograph with React",
|
5
5
|
"homepage": "https://isograph.dev",
|
6
6
|
"main": "dist/index.js",
|
@@ -16,8 +16,8 @@
|
|
16
16
|
"prepack": "yarn run test && yarn run compile"
|
17
17
|
},
|
18
18
|
"dependencies": {
|
19
|
-
"@isograph/disposable-types": "0.0.0-main-
|
20
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
19
|
+
"@isograph/disposable-types": "0.0.0-main-ce52cee9",
|
20
|
+
"@isograph/react-disposable-state": "0.0.0-main-ce52cee9",
|
21
21
|
"react": "^18.2.0"
|
22
22
|
},
|
23
23
|
"devDependencies": {
|
package/src/FragmentReference.ts
CHANGED
@@ -3,9 +3,9 @@ import { RefetchQueryNormalizationArtifactWrapper } from './entrypoint';
|
|
3
3
|
import { TopLevelReaderArtifact } from './reader';
|
4
4
|
|
5
5
|
// TODO type this better
|
6
|
-
export type
|
6
|
+
export type VariableValue = string | number | boolean | null | object;
|
7
7
|
|
8
|
-
export type Variables = { readonly [index: string]:
|
8
|
+
export type Variables = { readonly [index: string]: VariableValue };
|
9
9
|
|
10
10
|
export type FragmentReference<
|
11
11
|
TReadFromStore extends Object,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ParentCache } from '@isograph/react-disposable-state';
|
2
2
|
import { RetainedQuery } from './garbageCollection';
|
3
3
|
import { WithEncounteredRecords } from './read';
|
4
|
-
import { FragmentReference } from './FragmentReference';
|
4
|
+
import { FragmentReference, Variables } from './FragmentReference';
|
5
5
|
|
6
6
|
export type ComponentOrFieldName = string;
|
7
7
|
export type StringifiedArgs = string;
|
@@ -46,12 +46,12 @@ export type MissingFieldHandler = (
|
|
46
46
|
root: DataId,
|
47
47
|
fieldName: string,
|
48
48
|
arguments_: { [index: string]: any } | null,
|
49
|
-
variables:
|
49
|
+
variables: Variables | null,
|
50
50
|
) => Link | undefined;
|
51
51
|
|
52
52
|
export type IsographNetworkFunction = (
|
53
53
|
queryText: string,
|
54
|
-
variables:
|
54
|
+
variables: Variables,
|
55
55
|
) => Promise<any>;
|
56
56
|
|
57
57
|
export type Link = {
|
@@ -118,7 +118,7 @@ export function defaultMissingFieldHandler(
|
|
118
118
|
_root: DataId,
|
119
119
|
fieldName: string,
|
120
120
|
arguments_: { [index: string]: any } | null,
|
121
|
-
variables:
|
121
|
+
variables: Variables | null,
|
122
122
|
): Link | undefined {
|
123
123
|
if (fieldName === 'node' || fieldName === 'user') {
|
124
124
|
const variable = arguments_?.['id'];
|
@@ -126,6 +126,7 @@ export function defaultMissingFieldHandler(
|
|
126
126
|
|
127
127
|
// TODO can we handle explicit nulls here too? Probably, after wrapping in objects
|
128
128
|
if (value != null) {
|
129
|
+
// @ts-expect-error
|
129
130
|
return { __link: value };
|
130
131
|
}
|
131
132
|
}
|
package/src/cache.ts
CHANGED
@@ -30,7 +30,7 @@ import {
|
|
30
30
|
import { ReaderLinkedField, ReaderScalarField } from './reader';
|
31
31
|
import { Argument, ArgumentValue } from './util';
|
32
32
|
import { WithEncounteredRecords, readButDoNotEvaluate } from './read';
|
33
|
-
import { FragmentReference } from './FragmentReference';
|
33
|
+
import { FragmentReference, Variables } from './FragmentReference';
|
34
34
|
import { areEqualObjectsWithDeepComparison } from './areEqualWithDeepComparison';
|
35
35
|
|
36
36
|
declare global {
|
@@ -86,7 +86,7 @@ export function getOrCreateCacheForArtifact<
|
|
86
86
|
>(
|
87
87
|
environment: IsographEnvironment,
|
88
88
|
artifact: IsographEntrypoint<TReadFromStore, TClientFieldValue>,
|
89
|
-
variables:
|
89
|
+
variables: Variables,
|
90
90
|
): ParentCache<PromiseWrapper<TClientFieldValue>> {
|
91
91
|
const cacheKey = artifact.queryText + JSON.stringify(stableCopy(variables));
|
92
92
|
const factory: Factory<PromiseWrapper<TClientFieldValue>> = () =>
|
@@ -113,7 +113,7 @@ type NetworkRequestStatus =
|
|
113
113
|
export function makeNetworkRequest<T>(
|
114
114
|
environment: IsographEnvironment,
|
115
115
|
artifact: RefetchQueryNormalizationArtifact | IsographEntrypoint<any, any>,
|
116
|
-
variables:
|
116
|
+
variables: Variables,
|
117
117
|
): ItemCleanupPair<PromiseWrapper<T>> {
|
118
118
|
if (typeof window !== 'undefined' && window.__LOG) {
|
119
119
|
console.log('make network request', artifact, variables);
|
@@ -191,7 +191,7 @@ function normalizeData(
|
|
191
191
|
environment: IsographEnvironment,
|
192
192
|
normalizationAst: NormalizationAst,
|
193
193
|
networkResponse: NetworkResponseObject,
|
194
|
-
variables:
|
194
|
+
variables: Variables,
|
195
195
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
196
196
|
): Set<DataId> {
|
197
197
|
const encounteredIds = new Set<DataId>();
|
@@ -342,7 +342,7 @@ function normalizeDataIntoRecord(
|
|
342
342
|
networkResponseParentRecord: NetworkResponseObject,
|
343
343
|
targetParentRecord: StoreRecord,
|
344
344
|
targetParentRecordId: DataId,
|
345
|
-
variables:
|
345
|
+
variables: Variables,
|
346
346
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
347
347
|
mutableEncounteredIds: Set<DataId>,
|
348
348
|
) {
|
@@ -387,7 +387,7 @@ function normalizeScalarField(
|
|
387
387
|
astNode: NormalizationScalarField,
|
388
388
|
networkResponseParentRecord: NetworkResponseObject,
|
389
389
|
targetStoreRecord: StoreRecord,
|
390
|
-
variables:
|
390
|
+
variables: Variables,
|
391
391
|
): RecordHasBeenUpdated {
|
392
392
|
const networkResponseKey = getNetworkResponseKey(astNode);
|
393
393
|
const networkResponseData = networkResponseParentRecord[networkResponseKey];
|
@@ -414,7 +414,7 @@ function normalizeLinkedField(
|
|
414
414
|
networkResponseParentRecord: NetworkResponseObject,
|
415
415
|
targetParentRecord: StoreRecord,
|
416
416
|
targetParentRecordId: DataId,
|
417
|
-
variables:
|
417
|
+
variables: Variables,
|
418
418
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
419
419
|
mutableEncounteredIds: Set<DataId>,
|
420
420
|
): RecordHasBeenUpdated {
|
@@ -501,7 +501,7 @@ function normalizeNetworkResponseObject(
|
|
501
501
|
astNode: NormalizationLinkedField,
|
502
502
|
networkResponseData: NetworkResponseObject,
|
503
503
|
targetParentRecordId: string,
|
504
|
-
variables:
|
504
|
+
variables: Variables,
|
505
505
|
index: number | null,
|
506
506
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
507
507
|
mutableEncounteredIds: Set<DataId>,
|
@@ -570,7 +570,7 @@ export function getParentRecordKey(
|
|
570
570
|
| NormalizationScalarField
|
571
571
|
| ReaderLinkedField
|
572
572
|
| ReaderScalarField,
|
573
|
-
variables:
|
573
|
+
variables: Variables,
|
574
574
|
): string {
|
575
575
|
let parentRecordKey = astNode.fieldName;
|
576
576
|
const fieldParameters = astNode.arguments;
|
@@ -585,7 +585,7 @@ export function getParentRecordKey(
|
|
585
585
|
|
586
586
|
function getStoreKeyChunkForArgumentValue(
|
587
587
|
argumentValue: ArgumentValue,
|
588
|
-
variables:
|
588
|
+
variables: Variables,
|
589
589
|
) {
|
590
590
|
switch (argumentValue.kind) {
|
591
591
|
case 'Literal': {
|
@@ -603,10 +603,7 @@ function getStoreKeyChunkForArgumentValue(
|
|
603
603
|
}
|
604
604
|
}
|
605
605
|
|
606
|
-
function getStoreKeyChunkForArgument(
|
607
|
-
argument: Argument,
|
608
|
-
variables: { [index: string]: string },
|
609
|
-
) {
|
606
|
+
function getStoreKeyChunkForArgument(argument: Argument, variables: Variables) {
|
610
607
|
const chunk = getStoreKeyChunkForArgumentValue(argument[1], variables);
|
611
608
|
return `${FIRST_SPLIT_KEY}${argument[0]}${SECOND_SPLIT_KEY}${chunk}`;
|
612
609
|
}
|
@@ -650,7 +647,7 @@ function getDataIdOfNetworkResponse(
|
|
650
647
|
parentRecordId: DataId,
|
651
648
|
dataToNormalize: NetworkResponseObject,
|
652
649
|
astNode: NormalizationLinkedField | NormalizationScalarField,
|
653
|
-
variables:
|
650
|
+
variables: Variables,
|
654
651
|
index: number | null,
|
655
652
|
): DataId {
|
656
653
|
// Check whether the dataToNormalize has an id field. If so, that is the key.
|
package/src/garbageCollection.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Variables } from './FragmentReference';
|
1
2
|
import {
|
2
3
|
DataId,
|
3
4
|
IsographEnvironment,
|
@@ -76,7 +77,7 @@ function recordReachableIdsFromRecord(
|
|
76
77
|
currentRecord: StoreRecord,
|
77
78
|
mutableRetainedIds: Set<DataId>,
|
78
79
|
selections: NormalizationAst,
|
79
|
-
variables:
|
80
|
+
variables: Variables | null,
|
80
81
|
) {
|
81
82
|
for (const selection of selections) {
|
82
83
|
switch (selection.kind) {
|
package/src/read.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { getParentRecordKey, onNextChange } from './cache';
|
2
2
|
import { getOrCreateCachedComponent } from './componentCache';
|
3
3
|
import { RefetchQueryNormalizationArtifactWrapper } from './entrypoint';
|
4
|
-
import { FragmentReference } from './FragmentReference';
|
4
|
+
import { FragmentReference, Variables } from './FragmentReference';
|
5
5
|
import {
|
6
6
|
assertLink,
|
7
7
|
DataId,
|
@@ -57,7 +57,7 @@ function readData<TReadFromStore>(
|
|
57
57
|
environment: IsographEnvironment,
|
58
58
|
ast: ReaderAst<TReadFromStore>,
|
59
59
|
root: DataId,
|
60
|
-
variables:
|
60
|
+
variables: Variables,
|
61
61
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
62
62
|
mutableEncounteredRecords: Set<DataId>,
|
63
63
|
): ReadDataResult<TReadFromStore> {
|
@@ -315,11 +315,12 @@ function readData<TReadFromStore>(
|
|
315
315
|
}
|
316
316
|
|
317
317
|
function filterVariables(
|
318
|
-
variables:
|
318
|
+
variables: Variables,
|
319
319
|
allowedVariables: string[],
|
320
|
-
):
|
321
|
-
const result:
|
320
|
+
): Variables {
|
321
|
+
const result: Variables = {};
|
322
322
|
for (const key of allowedVariables) {
|
323
|
+
// @ts-expect-error
|
323
324
|
result[key] = variables[key];
|
324
325
|
}
|
325
326
|
return result;
|
@@ -3,7 +3,7 @@ import {
|
|
3
3
|
useUpdatableDisposableState,
|
4
4
|
} from '@isograph/react-disposable-state';
|
5
5
|
import { IsographEntrypoint } from './entrypoint';
|
6
|
-
import { FragmentReference } from './FragmentReference';
|
6
|
+
import { FragmentReference, Variables } from './FragmentReference';
|
7
7
|
import { useIsographEnvironment } from './IsographEnvironmentProvider';
|
8
8
|
import { makeNetworkRequest } from './cache';
|
9
9
|
import { ROOT_ID } from './IsographEnvironment';
|
@@ -17,7 +17,7 @@ export function useImperativeReference<
|
|
17
17
|
queryReference:
|
18
18
|
| FragmentReference<TReadFromStore, TClientFieldValue>
|
19
19
|
| UnassignedState;
|
20
|
-
loadQueryReference: (variables:
|
20
|
+
loadQueryReference: (variables: Variables) => void;
|
21
21
|
} {
|
22
22
|
const { state, setState } =
|
23
23
|
useUpdatableDisposableState<
|
@@ -26,7 +26,7 @@ export function useImperativeReference<
|
|
26
26
|
const environment = useIsographEnvironment();
|
27
27
|
return {
|
28
28
|
queryReference: state,
|
29
|
-
loadQueryReference: (variables:
|
29
|
+
loadQueryReference: (variables: Variables) => {
|
30
30
|
const [_networkRequest, disposeNetworkRequest] = makeNetworkRequest(
|
31
31
|
environment,
|
32
32
|
entrypoint,
|
package/src/useLazyReference.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { FragmentReference,
|
1
|
+
import { FragmentReference, Variables } from './FragmentReference';
|
2
2
|
import { useIsographEnvironment } from './IsographEnvironmentProvider';
|
3
3
|
import { ROOT_ID } from './IsographEnvironment';
|
4
4
|
import { IsographEntrypoint } from './entrypoint';
|
@@ -10,7 +10,7 @@ export function useLazyReference<
|
|
10
10
|
TClientFieldValue,
|
11
11
|
>(
|
12
12
|
entrypoint: IsographEntrypoint<TReadFromStore, TClientFieldValue>,
|
13
|
-
variables:
|
13
|
+
variables: Variables,
|
14
14
|
): {
|
15
15
|
queryReference: FragmentReference<TReadFromStore, TClientFieldValue>;
|
16
16
|
} {
|