@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.
Files changed (134) hide show
  1. package/dist/core/FragmentReference.d.ts +14 -4
  2. package/dist/core/FragmentReference.d.ts.map +1 -0
  3. package/dist/core/FragmentReference.js +2 -3
  4. package/dist/core/IsographEnvironment.d.ts +28 -10
  5. package/dist/core/IsographEnvironment.d.ts.map +1 -0
  6. package/dist/core/IsographEnvironment.js +15 -22
  7. package/dist/core/PromiseWrapper.d.ts +1 -0
  8. package/dist/core/PromiseWrapper.d.ts.map +1 -0
  9. package/dist/core/PromiseWrapper.js +4 -5
  10. package/dist/core/areEqualWithDeepComparison.d.ts +5 -3
  11. package/dist/core/areEqualWithDeepComparison.d.ts.map +1 -0
  12. package/dist/core/areEqualWithDeepComparison.js +73 -39
  13. package/dist/core/cache.d.ts +26 -10
  14. package/dist/core/cache.d.ts.map +1 -0
  15. package/dist/core/cache.js +160 -98
  16. package/dist/core/check.d.ts +18 -0
  17. package/dist/core/check.d.ts.map +1 -0
  18. package/dist/core/check.js +127 -0
  19. package/dist/core/componentCache.d.ts +1 -1
  20. package/dist/core/componentCache.d.ts.map +1 -0
  21. package/dist/core/componentCache.js +14 -14
  22. package/dist/core/entrypoint.d.ts +27 -8
  23. package/dist/core/entrypoint.d.ts.map +1 -0
  24. package/dist/core/entrypoint.js +1 -2
  25. package/dist/core/garbageCollection.d.ts +3 -1
  26. package/dist/core/garbageCollection.d.ts.map +1 -0
  27. package/dist/core/garbageCollection.js +48 -15
  28. package/dist/core/logging.d.ts +69 -0
  29. package/dist/core/logging.d.ts.map +1 -0
  30. package/dist/core/logging.js +19 -0
  31. package/dist/core/makeNetworkRequest.d.ts +4 -1
  32. package/dist/core/makeNetworkRequest.d.ts.map +1 -0
  33. package/dist/core/makeNetworkRequest.js +71 -15
  34. package/dist/core/read.d.ts +20 -5
  35. package/dist/core/read.d.ts.map +1 -0
  36. package/dist/core/read.js +104 -41
  37. package/dist/core/reader.d.ts +34 -10
  38. package/dist/core/reader.d.ts.map +1 -0
  39. package/dist/core/util.d.ts +2 -0
  40. package/dist/core/util.d.ts.map +1 -0
  41. package/dist/index.d.ts +10 -5
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +10 -2
  44. package/dist/loadable-hooks/useClientSideDefer.d.ts +15 -3
  45. package/dist/loadable-hooks/useClientSideDefer.d.ts.map +1 -0
  46. package/dist/loadable-hooks/useClientSideDefer.js +4 -6
  47. package/dist/loadable-hooks/useConnectionSpecPagination.d.ts +34 -0
  48. package/dist/loadable-hooks/useConnectionSpecPagination.d.ts.map +1 -0
  49. package/dist/loadable-hooks/useConnectionSpecPagination.js +160 -0
  50. package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts +1 -0
  51. package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts.map +1 -0
  52. package/dist/loadable-hooks/useImperativeExposedMutationField.js +1 -2
  53. package/dist/loadable-hooks/useImperativeLoadableField.d.ts +13 -5
  54. package/dist/loadable-hooks/useImperativeLoadableField.d.ts.map +1 -0
  55. package/dist/loadable-hooks/useImperativeLoadableField.js +3 -4
  56. package/dist/loadable-hooks/useSkipLimitPagination.d.ts +18 -24
  57. package/dist/loadable-hooks/useSkipLimitPagination.d.ts.map +1 -0
  58. package/dist/loadable-hooks/useSkipLimitPagination.js +88 -44
  59. package/dist/react/FragmentReader.d.ts +7 -4
  60. package/dist/react/FragmentReader.d.ts.map +1 -0
  61. package/dist/react/FragmentReader.js +4 -2
  62. package/dist/react/IsographEnvironmentProvider.d.ts +1 -0
  63. package/dist/react/IsographEnvironmentProvider.d.ts.map +1 -0
  64. package/dist/react/IsographEnvironmentProvider.js +3 -3
  65. package/dist/react/RenderAfterCommit__DO_NOT_USE.d.ts +10 -0
  66. package/dist/react/RenderAfterCommit__DO_NOT_USE.d.ts.map +1 -0
  67. package/dist/react/RenderAfterCommit__DO_NOT_USE.js +15 -0
  68. package/dist/react/useImperativeReference.d.ts +8 -3
  69. package/dist/react/useImperativeReference.d.ts.map +1 -0
  70. package/dist/react/useImperativeReference.js +4 -5
  71. package/dist/react/useLazyReference.d.ts +7 -2
  72. package/dist/react/useLazyReference.d.ts.map +1 -0
  73. package/dist/react/useLazyReference.js +11 -4
  74. package/dist/react/useReadAndSubscribe.d.ts +12 -3
  75. package/dist/react/useReadAndSubscribe.d.ts.map +1 -0
  76. package/dist/react/useReadAndSubscribe.js +6 -7
  77. package/dist/react/useRerenderOnChange.d.ts +6 -1
  78. package/dist/react/useRerenderOnChange.d.ts.map +1 -0
  79. package/dist/react/useRerenderOnChange.js +3 -4
  80. package/dist/react/useResult.d.ts +5 -1
  81. package/dist/react/useResult.d.ts.map +1 -0
  82. package/dist/react/useResult.js +8 -5
  83. package/{src/tests/isograph.config.json → isograph.config.json} +1 -1
  84. package/package.json +12 -8
  85. package/{src/tests/schema.graphql → schema.graphql} +1 -0
  86. package/src/core/FragmentReference.ts +17 -5
  87. package/src/core/IsographEnvironment.ts +38 -29
  88. package/src/core/areEqualWithDeepComparison.ts +76 -42
  89. package/src/core/cache.ts +237 -123
  90. package/src/core/check.ts +207 -0
  91. package/src/core/componentCache.ts +18 -17
  92. package/src/core/entrypoint.ts +15 -8
  93. package/src/core/garbageCollection.ts +71 -20
  94. package/src/core/logging.ts +116 -0
  95. package/src/core/makeNetworkRequest.ts +89 -13
  96. package/src/core/read.ts +162 -55
  97. package/src/core/reader.ts +40 -13
  98. package/src/core/util.ts +4 -0
  99. package/src/index.ts +14 -1
  100. package/src/loadable-hooks/useClientSideDefer.ts +45 -15
  101. package/src/loadable-hooks/useConnectionSpecPagination.ts +331 -0
  102. package/src/loadable-hooks/useImperativeLoadableField.ts +36 -10
  103. package/src/loadable-hooks/useSkipLimitPagination.ts +231 -90
  104. package/src/react/FragmentReader.tsx +13 -4
  105. package/src/react/RenderAfterCommit__DO_NOT_USE.tsx +17 -0
  106. package/src/react/useImperativeReference.ts +18 -7
  107. package/src/react/useLazyReference.ts +24 -4
  108. package/src/react/useReadAndSubscribe.ts +20 -5
  109. package/src/react/useRerenderOnChange.ts +6 -1
  110. package/src/react/useResult.ts +10 -2
  111. package/src/tests/__isograph/Query/meName/entrypoint.ts +7 -2
  112. package/src/tests/__isograph/Query/meName/param_type.ts +5 -2
  113. package/src/tests/__isograph/Query/meName/resolver_reader.ts +1 -0
  114. package/src/tests/__isograph/Query/meNameSuccessor/entrypoint.ts +9 -2
  115. package/src/tests/__isograph/Query/meNameSuccessor/param_type.ts +9 -6
  116. package/src/tests/__isograph/Query/meNameSuccessor/resolver_reader.ts +3 -0
  117. package/src/tests/__isograph/Query/nodeField/entrypoint.ts +13 -2
  118. package/src/tests/__isograph/Query/nodeField/param_type.ts +7 -3
  119. package/src/tests/__isograph/Query/nodeField/parameters_type.ts +3 -0
  120. package/src/tests/__isograph/Query/nodeField/resolver_reader.ts +1 -0
  121. package/src/tests/__isograph/Query/subquery/entrypoint.ts +67 -0
  122. package/src/tests/__isograph/Query/subquery/output_type.ts +3 -0
  123. package/src/tests/__isograph/Query/subquery/param_type.ts +12 -0
  124. package/src/tests/__isograph/Query/subquery/parameters_type.ts +3 -0
  125. package/src/tests/__isograph/Query/subquery/resolver_reader.ts +47 -0
  126. package/src/tests/__isograph/iso.ts +22 -11
  127. package/src/tests/garbageCollection.test.ts +45 -39
  128. package/src/tests/meNameSuccessor.ts +8 -3
  129. package/src/tests/nodeQuery.ts +6 -4
  130. package/src/tests/normalizeData.test.ts +120 -0
  131. package/src/tests/tsconfig.json +3 -3
  132. package/tsconfig.json +2 -2
  133. package/tsconfig.pkg.json +6 -1
  134. package/vitest.config.ts +20 -0
@@ -12,7 +12,10 @@ import {
12
12
  readPromise,
13
13
  } from '../core/PromiseWrapper';
14
14
 
15
- export function useResult<TReadFromStore extends Object, TClientFieldValue>(
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
- return readerWithRefetchQueries.readerArtifact.resolver(data);
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
- queryText,
39
- normalizationAst,
39
+ networkRequestInfo: {
40
+ kind: "NetworkRequestInfo",
41
+ queryText,
42
+ normalizationAst,
43
+ },
44
+ concreteType: "Query",
40
45
  readerWithRefetchQueries: {
41
46
  kind: "ReaderWithRefetchQueries",
42
47
  nestedRefetchQueries,
@@ -1,6 +1,9 @@
1
1
 
2
2
  export type Query__meName__param = {
3
- me: {
4
- name: string,
3
+ readonly data: {
4
+ readonly me: {
5
+ readonly name: string,
6
+ },
5
7
  },
8
+ readonly parameters: Record<PropertyKey, never>,
6
9
  };
@@ -9,6 +9,7 @@ const readerAst: ReaderAst<Query__meName__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",
@@ -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
- queryText,
75
- normalizationAst,
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
- me: {
4
- name: string,
5
- successor: ({
6
- successor: ({
7
- name: string,
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
- } | null),
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
- queryText,
38
- normalizationAst,
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
- node: ({
4
- id: string,
5
- } | null),
4
+ readonly data: {
5
+ readonly node: ({
6
+ readonly id: string,
7
+ } | null),
8
+ },
9
+ readonly parameters: Query__nodeField__parameters,
6
10
  };
@@ -0,0 +1,3 @@
1
+ export type Query__nodeField__parameters = {
2
+ readonly id: string,
3
+ };
@@ -14,6 +14,7 @@ const readerAst: ReaderAst<Query__nodeField__param> = [
14
14
  { kind: "Variable", name: "id" },
15
15
  ],
16
16
  ],
17
+ condition: null,
17
18
  selections: [
18
19
  {
19
20
  kind: "Scalar",
@@ -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,3 @@
1
+ import type React from 'react';
2
+ import { subquery as resolver } from '../../../normalizeData.test';
3
+ export type Query__subquery__output_type = ReturnType<typeof resolver>;
@@ -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,3 @@
1
+ export type Query__subquery__parameters = {
2
+ readonly id: string,
3
+ };
@@ -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> = <TClientFieldReturn, TComponentProps = Record<string, never>>(
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
- return function identity<TClientFieldReturn>(
84
- clientFieldOrEntrypoint: (param: any) => TClientFieldReturn,
85
- ): (param: any) => TClientFieldReturn {
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
- [ROOT_ID]: {
15
- me: { __link: '0' },
16
- you: { __link: '1' },
17
- node____id___0: {
18
- __link: '0',
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
- 0: {
22
- __typename: 'Economist',
23
- id: '0',
24
- name: 'Jeremy Bentham',
25
- successor: { __link: '1' },
26
- },
27
- 1: {
28
- __typename: 'Economist',
29
- id: '1',
30
- name: 'John Stuart Mill',
31
- predecessor: { __link: '0' },
32
- successor: { __link: '2' },
33
- },
34
- 2: {
35
- __typename: 'Economist',
36
- id: '2',
37
- name: 'Henry Sidgwick',
38
- predecessor: { __link: '1' },
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 not be garbage collected, even if there are no retained queries', () => {
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]).not.toBe(undefined);
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
- import meNameSuccessorEntrypoint from './__isograph/Query/meNameSuccessor/entrypoint';
16
- iso(`entrypoint Query.meNameSuccessor`);
16
+ const meNameSuccessorEntrypoint = iso(`entrypoint Query.meNameSuccessor`);
17
17
  export const meNameSuccessorRetainedQuery = {
18
- normalizationAst: meNameSuccessorEntrypoint.normalizationAst,
18
+ normalizationAst:
19
+ meNameSuccessorEntrypoint.networkRequestInfo.normalizationAst,
19
20
  variables: {},
21
+ root: {
22
+ __link: ROOT_ID,
23
+ __typename: 'Query',
24
+ },
20
25
  };
@@ -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
- import nodeFieldEntrypoint from './__isograph/Query/nodeField/entrypoint';
13
- iso(`entrypoint Query.nodeField`);
14
- export const nodeFieldRetainedQuery = {
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
  };