@isograph/react 0.2.0 → 0.3.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/dist/core/FragmentReference.d.ts +14 -4
- package/dist/core/FragmentReference.d.ts.map +1 -0
- package/dist/core/FragmentReference.js +2 -3
- package/dist/core/IsographEnvironment.d.ts +28 -10
- package/dist/core/IsographEnvironment.d.ts.map +1 -0
- package/dist/core/IsographEnvironment.js +15 -22
- package/dist/core/PromiseWrapper.d.ts +1 -0
- package/dist/core/PromiseWrapper.d.ts.map +1 -0
- package/dist/core/PromiseWrapper.js +4 -5
- package/dist/core/areEqualWithDeepComparison.d.ts +5 -3
- package/dist/core/areEqualWithDeepComparison.d.ts.map +1 -0
- package/dist/core/areEqualWithDeepComparison.js +73 -39
- package/dist/core/cache.d.ts +26 -10
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js +160 -98
- package/dist/core/check.d.ts +18 -0
- package/dist/core/check.d.ts.map +1 -0
- package/dist/core/check.js +127 -0
- package/dist/core/componentCache.d.ts +1 -1
- package/dist/core/componentCache.d.ts.map +1 -0
- package/dist/core/componentCache.js +14 -14
- package/dist/core/entrypoint.d.ts +27 -8
- package/dist/core/entrypoint.d.ts.map +1 -0
- package/dist/core/entrypoint.js +1 -2
- package/dist/core/garbageCollection.d.ts +3 -1
- package/dist/core/garbageCollection.d.ts.map +1 -0
- package/dist/core/garbageCollection.js +48 -15
- package/dist/core/logging.d.ts +69 -0
- package/dist/core/logging.d.ts.map +1 -0
- package/dist/core/logging.js +19 -0
- package/dist/core/makeNetworkRequest.d.ts +4 -1
- package/dist/core/makeNetworkRequest.d.ts.map +1 -0
- package/dist/core/makeNetworkRequest.js +71 -15
- package/dist/core/read.d.ts +20 -5
- package/dist/core/read.d.ts.map +1 -0
- package/dist/core/read.js +104 -41
- package/dist/core/reader.d.ts +34 -10
- package/dist/core/reader.d.ts.map +1 -0
- package/dist/core/util.d.ts +2 -0
- package/dist/core/util.d.ts.map +1 -0
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -2
- package/dist/loadable-hooks/useClientSideDefer.d.ts +15 -3
- package/dist/loadable-hooks/useClientSideDefer.d.ts.map +1 -0
- package/dist/loadable-hooks/useClientSideDefer.js +4 -6
- package/dist/loadable-hooks/useConnectionSpecPagination.d.ts +34 -0
- package/dist/loadable-hooks/useConnectionSpecPagination.d.ts.map +1 -0
- package/dist/loadable-hooks/useConnectionSpecPagination.js +160 -0
- package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts +1 -0
- package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts.map +1 -0
- package/dist/loadable-hooks/useImperativeExposedMutationField.js +1 -2
- package/dist/loadable-hooks/useImperativeLoadableField.d.ts +13 -5
- package/dist/loadable-hooks/useImperativeLoadableField.d.ts.map +1 -0
- package/dist/loadable-hooks/useImperativeLoadableField.js +3 -4
- package/dist/loadable-hooks/useSkipLimitPagination.d.ts +18 -24
- package/dist/loadable-hooks/useSkipLimitPagination.d.ts.map +1 -0
- package/dist/loadable-hooks/useSkipLimitPagination.js +88 -44
- package/dist/react/FragmentReader.d.ts +7 -4
- package/dist/react/FragmentReader.d.ts.map +1 -0
- package/dist/react/FragmentReader.js +4 -2
- package/dist/react/IsographEnvironmentProvider.d.ts +1 -0
- package/dist/react/IsographEnvironmentProvider.d.ts.map +1 -0
- package/dist/react/IsographEnvironmentProvider.js +3 -3
- package/dist/react/RenderAfterCommit__DO_NOT_USE.d.ts +10 -0
- package/dist/react/RenderAfterCommit__DO_NOT_USE.d.ts.map +1 -0
- package/dist/react/RenderAfterCommit__DO_NOT_USE.js +15 -0
- package/dist/react/useImperativeReference.d.ts +8 -3
- package/dist/react/useImperativeReference.d.ts.map +1 -0
- package/dist/react/useImperativeReference.js +4 -5
- package/dist/react/useLazyReference.d.ts +7 -2
- package/dist/react/useLazyReference.d.ts.map +1 -0
- package/dist/react/useLazyReference.js +11 -4
- package/dist/react/useReadAndSubscribe.d.ts +12 -3
- package/dist/react/useReadAndSubscribe.d.ts.map +1 -0
- package/dist/react/useReadAndSubscribe.js +6 -7
- package/dist/react/useRerenderOnChange.d.ts +6 -1
- package/dist/react/useRerenderOnChange.d.ts.map +1 -0
- package/dist/react/useRerenderOnChange.js +3 -4
- package/dist/react/useResult.d.ts +5 -1
- package/dist/react/useResult.d.ts.map +1 -0
- package/dist/react/useResult.js +8 -5
- package/{src/tests/isograph.config.json → isograph.config.json} +1 -1
- package/package.json +12 -8
- package/{src/tests/schema.graphql → schema.graphql} +1 -0
- package/src/core/FragmentReference.ts +17 -5
- package/src/core/IsographEnvironment.ts +38 -29
- package/src/core/areEqualWithDeepComparison.ts +76 -42
- package/src/core/cache.ts +237 -123
- package/src/core/check.ts +207 -0
- package/src/core/componentCache.ts +18 -17
- package/src/core/entrypoint.ts +15 -8
- package/src/core/garbageCollection.ts +71 -20
- package/src/core/logging.ts +116 -0
- package/src/core/makeNetworkRequest.ts +89 -13
- package/src/core/read.ts +162 -55
- package/src/core/reader.ts +40 -13
- package/src/core/util.ts +4 -0
- package/src/index.ts +14 -1
- package/src/loadable-hooks/useClientSideDefer.ts +45 -15
- package/src/loadable-hooks/useConnectionSpecPagination.ts +331 -0
- package/src/loadable-hooks/useImperativeLoadableField.ts +36 -10
- package/src/loadable-hooks/useSkipLimitPagination.ts +231 -90
- package/src/react/FragmentReader.tsx +13 -4
- package/src/react/RenderAfterCommit__DO_NOT_USE.tsx +17 -0
- package/src/react/useImperativeReference.ts +18 -7
- package/src/react/useLazyReference.ts +24 -4
- package/src/react/useReadAndSubscribe.ts +20 -5
- package/src/react/useRerenderOnChange.ts +6 -1
- package/src/react/useResult.ts +10 -2
- package/src/tests/__isograph/Query/meName/entrypoint.ts +7 -2
- package/src/tests/__isograph/Query/meName/param_type.ts +5 -2
- package/src/tests/__isograph/Query/meName/resolver_reader.ts +1 -0
- package/src/tests/__isograph/Query/meNameSuccessor/entrypoint.ts +9 -2
- package/src/tests/__isograph/Query/meNameSuccessor/param_type.ts +9 -6
- package/src/tests/__isograph/Query/meNameSuccessor/resolver_reader.ts +3 -0
- package/src/tests/__isograph/Query/nodeField/entrypoint.ts +13 -2
- package/src/tests/__isograph/Query/nodeField/param_type.ts +7 -3
- package/src/tests/__isograph/Query/nodeField/parameters_type.ts +3 -0
- package/src/tests/__isograph/Query/nodeField/resolver_reader.ts +1 -0
- package/src/tests/__isograph/Query/subquery/entrypoint.ts +67 -0
- package/src/tests/__isograph/Query/subquery/output_type.ts +3 -0
- package/src/tests/__isograph/Query/subquery/param_type.ts +12 -0
- package/src/tests/__isograph/Query/subquery/parameters_type.ts +3 -0
- package/src/tests/__isograph/Query/subquery/resolver_reader.ts +47 -0
- package/src/tests/__isograph/iso.ts +22 -11
- package/src/tests/garbageCollection.test.ts +45 -39
- package/src/tests/meNameSuccessor.ts +8 -3
- package/src/tests/nodeQuery.ts +6 -4
- package/src/tests/normalizeData.test.ts +120 -0
- package/src/tests/tsconfig.json +3 -3
- package/tsconfig.json +2 -2
- package/tsconfig.pkg.json +6 -1
- package/vitest.config.ts +20 -0
package/src/react/useResult.ts
CHANGED
@@ -12,7 +12,10 @@ import {
|
|
12
12
|
readPromise,
|
13
13
|
} from '../core/PromiseWrapper';
|
14
14
|
|
15
|
-
export function useResult<
|
15
|
+
export function useResult<
|
16
|
+
TReadFromStore extends { parameters: object; data: object },
|
17
|
+
TClientFieldValue,
|
18
|
+
>(
|
16
19
|
fragmentReference: FragmentReference<TReadFromStore, TClientFieldValue>,
|
17
20
|
partialNetworkRequestOptions?: Partial<NetworkRequestReaderOptions> | void,
|
18
21
|
): TClientFieldValue {
|
@@ -43,8 +46,13 @@ export function useResult<TReadFromStore extends Object, TClientFieldValue>(
|
|
43
46
|
const data = useReadAndSubscribe(
|
44
47
|
fragmentReference,
|
45
48
|
networkRequestOptions,
|
49
|
+
readerWithRefetchQueries.readerArtifact.readerAst,
|
46
50
|
);
|
47
|
-
|
51
|
+
const param = {
|
52
|
+
data: data,
|
53
|
+
parameters: fragmentReference.variables,
|
54
|
+
};
|
55
|
+
return readerWithRefetchQueries.readerArtifact.resolver(param);
|
48
56
|
}
|
49
57
|
}
|
50
58
|
}
|
@@ -16,6 +16,7 @@ const normalizationAst: NormalizationAst = [
|
|
16
16
|
kind: "Linked",
|
17
17
|
fieldName: "me",
|
18
18
|
arguments: null,
|
19
|
+
concreteType: "Economist",
|
19
20
|
selections: [
|
20
21
|
{
|
21
22
|
kind: "Scalar",
|
@@ -35,8 +36,12 @@ const artifact: IsographEntrypoint<
|
|
35
36
|
Query__meName__output_type
|
36
37
|
> = {
|
37
38
|
kind: "Entrypoint",
|
38
|
-
|
39
|
-
|
39
|
+
networkRequestInfo: {
|
40
|
+
kind: "NetworkRequestInfo",
|
41
|
+
queryText,
|
42
|
+
normalizationAst,
|
43
|
+
},
|
44
|
+
concreteType: "Query",
|
40
45
|
readerWithRefetchQueries: {
|
41
46
|
kind: "ReaderWithRefetchQueries",
|
42
47
|
nestedRefetchQueries,
|
@@ -23,6 +23,7 @@ const normalizationAst: NormalizationAst = [
|
|
23
23
|
kind: "Linked",
|
24
24
|
fieldName: "me",
|
25
25
|
arguments: null,
|
26
|
+
concreteType: "Economist",
|
26
27
|
selections: [
|
27
28
|
{
|
28
29
|
kind: "Scalar",
|
@@ -38,6 +39,7 @@ const normalizationAst: NormalizationAst = [
|
|
38
39
|
kind: "Linked",
|
39
40
|
fieldName: "successor",
|
40
41
|
arguments: null,
|
42
|
+
concreteType: "Economist",
|
41
43
|
selections: [
|
42
44
|
{
|
43
45
|
kind: "Scalar",
|
@@ -48,6 +50,7 @@ const normalizationAst: NormalizationAst = [
|
|
48
50
|
kind: "Linked",
|
49
51
|
fieldName: "successor",
|
50
52
|
arguments: null,
|
53
|
+
concreteType: "Economist",
|
51
54
|
selections: [
|
52
55
|
{
|
53
56
|
kind: "Scalar",
|
@@ -71,8 +74,12 @@ const artifact: IsographEntrypoint<
|
|
71
74
|
Query__meNameSuccessor__output_type
|
72
75
|
> = {
|
73
76
|
kind: "Entrypoint",
|
74
|
-
|
75
|
-
|
77
|
+
networkRequestInfo: {
|
78
|
+
kind: "NetworkRequestInfo",
|
79
|
+
queryText,
|
80
|
+
normalizationAst,
|
81
|
+
},
|
82
|
+
concreteType: "Query",
|
76
83
|
readerWithRefetchQueries: {
|
77
84
|
kind: "ReaderWithRefetchQueries",
|
78
85
|
nestedRefetchQueries,
|
@@ -1,11 +1,14 @@
|
|
1
1
|
|
2
2
|
export type Query__meNameSuccessor__param = {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
successor: ({
|
7
|
-
|
3
|
+
readonly data: {
|
4
|
+
readonly me: {
|
5
|
+
readonly name: string,
|
6
|
+
readonly successor: ({
|
7
|
+
readonly successor: ({
|
8
|
+
readonly name: string,
|
9
|
+
} | null),
|
8
10
|
} | null),
|
9
|
-
}
|
11
|
+
},
|
10
12
|
},
|
13
|
+
readonly parameters: Record<PropertyKey, never>,
|
11
14
|
};
|
@@ -9,6 +9,7 @@ const readerAst: ReaderAst<Query__meNameSuccessor__param> = [
|
|
9
9
|
fieldName: "me",
|
10
10
|
alias: null,
|
11
11
|
arguments: null,
|
12
|
+
condition: null,
|
12
13
|
selections: [
|
13
14
|
{
|
14
15
|
kind: "Scalar",
|
@@ -21,12 +22,14 @@ const readerAst: ReaderAst<Query__meNameSuccessor__param> = [
|
|
21
22
|
fieldName: "successor",
|
22
23
|
alias: null,
|
23
24
|
arguments: null,
|
25
|
+
condition: null,
|
24
26
|
selections: [
|
25
27
|
{
|
26
28
|
kind: "Linked",
|
27
29
|
fieldName: "successor",
|
28
30
|
alias: null,
|
29
31
|
arguments: null,
|
32
|
+
condition: null,
|
30
33
|
selections: [
|
31
34
|
{
|
32
35
|
kind: "Scalar",
|
@@ -6,6 +6,7 @@ const nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[] = [];
|
|
6
6
|
|
7
7
|
const queryText = 'query nodeField ($id: ID!) {\
|
8
8
|
node____id___v_id: node(id: $id) {\
|
9
|
+
__typename,\
|
9
10
|
id,\
|
10
11
|
},\
|
11
12
|
}';
|
@@ -20,7 +21,13 @@ const normalizationAst: NormalizationAst = [
|
|
20
21
|
{ kind: "Variable", name: "id" },
|
21
22
|
],
|
22
23
|
],
|
24
|
+
concreteType: null,
|
23
25
|
selections: [
|
26
|
+
{
|
27
|
+
kind: "Scalar",
|
28
|
+
fieldName: "__typename",
|
29
|
+
arguments: null,
|
30
|
+
},
|
24
31
|
{
|
25
32
|
kind: "Scalar",
|
26
33
|
fieldName: "id",
|
@@ -34,8 +41,12 @@ const artifact: IsographEntrypoint<
|
|
34
41
|
Query__nodeField__output_type
|
35
42
|
> = {
|
36
43
|
kind: "Entrypoint",
|
37
|
-
|
38
|
-
|
44
|
+
networkRequestInfo: {
|
45
|
+
kind: "NetworkRequestInfo",
|
46
|
+
queryText,
|
47
|
+
normalizationAst,
|
48
|
+
},
|
49
|
+
concreteType: "Query",
|
39
50
|
readerWithRefetchQueries: {
|
40
51
|
kind: "ReaderWithRefetchQueries",
|
41
52
|
nestedRefetchQueries,
|
@@ -1,6 +1,10 @@
|
|
1
|
+
import type { Query__nodeField__parameters } from './parameters_type';
|
1
2
|
|
2
3
|
export type Query__nodeField__param = {
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
readonly data: {
|
5
|
+
readonly node: ({
|
6
|
+
readonly id: string,
|
7
|
+
} | null),
|
8
|
+
},
|
9
|
+
readonly parameters: Query__nodeField__parameters,
|
6
10
|
};
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import type {IsographEntrypoint, NormalizationAst, RefetchQueryNormalizationArtifactWrapper} from '@isograph/react';
|
2
|
+
import {Query__subquery__param} from './param_type';
|
3
|
+
import {Query__subquery__output_type} from './output_type';
|
4
|
+
import readerResolver from './resolver_reader';
|
5
|
+
const nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[] = [];
|
6
|
+
|
7
|
+
const queryText = 'query subquery ($id: ID!) {\
|
8
|
+
query {\
|
9
|
+
node____id___v_id: node(id: $id) {\
|
10
|
+
__typename,\
|
11
|
+
id,\
|
12
|
+
},\
|
13
|
+
},\
|
14
|
+
}';
|
15
|
+
|
16
|
+
const normalizationAst: NormalizationAst = [
|
17
|
+
{
|
18
|
+
kind: "Linked",
|
19
|
+
fieldName: "query",
|
20
|
+
arguments: null,
|
21
|
+
concreteType: "Query",
|
22
|
+
selections: [
|
23
|
+
{
|
24
|
+
kind: "Linked",
|
25
|
+
fieldName: "node",
|
26
|
+
arguments: [
|
27
|
+
[
|
28
|
+
"id",
|
29
|
+
{ kind: "Variable", name: "id" },
|
30
|
+
],
|
31
|
+
],
|
32
|
+
concreteType: null,
|
33
|
+
selections: [
|
34
|
+
{
|
35
|
+
kind: "Scalar",
|
36
|
+
fieldName: "__typename",
|
37
|
+
arguments: null,
|
38
|
+
},
|
39
|
+
{
|
40
|
+
kind: "Scalar",
|
41
|
+
fieldName: "id",
|
42
|
+
arguments: null,
|
43
|
+
},
|
44
|
+
],
|
45
|
+
},
|
46
|
+
],
|
47
|
+
},
|
48
|
+
];
|
49
|
+
const artifact: IsographEntrypoint<
|
50
|
+
Query__subquery__param,
|
51
|
+
Query__subquery__output_type
|
52
|
+
> = {
|
53
|
+
kind: "Entrypoint",
|
54
|
+
networkRequestInfo: {
|
55
|
+
kind: "NetworkRequestInfo",
|
56
|
+
queryText,
|
57
|
+
normalizationAst,
|
58
|
+
},
|
59
|
+
concreteType: "Query",
|
60
|
+
readerWithRefetchQueries: {
|
61
|
+
kind: "ReaderWithRefetchQueries",
|
62
|
+
nestedRefetchQueries,
|
63
|
+
readerArtifact: readerResolver,
|
64
|
+
},
|
65
|
+
};
|
66
|
+
|
67
|
+
export default artifact;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { Query__subquery__parameters } from './parameters_type';
|
2
|
+
|
3
|
+
export type Query__subquery__param = {
|
4
|
+
readonly data: {
|
5
|
+
readonly query: {
|
6
|
+
readonly node: ({
|
7
|
+
readonly id: string,
|
8
|
+
} | null),
|
9
|
+
},
|
10
|
+
},
|
11
|
+
readonly parameters: Query__subquery__parameters,
|
12
|
+
};
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import type { EagerReaderArtifact, ReaderAst } from '@isograph/react';
|
2
|
+
import { Query__subquery__param } from './param_type';
|
3
|
+
import { Query__subquery__output_type } from './output_type';
|
4
|
+
import { subquery as resolver } from '../../../normalizeData.test';
|
5
|
+
|
6
|
+
const readerAst: ReaderAst<Query__subquery__param> = [
|
7
|
+
{
|
8
|
+
kind: "Linked",
|
9
|
+
fieldName: "query",
|
10
|
+
alias: null,
|
11
|
+
arguments: null,
|
12
|
+
condition: null,
|
13
|
+
selections: [
|
14
|
+
{
|
15
|
+
kind: "Linked",
|
16
|
+
fieldName: "node",
|
17
|
+
alias: null,
|
18
|
+
arguments: [
|
19
|
+
[
|
20
|
+
"id",
|
21
|
+
{ kind: "Variable", name: "id" },
|
22
|
+
],
|
23
|
+
],
|
24
|
+
condition: null,
|
25
|
+
selections: [
|
26
|
+
{
|
27
|
+
kind: "Scalar",
|
28
|
+
fieldName: "id",
|
29
|
+
alias: null,
|
30
|
+
arguments: null,
|
31
|
+
},
|
32
|
+
],
|
33
|
+
},
|
34
|
+
],
|
35
|
+
},
|
36
|
+
];
|
37
|
+
|
38
|
+
const artifact: EagerReaderArtifact<
|
39
|
+
Query__subquery__param,
|
40
|
+
Query__subquery__output_type
|
41
|
+
> = {
|
42
|
+
kind: "EagerReaderArtifact",
|
43
|
+
resolver,
|
44
|
+
readerAst,
|
45
|
+
};
|
46
|
+
|
47
|
+
export default artifact;
|
@@ -1,16 +1,18 @@
|
|
1
|
-
import type {IsographEntrypoint} from '@isograph/react';
|
2
|
-
import { Query__meNameSuccessor__param } from './Query/meNameSuccessor/param_type';
|
3
|
-
import { Query__meName__param } from './Query/meName/param_type';
|
4
|
-
import { Query__nodeField__param } from './Query/nodeField/param_type';
|
1
|
+
import type { IsographEntrypoint } from '@isograph/react';
|
2
|
+
import { type Query__meNameSuccessor__param } from './Query/meNameSuccessor/param_type';
|
3
|
+
import { type Query__meName__param } from './Query/meName/param_type';
|
4
|
+
import { type Query__nodeField__param } from './Query/nodeField/param_type';
|
5
|
+
import { type Query__subquery__param } from './Query/subquery/param_type';
|
5
6
|
import entrypoint_Query__meNameSuccessor from '../__isograph/Query/meNameSuccessor/entrypoint';
|
6
7
|
import entrypoint_Query__meName from '../__isograph/Query/meName/entrypoint';
|
7
8
|
import entrypoint_Query__nodeField from '../__isograph/Query/nodeField/entrypoint';
|
9
|
+
import entrypoint_Query__subquery from '../__isograph/Query/subquery/entrypoint';
|
8
10
|
|
9
11
|
// This is the type given to regular client fields.
|
10
12
|
// This means that the type of the exported iso literal is exactly
|
11
13
|
// the type of the passed-in function, which takes one parameter
|
12
14
|
// of type TParam.
|
13
|
-
type IdentityWithParam<TParam> = <TClientFieldReturn>(
|
15
|
+
type IdentityWithParam<TParam extends object> = <TClientFieldReturn>(
|
14
16
|
clientField: (param: TParam) => TClientFieldReturn
|
15
17
|
) => (param: TParam) => TClientFieldReturn;
|
16
18
|
|
@@ -21,7 +23,10 @@ type IdentityWithParam<TParam> = <TClientFieldReturn>(
|
|
21
23
|
//
|
22
24
|
// TComponentProps becomes the types of the props you must pass
|
23
25
|
// whenever the @component field is rendered.
|
24
|
-
type IdentityWithParamComponent<TParam
|
26
|
+
type IdentityWithParamComponent<TParam extends object> = <
|
27
|
+
TClientFieldReturn,
|
28
|
+
TComponentProps = Record<PropertyKey, never>,
|
29
|
+
>(
|
25
30
|
clientComponentField: (data: TParam, componentProps: TComponentProps) => TClientFieldReturn
|
26
31
|
) => (data: TParam, componentProps: TComponentProps) => TClientFieldReturn;
|
27
32
|
|
@@ -63,6 +68,10 @@ export function iso<T>(
|
|
63
68
|
param: T & MatchesWhitespaceAndString<'field Query.nodeField', T>
|
64
69
|
): IdentityWithParam<Query__nodeField__param>;
|
65
70
|
|
71
|
+
export function iso<T>(
|
72
|
+
param: T & MatchesWhitespaceAndString<'field Query.subquery', T>
|
73
|
+
): IdentityWithParam<Query__subquery__param>;
|
74
|
+
|
66
75
|
export function iso<T>(
|
67
76
|
param: T & MatchesWhitespaceAndString<'entrypoint Query.meNameSuccessor', T>
|
68
77
|
): typeof entrypoint_Query__meNameSuccessor;
|
@@ -75,14 +84,16 @@ export function iso<T>(
|
|
75
84
|
param: T & MatchesWhitespaceAndString<'entrypoint Query.nodeField', T>
|
76
85
|
): typeof entrypoint_Query__nodeField;
|
77
86
|
|
87
|
+
export function iso<T>(
|
88
|
+
param: T & MatchesWhitespaceAndString<'entrypoint Query.subquery', T>
|
89
|
+
): typeof entrypoint_Query__subquery;
|
90
|
+
|
78
91
|
export function iso(_isographLiteralText: string):
|
79
92
|
| IdentityWithParam<any>
|
80
93
|
| IdentityWithParamComponent<any>
|
81
94
|
| IsographEntrypoint<any, any>
|
82
95
|
{
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
return clientFieldOrEntrypoint;
|
87
|
-
};
|
96
|
+
throw new Error('iso: Unexpected invocation at runtime. Either the Babel transform ' +
|
97
|
+
'was not set up, or it failed to identify this call site. Make sure it ' +
|
98
|
+
'is being used verbatim as `iso`.');
|
88
99
|
}
|
@@ -2,6 +2,7 @@ import { describe, test, expect } from 'vitest';
|
|
2
2
|
import {
|
3
3
|
ROOT_ID,
|
4
4
|
createIsographEnvironment,
|
5
|
+
type IsographStore,
|
5
6
|
} from '../core/IsographEnvironment';
|
6
7
|
import {
|
7
8
|
garbageCollectEnvironment,
|
@@ -10,32 +11,37 @@ import {
|
|
10
11
|
import { iso } from './__isograph/iso';
|
11
12
|
import { nodeFieldRetainedQuery } from './nodeQuery';
|
12
13
|
|
13
|
-
const getDefaultStore = () => ({
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
const getDefaultStore = (): IsographStore => ({
|
15
|
+
Query: {
|
16
|
+
[ROOT_ID]: {
|
17
|
+
me: { __link: '0', __typename: 'Economist' },
|
18
|
+
you: { __link: '1', __typename: 'Economist' },
|
19
|
+
node____id___0: {
|
20
|
+
__link: '0',
|
21
|
+
__typename: 'Economist',
|
22
|
+
},
|
19
23
|
},
|
20
24
|
},
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
25
|
+
Economist: {
|
26
|
+
0: {
|
27
|
+
__typename: 'Economist',
|
28
|
+
id: '0',
|
29
|
+
name: 'Jeremy Bentham',
|
30
|
+
successor: { __link: '1', __typename: 'Economist' },
|
31
|
+
},
|
32
|
+
1: {
|
33
|
+
__typename: 'Economist',
|
34
|
+
id: '1',
|
35
|
+
name: 'John Stuart Mill',
|
36
|
+
predecessor: { __link: '0', __typename: 'Economist' },
|
37
|
+
successor: { __link: '2', __typename: 'Economist' },
|
38
|
+
},
|
39
|
+
2: {
|
40
|
+
__typename: 'Economist',
|
41
|
+
id: '2',
|
42
|
+
name: 'Henry Sidgwick',
|
43
|
+
predecessor: { __link: '1', __typename: 'Economist' },
|
44
|
+
},
|
39
45
|
},
|
40
46
|
});
|
41
47
|
|
@@ -46,12 +52,12 @@ export const meNameField = iso(`
|
|
46
52
|
}
|
47
53
|
}
|
48
54
|
`)(() => {});
|
49
|
-
import meNameEntrypoint from './__isograph/Query/meName/entrypoint';
|
50
55
|
import { meNameSuccessorRetainedQuery } from './meNameSuccessor';
|
51
|
-
iso(`entrypoint Query.meName`);
|
56
|
+
const meNameEntrypoint = iso(`entrypoint Query.meName`);
|
52
57
|
const meNameRetainedQuery = {
|
53
|
-
normalizationAst: meNameEntrypoint.normalizationAst,
|
58
|
+
normalizationAst: meNameEntrypoint.networkRequestInfo.normalizationAst,
|
54
59
|
variables: {},
|
60
|
+
root: { __link: ROOT_ID, __typename: 'Query' },
|
55
61
|
};
|
56
62
|
|
57
63
|
describe('garbage collection', () => {
|
@@ -63,13 +69,13 @@ describe('garbage collection', () => {
|
|
63
69
|
null as any,
|
64
70
|
);
|
65
71
|
|
66
|
-
expect(store[1]).not.toBe(undefined);
|
72
|
+
expect(store.Economist?.[1]).not.toBe(undefined);
|
67
73
|
|
68
74
|
// TODO enable babel so we don't have to do this
|
69
75
|
retainQuery(environment, meNameRetainedQuery);
|
70
76
|
garbageCollectEnvironment(environment);
|
71
77
|
|
72
|
-
expect(store[1]).toBe(undefined);
|
78
|
+
expect(store.Economist?.[1]).toBe(undefined);
|
73
79
|
});
|
74
80
|
|
75
81
|
test('Referenced records should not be garbage collected', () => {
|
@@ -80,13 +86,13 @@ describe('garbage collection', () => {
|
|
80
86
|
null as any,
|
81
87
|
);
|
82
88
|
|
83
|
-
expect(store[0]).not.toBe(undefined);
|
89
|
+
expect(store.Economist?.[0]).not.toBe(undefined);
|
84
90
|
|
85
91
|
// TODO enable babel so we don't have to do this
|
86
92
|
retainQuery(environment, meNameRetainedQuery);
|
87
93
|
garbageCollectEnvironment(environment);
|
88
94
|
|
89
|
-
expect(store[0]).not.toBe(undefined);
|
95
|
+
expect(store.Economist?.[0]).not.toBe(undefined);
|
90
96
|
});
|
91
97
|
|
92
98
|
test('Referenced records should not be garbage collected, and this should work with variables', () => {
|
@@ -97,12 +103,12 @@ describe('garbage collection', () => {
|
|
97
103
|
null as any,
|
98
104
|
);
|
99
105
|
|
100
|
-
expect(store[0]).not.toBe(undefined);
|
106
|
+
expect(store.Economist?.[0]).not.toBe(undefined);
|
101
107
|
|
102
108
|
retainQuery(environment, nodeFieldRetainedQuery);
|
103
109
|
garbageCollectEnvironment(environment);
|
104
110
|
|
105
|
-
expect(store[0]).not.toBe(undefined);
|
111
|
+
expect(store.Economist?.[0]).not.toBe(undefined);
|
106
112
|
});
|
107
113
|
|
108
114
|
test('Referenced records should not be garbage collected, and this should work through multiple levels', () => {
|
@@ -116,12 +122,12 @@ describe('garbage collection', () => {
|
|
116
122
|
retainQuery(environment, meNameSuccessorRetainedQuery);
|
117
123
|
garbageCollectEnvironment(environment);
|
118
124
|
|
119
|
-
expect(store[0]).not.toBe(undefined);
|
120
|
-
expect(store[1]).not.toBe(undefined);
|
121
|
-
expect(store[2]).not.toBe(undefined);
|
125
|
+
expect(store.Economist?.[0]).not.toBe(undefined);
|
126
|
+
expect(store.Economist?.[1]).not.toBe(undefined);
|
127
|
+
expect(store.Economist?.[2]).not.toBe(undefined);
|
122
128
|
});
|
123
129
|
|
124
|
-
test('ROOT_ID should
|
130
|
+
test('ROOT_ID should be garbage collected, if there are no retained queries', () => {
|
125
131
|
const store = getDefaultStore();
|
126
132
|
const environment = createIsographEnvironment(
|
127
133
|
store,
|
@@ -130,7 +136,7 @@ describe('garbage collection', () => {
|
|
130
136
|
);
|
131
137
|
garbageCollectEnvironment(environment);
|
132
138
|
|
133
|
-
expect(store[ROOT_ID]).
|
134
|
-
expect(store[0]).toBe(undefined);
|
139
|
+
expect(store.Query?.[ROOT_ID]).toBe(undefined);
|
140
|
+
expect(store.Economist?.[0]).toBe(undefined);
|
135
141
|
});
|
136
142
|
});
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { ROOT_ID } from '../core/IsographEnvironment';
|
1
2
|
import { iso } from './__isograph/iso';
|
2
3
|
|
3
4
|
export const meNameField = iso(`
|
@@ -12,9 +13,13 @@ export const meNameField = iso(`
|
|
12
13
|
}
|
13
14
|
}
|
14
15
|
`)(() => {});
|
15
|
-
|
16
|
-
iso(`entrypoint Query.meNameSuccessor`);
|
16
|
+
const meNameSuccessorEntrypoint = iso(`entrypoint Query.meNameSuccessor`);
|
17
17
|
export const meNameSuccessorRetainedQuery = {
|
18
|
-
normalizationAst:
|
18
|
+
normalizationAst:
|
19
|
+
meNameSuccessorEntrypoint.networkRequestInfo.normalizationAst,
|
19
20
|
variables: {},
|
21
|
+
root: {
|
22
|
+
__link: ROOT_ID,
|
23
|
+
__typename: 'Query',
|
24
|
+
},
|
20
25
|
};
|
package/src/tests/nodeQuery.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import { RetainedQuery } from '../core/garbageCollection';
|
2
|
+
import { ROOT_ID } from '../core/IsographEnvironment';
|
1
3
|
import { iso } from './__isograph/iso';
|
2
4
|
|
3
5
|
// TODO investigate why this can't be in garbageCollection.test.ts without
|
@@ -9,9 +11,9 @@ export const nodeField = iso(`
|
|
9
11
|
}
|
10
12
|
}
|
11
13
|
`)(() => {});
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
normalizationAst: nodeFieldEntrypoint.normalizationAst,
|
14
|
+
const nodeFieldEntrypoint = iso(`entrypoint Query.nodeField`);
|
15
|
+
export const nodeFieldRetainedQuery: RetainedQuery = {
|
16
|
+
normalizationAst: nodeFieldEntrypoint.networkRequestInfo.normalizationAst,
|
16
17
|
variables: { id: 0 },
|
18
|
+
root: { __link: ROOT_ID, __typename: 'Query' },
|
17
19
|
};
|