@isograph/react 0.3.0 → 0.3.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/.turbo/turbo-compile-typescript.log +4 -0
- package/dist/core/FragmentReference.d.ts +16 -7
- package/dist/core/FragmentReference.d.ts.map +1 -1
- package/dist/core/FragmentReference.js +3 -12
- package/dist/core/IsographEnvironment.d.ts +17 -27
- package/dist/core/IsographEnvironment.d.ts.map +1 -1
- package/dist/core/IsographEnvironment.js +4 -0
- package/dist/core/PromiseWrapper.d.ts +3 -4
- package/dist/core/PromiseWrapper.d.ts.map +1 -1
- package/dist/core/PromiseWrapper.js +5 -4
- package/dist/core/areEqualWithDeepComparison.d.ts.map +1 -1
- package/dist/core/areEqualWithDeepComparison.js +16 -0
- package/dist/core/cache.d.ts +11 -20
- package/dist/core/cache.d.ts.map +1 -1
- package/dist/core/cache.js +60 -45
- package/dist/core/check.d.ts +9 -5
- package/dist/core/check.d.ts.map +1 -1
- package/dist/core/check.js +2 -2
- package/dist/core/componentCache.d.ts +1 -1
- package/dist/core/componentCache.d.ts.map +1 -1
- package/dist/core/componentCache.js +27 -31
- package/dist/core/entrypoint.d.ts +23 -26
- package/dist/core/entrypoint.d.ts.map +1 -1
- package/dist/core/garbageCollection.d.ts +3 -4
- package/dist/core/garbageCollection.d.ts.map +1 -1
- package/dist/core/garbageCollection.js +1 -1
- package/dist/core/logging.d.ts +12 -13
- package/dist/core/logging.d.ts.map +1 -1
- package/dist/core/logging.js +8 -5
- package/dist/core/makeNetworkRequest.d.ts +5 -5
- package/dist/core/makeNetworkRequest.d.ts.map +1 -1
- package/dist/core/makeNetworkRequest.js +107 -22
- package/dist/core/read.d.ts +15 -10
- package/dist/core/read.d.ts.map +1 -1
- package/dist/core/read.js +398 -304
- package/dist/core/reader.d.ts +24 -32
- package/dist/core/reader.d.ts.map +1 -1
- package/dist/core/startUpdate.d.ts +5 -0
- package/dist/core/startUpdate.d.ts.map +1 -0
- package/dist/core/startUpdate.js +15 -0
- package/dist/core/util.d.ts +3 -0
- package/dist/core/util.d.ts.map +1 -1
- package/dist/index.d.ts +16 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/loadable-hooks/useClientSideDefer.d.ts +4 -10
- package/dist/loadable-hooks/useClientSideDefer.d.ts.map +1 -1
- package/dist/loadable-hooks/useClientSideDefer.js +2 -2
- package/dist/loadable-hooks/useConnectionSpecPagination.d.ts +8 -15
- package/dist/loadable-hooks/useConnectionSpecPagination.d.ts.map +1 -1
- package/dist/loadable-hooks/useConnectionSpecPagination.js +6 -4
- package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts +1 -2
- package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts.map +1 -1
- package/dist/loadable-hooks/useImperativeLoadableField.d.ts +4 -6
- package/dist/loadable-hooks/useImperativeLoadableField.d.ts.map +1 -1
- package/dist/loadable-hooks/useImperativeLoadableField.js +1 -1
- package/dist/loadable-hooks/useSkipLimitPagination.d.ts +6 -13
- package/dist/loadable-hooks/useSkipLimitPagination.d.ts.map +1 -1
- package/dist/loadable-hooks/useSkipLimitPagination.js +11 -9
- package/dist/react/FragmentReader.d.ts +2 -3
- package/dist/react/FragmentReader.d.ts.map +1 -1
- package/dist/react/IsographEnvironmentProvider.d.ts.map +1 -1
- package/dist/react/useImperativeReference.d.ts +7 -10
- package/dist/react/useImperativeReference.d.ts.map +1 -1
- package/dist/react/useImperativeReference.js +2 -3
- package/dist/react/useLazyReference.d.ts +4 -7
- package/dist/react/useLazyReference.d.ts.map +1 -1
- package/dist/react/useLazyReference.js +26 -5
- package/dist/react/useReadAndSubscribe.d.ts +3 -9
- package/dist/react/useReadAndSubscribe.d.ts.map +1 -1
- package/dist/react/useReadAndSubscribe.js +7 -3
- package/dist/react/useRerenderOnChange.d.ts +1 -1
- package/dist/react/useRerenderOnChange.d.ts.map +1 -1
- package/dist/react/useResult.d.ts +3 -6
- package/dist/react/useResult.d.ts.map +1 -1
- package/dist/react/useResult.js +10 -8
- package/isograph.config.json +1 -0
- package/package.json +7 -6
- package/src/core/FragmentReference.ts +30 -15
- package/src/core/IsographEnvironment.ts +39 -31
- package/src/core/PromiseWrapper.ts +3 -3
- package/src/core/areEqualWithDeepComparison.ts +20 -0
- package/src/core/cache.ts +105 -72
- package/src/core/check.ts +13 -8
- package/src/core/componentCache.ts +45 -52
- package/src/core/entrypoint.ts +34 -16
- package/src/core/garbageCollection.ts +6 -6
- package/src/core/logging.ts +24 -22
- package/src/core/makeNetworkRequest.ts +183 -30
- package/src/core/read.ts +618 -435
- package/src/core/reader.ts +37 -24
- package/src/core/startUpdate.ts +28 -0
- package/src/core/util.ts +4 -0
- package/src/index.ts +82 -9
- package/src/loadable-hooks/useClientSideDefer.ts +11 -10
- package/src/loadable-hooks/useConnectionSpecPagination.ts +26 -13
- package/src/loadable-hooks/useImperativeExposedMutationField.ts +1 -1
- package/src/loadable-hooks/useImperativeLoadableField.ts +10 -12
- package/src/loadable-hooks/useSkipLimitPagination.ts +37 -19
- package/src/react/FragmentReader.tsx +3 -3
- package/src/react/IsographEnvironmentProvider.tsx +1 -1
- package/src/react/useImperativeReference.ts +40 -19
- package/src/react/useLazyReference.ts +62 -14
- package/src/react/useReadAndSubscribe.ts +17 -9
- package/src/react/useRerenderOnChange.ts +2 -2
- package/src/react/useResult.ts +21 -8
- package/src/tests/__isograph/Query/meName/entrypoint.ts +4 -28
- package/src/tests/__isograph/Query/meName/normalization_ast.ts +25 -0
- package/src/tests/__isograph/Query/meName/query_text.ts +6 -0
- package/src/tests/__isograph/Query/meName/resolver_reader.ts +4 -0
- package/src/tests/__isograph/Query/meNameSuccessor/entrypoint.ts +4 -66
- package/src/tests/__isograph/Query/meNameSuccessor/normalization_ast.ts +56 -0
- package/src/tests/__isograph/Query/meNameSuccessor/query_text.ts +13 -0
- package/src/tests/__isograph/Query/meNameSuccessor/resolver_reader.ts +7 -0
- package/src/tests/__isograph/Query/nodeField/entrypoint.ts +4 -33
- package/src/tests/__isograph/Query/nodeField/normalization_ast.ts +30 -0
- package/src/tests/__isograph/Query/nodeField/query_text.ts +6 -0
- package/src/tests/__isograph/Query/nodeField/resolver_reader.ts +4 -0
- package/src/tests/__isograph/Query/subquery/entrypoint.ts +4 -43
- package/src/tests/__isograph/Query/subquery/normalization_ast.ts +38 -0
- package/src/tests/__isograph/Query/subquery/query_text.ts +8 -0
- package/src/tests/__isograph/Query/subquery/resolver_reader.ts +5 -0
- package/src/tests/__isograph/iso.ts +3 -2
- package/src/tests/garbageCollection.test.ts +10 -8
- package/src/tests/meNameSuccessor.ts +1 -1
- package/src/tests/nodeQuery.ts +2 -1
- package/src/tests/normalizeData.test.ts +1 -1
- package/tsconfig.pkg.json +1 -2
@@ -2,16 +2,15 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.useImperativeReference = useImperativeReference;
|
4
4
|
const react_disposable_state_1 = require("@isograph/react-disposable-state");
|
5
|
-
const IsographEnvironmentProvider_1 = require("./IsographEnvironmentProvider");
|
6
5
|
const IsographEnvironment_1 = require("../core/IsographEnvironment");
|
7
6
|
const makeNetworkRequest_1 = require("../core/makeNetworkRequest");
|
8
7
|
const PromiseWrapper_1 = require("../core/PromiseWrapper");
|
9
|
-
|
8
|
+
const IsographEnvironmentProvider_1 = require("./IsographEnvironmentProvider");
|
10
9
|
function useImperativeReference(entrypoint) {
|
11
10
|
const { state, setState } = (0, react_disposable_state_1.useUpdatableDisposableState)();
|
12
11
|
const environment = (0, IsographEnvironmentProvider_1.useIsographEnvironment)();
|
13
12
|
return {
|
14
|
-
fragmentReference: state,
|
13
|
+
fragmentReference: state !== react_disposable_state_1.UNASSIGNED_STATE ? state : null,
|
15
14
|
loadFragmentReference: (variables, fetchOptions) => {
|
16
15
|
const [networkRequest, disposeNetworkRequest] = (0, makeNetworkRequest_1.maybeMakeNetworkRequest)(environment, entrypoint, variables, fetchOptions);
|
17
16
|
setState([
|
@@ -1,10 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import { IsographEntrypoint } from '../core/entrypoint';
|
3
|
-
import {
|
4
|
-
export declare function useLazyReference<TReadFromStore extends {
|
5
|
-
parameters: object;
|
6
|
-
data: object;
|
7
|
-
}, TClientFieldValue>(entrypoint: IsographEntrypoint<TReadFromStore, TClientFieldValue>, variables: ExtractParameters<TReadFromStore>, fetchOptions?: FetchOptions): {
|
1
|
+
import { FetchOptions, type RequiredFetchOptions } from '../core/check';
|
2
|
+
import { IsographEntrypoint, type NormalizationAst, type NormalizationAstLoader } from '../core/entrypoint';
|
3
|
+
import { ExtractParameters, FragmentReference, type UnknownTReadFromStore } from '../core/FragmentReference';
|
4
|
+
export declare function useLazyReference<TReadFromStore extends UnknownTReadFromStore, TClientFieldValue, TNormalizationAst extends NormalizationAst | NormalizationAstLoader>(entrypoint: IsographEntrypoint<TReadFromStore, TClientFieldValue, TNormalizationAst>, variables: ExtractParameters<TReadFromStore>, ...[fetchOptions]: TNormalizationAst extends NormalizationAstLoader ? [fetchOptions: RequiredFetchOptions<TClientFieldValue>] : [fetchOptions?: FetchOptions<TClientFieldValue>]): NormalizationAst | NormalizationAstLoader extends TNormalizationAst ? unknown : {
|
8
5
|
fragmentReference: FragmentReference<TReadFromStore, TClientFieldValue>;
|
9
6
|
};
|
10
7
|
//# sourceMappingURL=useLazyReference.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useLazyReference.d.ts","sourceRoot":"","sources":["../../src/react/useLazyReference.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"useLazyReference.d.ts","sourceRoot":"","sources":["../../src/react/useLazyReference.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EACL,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,qBAAqB,EAC3B,MAAM,2BAA2B,CAAC;AAInC,wBAAgB,gBAAgB,CAC9B,cAAc,SAAS,qBAAqB,EAC5C,iBAAiB,EACjB,iBAAiB,SAAS,gBAAgB,GAAG,sBAAsB,EAEnE,UAAU,EAAE,kBAAkB,CAC5B,cAAc,EACd,iBAAiB,EACjB,iBAAiB,CAClB,EACD,SAAS,EAAE,iBAAiB,CAAC,cAAc,CAAC,EAC5C,GAAG,CAAC,YAAY,CAAC,EAAE,iBAAiB,SAAS,sBAAsB,GAC/D,CAAC,YAAY,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,GACvD,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC,GACnD,gBAAgB,GAAG,sBAAsB,SAAS,iBAAiB,GAClE,OAAO,GACP;IACE,iBAAiB,EAAE,iBAAiB,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;CACzE,CAqBJ"}
|
@@ -1,21 +1,42 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.useLazyReference = useLazyReference;
|
4
|
-
const IsographEnvironmentProvider_1 = require("./IsographEnvironmentProvider");
|
5
|
-
const cache_1 = require("../core/cache");
|
6
4
|
const react_disposable_state_1 = require("@isograph/react-disposable-state");
|
5
|
+
const cache_1 = require("../core/cache");
|
7
6
|
const logging_1 = require("../core/logging");
|
8
|
-
|
7
|
+
const IsographEnvironmentProvider_1 = require("./IsographEnvironmentProvider");
|
8
|
+
function useLazyReference(entrypoint, variables, ...[fetchOptions]) {
|
9
9
|
const environment = (0, IsographEnvironmentProvider_1.useIsographEnvironment)();
|
10
10
|
if ((entrypoint === null || entrypoint === void 0 ? void 0 : entrypoint.kind) !== 'Entrypoint') {
|
11
11
|
// TODO have a separate error logger
|
12
|
-
(0, logging_1.logMessage)(environment, {
|
12
|
+
(0, logging_1.logMessage)(environment, () => ({
|
13
13
|
kind: 'NonEntrypointReceived',
|
14
14
|
entrypoint,
|
15
|
-
});
|
15
|
+
}));
|
16
16
|
}
|
17
17
|
const cache = (0, cache_1.getOrCreateCacheForArtifact)(environment, entrypoint, variables, fetchOptions);
|
18
18
|
return {
|
19
19
|
fragmentReference: (0, react_disposable_state_1.useLazyDisposableState)(cache).state,
|
20
20
|
};
|
21
21
|
}
|
22
|
+
// @ts-ignore
|
23
|
+
function tsTests() {
|
24
|
+
let withAst;
|
25
|
+
let withAstLoader;
|
26
|
+
let withAstOrLoader;
|
27
|
+
useLazyReference(withAst, {});
|
28
|
+
useLazyReference(withAst, {}, { shouldFetch: 'Yes' });
|
29
|
+
useLazyReference(withAst, {}, { shouldFetch: 'IfNecessary' });
|
30
|
+
// @ts-expect-error if there's no ast, require `shouldFetch` to be specified
|
31
|
+
useLazyReference(withAstLoader, {});
|
32
|
+
useLazyReference(withAstLoader, {}, { shouldFetch: 'Yes' });
|
33
|
+
// @ts-expect-error if there's no ast, `shouldFetch` can't be `IfNecessary`
|
34
|
+
useLazyReference(withAstLoader, {}, { shouldFetch: 'IfNecessary' });
|
35
|
+
// if the type is unknown there can be no ast so we should use the same rules
|
36
|
+
// but because of TS bugs with inference we just return unknown
|
37
|
+
// @ts-expect-error this returns unknown which doesn't satisfy the constraint
|
38
|
+
useLazyReference(withAstOrLoader, {});
|
39
|
+
// @ts-expect-error this returns unknown which doesn't satisfy the constraint
|
40
|
+
useLazyReference(withAstOrLoader, {}, { shouldFetch: 'Yes' });
|
41
|
+
useLazyReference(withAstOrLoader, {}, { shouldFetch: 'IfNecessary' });
|
42
|
+
}
|
@@ -1,17 +1,11 @@
|
|
1
|
-
import { FragmentReference,
|
1
|
+
import { ExtractData, FragmentReference, type UnknownTReadFromStore } from '../core/FragmentReference';
|
2
2
|
import { NetworkRequestReaderOptions, WithEncounteredRecords } from '../core/read';
|
3
3
|
import type { ReaderAst } from '../core/reader';
|
4
4
|
/**
|
5
5
|
* Read the data from a fragment reference and subscribe to updates.
|
6
6
|
*/
|
7
|
-
export declare function useReadAndSubscribe<TReadFromStore extends
|
8
|
-
|
9
|
-
data: object;
|
10
|
-
}>(fragmentReference: FragmentReference<TReadFromStore, any>, networkRequestOptions: NetworkRequestReaderOptions, readerAst: ReaderAst<TReadFromStore>): ExtractData<TReadFromStore>;
|
11
|
-
export declare function useSubscribeToMultiple<TReadFromStore extends {
|
12
|
-
parameters: object;
|
13
|
-
data: object;
|
14
|
-
}>(items: ReadonlyArray<{
|
7
|
+
export declare function useReadAndSubscribe<TReadFromStore extends UnknownTReadFromStore>(fragmentReference: FragmentReference<TReadFromStore, any>, networkRequestOptions: NetworkRequestReaderOptions, readerAst: ReaderAst<TReadFromStore>): ExtractData<TReadFromStore>;
|
8
|
+
export declare function useSubscribeToMultiple<TReadFromStore extends UnknownTReadFromStore>(items: ReadonlyArray<{
|
15
9
|
records: WithEncounteredRecords<TReadFromStore>;
|
16
10
|
callback: (updatedRecords: WithEncounteredRecords<TReadFromStore>) => void;
|
17
11
|
fragmentReference: FragmentReference<TReadFromStore, any>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useReadAndSubscribe.d.ts","sourceRoot":"","sources":["../../src/react/useReadAndSubscribe.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"useReadAndSubscribe.d.ts","sourceRoot":"","sources":["../../src/react/useReadAndSubscribe.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,KAAK,qBAAqB,EAC3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,2BAA2B,EAE3B,sBAAsB,EACvB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,SAAS,qBAAqB,EAE5C,iBAAiB,EAAE,iBAAiB,CAAC,cAAc,EAAE,GAAG,CAAC,EACzD,qBAAqB,EAAE,2BAA2B,EAClD,SAAS,EAAE,SAAS,CAAC,cAAc,CAAC,GACnC,WAAW,CAAC,cAAc,CAAC,CAY7B;AAED,wBAAgB,sBAAsB,CACpC,cAAc,SAAS,qBAAqB,EAE5C,KAAK,EAAE,aAAa,CAAC;IACnB,OAAO,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;IAChD,QAAQ,EAAE,CAAC,cAAc,EAAE,sBAAsB,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;IAC3E,iBAAiB,EAAE,iBAAiB,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;IAC1D,SAAS,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;CACtC,CAAC,QAuCH"}
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useReadAndSubscribe = useReadAndSubscribe;
|
4
4
|
exports.useSubscribeToMultiple = useSubscribeToMultiple;
|
5
5
|
const react_1 = require("react");
|
6
|
+
const cache_1 = require("../core/cache");
|
6
7
|
const FragmentReference_1 = require("../core/FragmentReference");
|
8
|
+
const PromiseWrapper_1 = require("../core/PromiseWrapper");
|
7
9
|
const read_1 = require("../core/read");
|
8
|
-
const useRerenderOnChange_1 = require("./useRerenderOnChange");
|
9
10
|
const IsographEnvironmentProvider_1 = require("./IsographEnvironmentProvider");
|
10
|
-
const
|
11
|
+
const useRerenderOnChange_1 = require("./useRerenderOnChange");
|
11
12
|
/**
|
12
13
|
* Read the data from a fragment reference and subscribe to updates.
|
13
14
|
*/
|
@@ -34,7 +35,10 @@ function useSubscribeToMultiple(items) {
|
|
34
35
|
// TODO find out
|
35
36
|
[
|
36
37
|
items
|
37
|
-
.map(({ fragmentReference }) =>
|
38
|
+
.map(({ fragmentReference }) => {
|
39
|
+
const readerWithRefetchQueries = (0, PromiseWrapper_1.readPromise)(fragmentReference.readerWithRefetchQueries);
|
40
|
+
(0, FragmentReference_1.stableIdForFragmentReference)(fragmentReference, readerWithRefetchQueries.readerArtifact.fieldName);
|
41
|
+
})
|
38
42
|
.join('.'),
|
39
43
|
]);
|
40
44
|
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { WithEncounteredRecords } from '../core/read';
|
2
1
|
import { FragmentReference } from '../core/FragmentReference';
|
2
|
+
import { WithEncounteredRecords } from '../core/read';
|
3
3
|
import type { ReaderAst } from '../core/reader';
|
4
4
|
export declare function useRerenderOnChange<TReadFromStore extends {
|
5
5
|
parameters: object;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useRerenderOnChange.d.ts","sourceRoot":"","sources":["../../src/react/useRerenderOnChange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"useRerenderOnChange.d.ts","sourceRoot":"","sources":["../../src/react/useRerenderOnChange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKhD,wBAAgB,mBAAmB,CACjC,cAAc,SAAS;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAE3D,yBAAyB,EAAE,sBAAsB,CAAC,cAAc,CAAC,EACjE,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,EAC9C,4BAA4B,EAAE,CAC5B,IAAI,EAAE,sBAAsB,CAAC,cAAc,CAAC,KACzC,IAAI,EACT,SAAS,EAAE,SAAS,CAAC,cAAc,CAAC,QAoBrC"}
|
@@ -1,9 +1,6 @@
|
|
1
|
-
import { FragmentReference } from '../core/FragmentReference';
|
2
|
-
import { NetworkRequestReaderOptions } from '../core/read';
|
1
|
+
import { FragmentReference, type UnknownTReadFromStore } from '../core/FragmentReference';
|
3
2
|
import { PromiseWrapper } from '../core/PromiseWrapper';
|
4
|
-
|
5
|
-
|
6
|
-
data: object;
|
7
|
-
}, TClientFieldValue>(fragmentReference: FragmentReference<TReadFromStore, TClientFieldValue>, partialNetworkRequestOptions?: Partial<NetworkRequestReaderOptions> | void): TClientFieldValue;
|
3
|
+
import { NetworkRequestReaderOptions } from '../core/read';
|
4
|
+
export declare function useResult<TReadFromStore extends UnknownTReadFromStore, TClientFieldValue>(fragmentReference: FragmentReference<TReadFromStore, TClientFieldValue>, partialNetworkRequestOptions?: Partial<NetworkRequestReaderOptions> | void): TClientFieldValue;
|
8
5
|
export declare function maybeUnwrapNetworkRequest(networkRequest: PromiseWrapper<void, any>, networkRequestOptions: NetworkRequestReaderOptions): void;
|
9
6
|
//# sourceMappingURL=useResult.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useResult.d.ts","sourceRoot":"","sources":["../../src/react/useResult.ts"],"names":[],"mappings":"AACA,OAAO,
|
1
|
+
{"version":3,"file":"useResult.d.ts","sourceRoot":"","sources":["../../src/react/useResult.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,KAAK,qBAAqB,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,cAAc,EAEf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AAKtB,wBAAgB,SAAS,CACvB,cAAc,SAAS,qBAAqB,EAC5C,iBAAiB,EAEjB,iBAAiB,EAAE,iBAAiB,CAAC,cAAc,EAAE,iBAAiB,CAAC,EACvE,4BAA4B,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,GAAG,IAAI,GACzE,iBAAiB,CA8CnB;AAED,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,EACzC,qBAAqB,EAAE,2BAA2B,QAWnD"}
|
package/dist/react/useResult.js
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.useResult = useResult;
|
4
4
|
exports.maybeUnwrapNetworkRequest = maybeUnwrapNetworkRequest;
|
5
|
-
const IsographEnvironmentProvider_1 = require("../react/IsographEnvironmentProvider");
|
6
5
|
const componentCache_1 = require("../core/componentCache");
|
7
|
-
const useReadAndSubscribe_1 = require("./useReadAndSubscribe");
|
8
|
-
const read_1 = require("../core/read");
|
9
6
|
const PromiseWrapper_1 = require("../core/PromiseWrapper");
|
7
|
+
const read_1 = require("../core/read");
|
8
|
+
const startUpdate_1 = require("../core/startUpdate");
|
9
|
+
const IsographEnvironmentProvider_1 = require("../react/IsographEnvironmentProvider");
|
10
|
+
const useReadAndSubscribe_1 = require("./useReadAndSubscribe");
|
10
11
|
function useResult(fragmentReference, partialNetworkRequestOptions) {
|
11
12
|
const environment = (0, IsographEnvironmentProvider_1.useIsographEnvironment)();
|
12
13
|
const networkRequestOptions = (0, read_1.getNetworkRequestOptionsWithDefaults)(partialNetworkRequestOptions);
|
@@ -15,14 +16,15 @@ function useResult(fragmentReference, partialNetworkRequestOptions) {
|
|
15
16
|
switch (readerWithRefetchQueries.readerArtifact.kind) {
|
16
17
|
case 'ComponentReaderArtifact': {
|
17
18
|
// @ts-expect-error
|
18
|
-
return (0, componentCache_1.getOrCreateCachedComponent)(environment, readerWithRefetchQueries.readerArtifact.
|
19
|
+
return (0, componentCache_1.getOrCreateCachedComponent)(environment, readerWithRefetchQueries.readerArtifact.fieldName, fragmentReference, networkRequestOptions);
|
19
20
|
}
|
20
21
|
case 'EagerReaderArtifact': {
|
21
22
|
const data = (0, useReadAndSubscribe_1.useReadAndSubscribe)(fragmentReference, networkRequestOptions, readerWithRefetchQueries.readerArtifact.readerAst);
|
22
|
-
const param = {
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
const param = Object.assign({ data: data, parameters: fragmentReference.variables }, (readerWithRefetchQueries.readerArtifact.hasUpdatable
|
24
|
+
? {
|
25
|
+
startUpdate: (0, startUpdate_1.getOrCreateCachedStartUpdate)(environment, fragmentReference, readerWithRefetchQueries.readerArtifact.fieldName),
|
26
|
+
}
|
27
|
+
: undefined));
|
26
28
|
return readerWithRefetchQueries.readerArtifact.resolver(param);
|
27
29
|
}
|
28
30
|
}
|
package/isograph.config.json
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@isograph/react",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.1",
|
4
4
|
"description": "Use Isograph with React",
|
5
5
|
"homepage": "https://isograph.dev",
|
6
6
|
"main": "dist/index.js",
|
@@ -8,15 +8,16 @@
|
|
8
8
|
"author": "Isograph Labs",
|
9
9
|
"license": "MIT",
|
10
10
|
"scripts": {
|
11
|
-
"compile": "rm -rf dist/* && tsc -p tsconfig.pkg.json",
|
11
|
+
"compile-typescript": "rm -rf dist/* && tsc -p tsconfig.pkg.json",
|
12
12
|
"compile-watch": "tsc -p tsconfig.pkg.json --watch",
|
13
13
|
"test": "vitest run",
|
14
14
|
"test-watch": "vitest watch",
|
15
15
|
"coverage": "vitest run --coverage",
|
16
|
-
"prepack": "pnpm run test && pnpm run compile",
|
16
|
+
"prepack": "pnpm run test && pnpm run compile-typescript",
|
17
17
|
"tsc": "tsc",
|
18
|
-
"
|
19
|
-
"iso
|
18
|
+
"tsc-force": "tsc --build --clean && tsc --build --force",
|
19
|
+
"iso": "cross-env ../../target/debug/isograph_cli --config ./isograph.config.json",
|
20
|
+
"iso-watch": "cross-env ../../target/debug/isograph_cli --config ./isograph.config.json --watch"
|
20
21
|
},
|
21
22
|
"dependencies": {
|
22
23
|
"@isograph/disposable-types": "*",
|
@@ -24,7 +25,7 @@
|
|
24
25
|
"@isograph/reference-counted-pointer": "*"
|
25
26
|
},
|
26
27
|
"peerDependencies": {
|
27
|
-
"react": "18.
|
28
|
+
"react": "^18.0.0 || ^19.0.0"
|
28
29
|
},
|
29
30
|
"devDependencies": {
|
30
31
|
"@babel/preset-typescript": "^7.24.7",
|
@@ -1,12 +1,28 @@
|
|
1
|
-
import { type Link } from './IsographEnvironment';
|
2
1
|
import { ReaderWithRefetchQueries } from '../core/entrypoint';
|
2
|
+
import { stableCopy } from './cache';
|
3
|
+
import { type Link } from './IsographEnvironment';
|
3
4
|
import { PromiseWrapper } from './PromiseWrapper';
|
5
|
+
import type { StartUpdate } from './reader';
|
4
6
|
|
5
7
|
// TODO type this better
|
6
|
-
export type VariableValue =
|
8
|
+
export type VariableValue =
|
9
|
+
| string
|
10
|
+
| number
|
11
|
+
| boolean
|
12
|
+
| null
|
13
|
+
| {
|
14
|
+
readonly [index: string]: VariableValue;
|
15
|
+
}
|
16
|
+
| VariableValue[];
|
7
17
|
|
8
18
|
export type Variables = { readonly [index: string]: VariableValue };
|
9
19
|
|
20
|
+
export type UnknownTReadFromStore = {
|
21
|
+
parameters: object;
|
22
|
+
data: object;
|
23
|
+
startUpdate?: StartUpdate<object>;
|
24
|
+
};
|
25
|
+
|
10
26
|
export type ExtractData<T> = T extends {
|
11
27
|
data: infer D extends object;
|
12
28
|
}
|
@@ -19,8 +35,14 @@ export type ExtractParameters<T> = T extends {
|
|
19
35
|
? P
|
20
36
|
: Variables;
|
21
37
|
|
38
|
+
export type ExtractStartUpdate<
|
39
|
+
T extends {
|
40
|
+
startUpdate?: StartUpdate<object>;
|
41
|
+
},
|
42
|
+
> = T['startUpdate'];
|
43
|
+
|
22
44
|
export type FragmentReference<
|
23
|
-
TReadFromStore extends
|
45
|
+
TReadFromStore extends UnknownTReadFromStore,
|
24
46
|
TClientFieldValue,
|
25
47
|
> = {
|
26
48
|
readonly kind: 'FragmentReference';
|
@@ -32,18 +54,11 @@ export type FragmentReference<
|
|
32
54
|
readonly networkRequest: PromiseWrapper<void, any>;
|
33
55
|
};
|
34
56
|
|
57
|
+
export type StableIdForFragmentReference = string;
|
58
|
+
|
35
59
|
export function stableIdForFragmentReference(
|
36
60
|
fragmentReference: FragmentReference<any, any>,
|
37
|
-
|
38
|
-
|
39
|
-
}
|
40
|
-
|
41
|
-
function serializeVariables(variables: Variables) {
|
42
|
-
let s = '';
|
43
|
-
const keys = Object.keys(variables);
|
44
|
-
keys.sort();
|
45
|
-
for (const key of keys) {
|
46
|
-
s += `${key}:${variables[key]},`;
|
47
|
-
}
|
48
|
-
return s;
|
61
|
+
fieldName: string,
|
62
|
+
): StableIdForFragmentReference {
|
63
|
+
return `${fragmentReference.root.__typename}/${fragmentReference.root.__link}/${fieldName}/${JSON.stringify(stableCopy(fragmentReference.variables))}`;
|
49
64
|
}
|
@@ -1,57 +1,61 @@
|
|
1
1
|
import { ParentCache } from '@isograph/react-disposable-state';
|
2
|
-
import { RetainedQuery } from './garbageCollection';
|
3
|
-
import { WithEncounteredRecords } from './read';
|
4
|
-
import { FragmentReference, Variables } from './FragmentReference';
|
5
|
-
import { PromiseWrapper, wrapPromise } from './PromiseWrapper';
|
6
2
|
import { IsographEntrypoint } from './entrypoint';
|
7
|
-
import
|
3
|
+
import {
|
4
|
+
FragmentReference,
|
5
|
+
Variables,
|
6
|
+
type StableIdForFragmentReference,
|
7
|
+
type UnknownTReadFromStore,
|
8
|
+
} from './FragmentReference';
|
9
|
+
import { RetainedQuery } from './garbageCollection';
|
8
10
|
import { LogFunction, WrappedLogFunction } from './logging';
|
11
|
+
import { PromiseWrapper, wrapPromise } from './PromiseWrapper';
|
12
|
+
import { WithEncounteredRecords } from './read';
|
13
|
+
import type { ReaderAst, StartUpdate } from './reader';
|
9
14
|
|
10
15
|
export type ComponentOrFieldName = string;
|
11
16
|
export type StringifiedArgs = string;
|
12
|
-
type ComponentCache = {
|
13
|
-
[key: DataId]: {
|
14
|
-
[key: ComponentOrFieldName]: { [key: StringifiedArgs]: React.FC<any> };
|
15
|
-
};
|
16
|
-
};
|
17
17
|
|
18
|
-
export type
|
19
|
-
|
20
|
-
> = {
|
21
|
-
readonly kind: 'FragmentSubscription';
|
22
|
-
readonly callback: (
|
23
|
-
newEncounteredDataAndRecords: WithEncounteredRecords<TReadFromStore>,
|
24
|
-
) => void;
|
25
|
-
/** The value read out from the previous call to readButDoNotEvaluate */
|
26
|
-
readonly encounteredDataAndRecords: WithEncounteredRecords<TReadFromStore>;
|
27
|
-
readonly fragmentReference: FragmentReference<TReadFromStore, any>;
|
28
|
-
readonly readerAst: ReaderAst<TReadFromStore>;
|
18
|
+
export type FieldCache<T> = {
|
19
|
+
[key: StableIdForFragmentReference]: T;
|
29
20
|
};
|
30
21
|
|
31
|
-
type
|
22
|
+
export type FragmentSubscription<TReadFromStore extends UnknownTReadFromStore> =
|
23
|
+
{
|
24
|
+
readonly kind: 'FragmentSubscription';
|
25
|
+
readonly callback: (
|
26
|
+
newEncounteredDataAndRecords: WithEncounteredRecords<TReadFromStore>,
|
27
|
+
) => void;
|
28
|
+
/** The value read out from the previous call to readButDoNotEvaluate */
|
29
|
+
readonly encounteredDataAndRecords: WithEncounteredRecords<TReadFromStore>;
|
30
|
+
readonly fragmentReference: FragmentReference<TReadFromStore, any>;
|
31
|
+
readonly readerAst: ReaderAst<TReadFromStore>;
|
32
|
+
};
|
33
|
+
|
34
|
+
export type AnyChangesToRecordSubscription = {
|
32
35
|
readonly kind: 'AnyChangesToRecord';
|
33
36
|
readonly callback: () => void;
|
34
37
|
readonly recordLink: Link;
|
35
38
|
};
|
36
39
|
|
37
|
-
type AnyRecordSubscription = {
|
40
|
+
export type AnyRecordSubscription = {
|
38
41
|
readonly kind: 'AnyRecords';
|
39
42
|
readonly callback: () => void;
|
40
43
|
};
|
41
44
|
|
42
|
-
type Subscription =
|
43
|
-
| FragmentSubscription<
|
45
|
+
export type Subscription =
|
46
|
+
| FragmentSubscription<any>
|
44
47
|
| AnyChangesToRecordSubscription
|
45
48
|
| AnyRecordSubscription;
|
46
|
-
type Subscriptions = Set<Subscription>;
|
49
|
+
export type Subscriptions = Set<Subscription>;
|
47
50
|
// Should this be a map?
|
48
|
-
type CacheMap<T> = { [index: string]: ParentCache<T> };
|
51
|
+
export type CacheMap<T> = { [index: string]: ParentCache<T> };
|
49
52
|
|
50
53
|
export type IsographEnvironment = {
|
51
54
|
readonly store: IsographStore;
|
52
55
|
readonly networkFunction: IsographNetworkFunction;
|
53
56
|
readonly missingFieldHandler: MissingFieldHandler | null;
|
54
|
-
readonly componentCache:
|
57
|
+
readonly componentCache: FieldCache<React.FC<any>>;
|
58
|
+
readonly eagerReaderCache: FieldCache<StartUpdate<any> | undefined>;
|
55
59
|
readonly subscriptions: Subscriptions;
|
56
60
|
// N.B. this must be <any, any>, but all *usages* of this should go through
|
57
61
|
// a function that adds type parameters.
|
@@ -59,7 +63,7 @@ export type IsographEnvironment = {
|
|
59
63
|
// TODO make this a CacheMap and add GC
|
60
64
|
readonly entrypointArtifactCache: Map<
|
61
65
|
string,
|
62
|
-
PromiseWrapper<IsographEntrypoint<any, any>>
|
66
|
+
PromiseWrapper<IsographEntrypoint<any, any, any>>
|
63
67
|
>;
|
64
68
|
readonly retainedQueries: Set<RetainedQuery>;
|
65
69
|
readonly gcBuffer: Array<RetainedQuery>;
|
@@ -127,11 +131,15 @@ export function createIsographEnvironment(
|
|
127
131
|
missingFieldHandler?: MissingFieldHandler | null,
|
128
132
|
logFunction?: LogFunction | null,
|
129
133
|
): IsographEnvironment {
|
134
|
+
logFunction?.({
|
135
|
+
kind: 'EnvironmentCreated',
|
136
|
+
});
|
130
137
|
return {
|
131
138
|
store,
|
132
139
|
networkFunction,
|
133
140
|
missingFieldHandler: missingFieldHandler ?? null,
|
134
141
|
componentCache: {},
|
142
|
+
eagerReaderCache: {},
|
135
143
|
subscriptions: new Set(),
|
136
144
|
fragmentCache: {},
|
137
145
|
entrypointArtifactCache: new Map(),
|
@@ -180,8 +188,8 @@ export function getLink(maybeLink: DataTypeValue): Link | null {
|
|
180
188
|
export function getOrLoadIsographArtifact(
|
181
189
|
environment: IsographEnvironment,
|
182
190
|
key: string,
|
183
|
-
loader: () => Promise<IsographEntrypoint<any, any>>,
|
184
|
-
): PromiseWrapper<IsographEntrypoint<any, any>> {
|
191
|
+
loader: () => Promise<IsographEntrypoint<any, any, any>>,
|
192
|
+
): PromiseWrapper<IsographEntrypoint<any, any, any>> {
|
185
193
|
const value = environment.entrypointArtifactCache.get(key);
|
186
194
|
if (value != null) {
|
187
195
|
return value;
|
@@ -1,9 +1,9 @@
|
|
1
1
|
export type AnyError = any;
|
2
2
|
|
3
|
-
const NOT_SET: Symbol = Symbol('NOT_SET');
|
4
|
-
type NotSet = typeof NOT_SET;
|
3
|
+
export const NOT_SET: Symbol = Symbol('NOT_SET');
|
4
|
+
export type NotSet = typeof NOT_SET;
|
5
5
|
|
6
|
-
type Result<T, E> =
|
6
|
+
export type Result<T, E> =
|
7
7
|
| {
|
8
8
|
kind: 'Ok';
|
9
9
|
value: T;
|
@@ -1,4 +1,6 @@
|
|
1
|
+
import type { Link } from './IsographEnvironment';
|
1
2
|
import type { ReaderAst, ReaderLinkedField, ReaderScalarField } from './reader';
|
3
|
+
|
2
4
|
export function mergeUsingReaderAst(
|
3
5
|
field: ReaderScalarField | ReaderLinkedField,
|
4
6
|
oldItem: unknown,
|
@@ -96,6 +98,24 @@ export function mergeObjectsUsingReaderAst(
|
|
96
98
|
}
|
97
99
|
break;
|
98
100
|
}
|
101
|
+
case 'Link': {
|
102
|
+
const key = field.alias;
|
103
|
+
// @ts-expect-error
|
104
|
+
const oldValue: Link = oldItemObject[key];
|
105
|
+
// @ts-expect-error
|
106
|
+
const newValue: Link = newItemObject[key];
|
107
|
+
|
108
|
+
if (
|
109
|
+
oldValue.__link !== newValue.__link ||
|
110
|
+
oldValue.__typename !== newValue.__typename
|
111
|
+
) {
|
112
|
+
canRecycle = false;
|
113
|
+
} else {
|
114
|
+
// @ts-expect-error
|
115
|
+
newItemObject[key] = oldValue;
|
116
|
+
}
|
117
|
+
break;
|
118
|
+
}
|
99
119
|
case 'ImperativelyLoadedField':
|
100
120
|
case 'LoadablySelectedField':
|
101
121
|
break;
|