@isograph/react 0.2.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.
Files changed (151) hide show
  1. package/.turbo/turbo-compile-typescript.log +4 -0
  2. package/dist/core/FragmentReference.d.ts +25 -6
  3. package/dist/core/FragmentReference.d.ts.map +1 -0
  4. package/dist/core/FragmentReference.js +3 -13
  5. package/dist/core/IsographEnvironment.d.ts +34 -26
  6. package/dist/core/IsographEnvironment.d.ts.map +1 -0
  7. package/dist/core/IsographEnvironment.js +19 -22
  8. package/dist/core/PromiseWrapper.d.ts +4 -4
  9. package/dist/core/PromiseWrapper.d.ts.map +1 -0
  10. package/dist/core/PromiseWrapper.js +9 -9
  11. package/dist/core/areEqualWithDeepComparison.d.ts +5 -3
  12. package/dist/core/areEqualWithDeepComparison.d.ts.map +1 -0
  13. package/dist/core/areEqualWithDeepComparison.js +89 -39
  14. package/dist/core/cache.d.ts +20 -13
  15. package/dist/core/cache.d.ts.map +1 -0
  16. package/dist/core/cache.js +205 -128
  17. package/dist/core/check.d.ts +22 -0
  18. package/dist/core/check.d.ts.map +1 -0
  19. package/dist/core/check.js +127 -0
  20. package/dist/core/componentCache.d.ts +2 -2
  21. package/dist/core/componentCache.d.ts.map +1 -0
  22. package/dist/core/componentCache.js +28 -32
  23. package/dist/core/entrypoint.d.ts +31 -15
  24. package/dist/core/entrypoint.d.ts.map +1 -0
  25. package/dist/core/entrypoint.js +1 -2
  26. package/dist/core/garbageCollection.d.ts +6 -5
  27. package/dist/core/garbageCollection.d.ts.map +1 -0
  28. package/dist/core/garbageCollection.js +49 -16
  29. package/dist/core/logging.d.ts +68 -0
  30. package/dist/core/logging.d.ts.map +1 -0
  31. package/dist/core/logging.js +22 -0
  32. package/dist/core/makeNetworkRequest.d.ts +6 -3
  33. package/dist/core/makeNetworkRequest.d.ts.map +1 -0
  34. package/dist/core/makeNetworkRequest.js +160 -19
  35. package/dist/core/read.d.ts +25 -5
  36. package/dist/core/read.d.ts.map +1 -0
  37. package/dist/core/read.js +416 -259
  38. package/dist/core/reader.d.ts +31 -15
  39. package/dist/core/reader.d.ts.map +1 -0
  40. package/dist/core/startUpdate.d.ts +5 -0
  41. package/dist/core/startUpdate.d.ts.map +1 -0
  42. package/dist/core/startUpdate.js +15 -0
  43. package/dist/core/util.d.ts +5 -0
  44. package/dist/core/util.d.ts.map +1 -0
  45. package/dist/index.d.ts +19 -14
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +11 -2
  48. package/dist/loadable-hooks/useClientSideDefer.d.ts +9 -3
  49. package/dist/loadable-hooks/useClientSideDefer.d.ts.map +1 -0
  50. package/dist/loadable-hooks/useClientSideDefer.js +6 -8
  51. package/dist/loadable-hooks/useConnectionSpecPagination.d.ts +27 -0
  52. package/dist/loadable-hooks/useConnectionSpecPagination.d.ts.map +1 -0
  53. package/dist/loadable-hooks/useConnectionSpecPagination.js +162 -0
  54. package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts +2 -2
  55. package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts.map +1 -0
  56. package/dist/loadable-hooks/useImperativeExposedMutationField.js +1 -2
  57. package/dist/loadable-hooks/useImperativeLoadableField.d.ts +13 -7
  58. package/dist/loadable-hooks/useImperativeLoadableField.d.ts.map +1 -0
  59. package/dist/loadable-hooks/useImperativeLoadableField.js +4 -5
  60. package/dist/loadable-hooks/useSkipLimitPagination.d.ts +13 -26
  61. package/dist/loadable-hooks/useSkipLimitPagination.d.ts.map +1 -0
  62. package/dist/loadable-hooks/useSkipLimitPagination.js +93 -47
  63. package/dist/react/FragmentReader.d.ts +6 -4
  64. package/dist/react/FragmentReader.d.ts.map +1 -0
  65. package/dist/react/FragmentReader.js +4 -2
  66. package/dist/react/IsographEnvironmentProvider.d.ts +1 -0
  67. package/dist/react/IsographEnvironmentProvider.d.ts.map +1 -0
  68. package/dist/react/IsographEnvironmentProvider.js +3 -3
  69. package/dist/react/RenderAfterCommit__DO_NOT_USE.d.ts +10 -0
  70. package/dist/react/RenderAfterCommit__DO_NOT_USE.d.ts.map +1 -0
  71. package/dist/react/RenderAfterCommit__DO_NOT_USE.js +15 -0
  72. package/dist/react/useImperativeReference.d.ts +8 -6
  73. package/dist/react/useImperativeReference.d.ts.map +1 -0
  74. package/dist/react/useImperativeReference.js +6 -8
  75. package/dist/react/useLazyReference.d.ts +5 -3
  76. package/dist/react/useLazyReference.d.ts.map +1 -0
  77. package/dist/react/useLazyReference.js +34 -6
  78. package/dist/react/useReadAndSubscribe.d.ts +6 -3
  79. package/dist/react/useReadAndSubscribe.d.ts.map +1 -0
  80. package/dist/react/useReadAndSubscribe.js +13 -10
  81. package/dist/react/useRerenderOnChange.d.ts +7 -2
  82. package/dist/react/useRerenderOnChange.d.ts.map +1 -0
  83. package/dist/react/useRerenderOnChange.js +3 -4
  84. package/dist/react/useResult.d.ts +4 -3
  85. package/dist/react/useResult.d.ts.map +1 -0
  86. package/dist/react/useResult.js +14 -9
  87. package/isograph.config.json +8 -0
  88. package/package.json +14 -9
  89. package/{src/tests/schema.graphql → schema.graphql} +1 -0
  90. package/src/core/FragmentReference.ts +44 -17
  91. package/src/core/IsographEnvironment.ts +67 -50
  92. package/src/core/PromiseWrapper.ts +3 -3
  93. package/src/core/areEqualWithDeepComparison.ts +95 -41
  94. package/src/core/cache.ts +316 -169
  95. package/src/core/check.ts +212 -0
  96. package/src/core/componentCache.ts +40 -46
  97. package/src/core/entrypoint.ts +41 -16
  98. package/src/core/garbageCollection.ts +77 -26
  99. package/src/core/logging.ts +118 -0
  100. package/src/core/makeNetworkRequest.ts +249 -20
  101. package/src/core/read.ts +658 -368
  102. package/src/core/reader.ts +61 -21
  103. package/src/core/startUpdate.ts +28 -0
  104. package/src/core/util.ts +8 -0
  105. package/src/index.ts +94 -8
  106. package/src/loadable-hooks/useClientSideDefer.ts +48 -17
  107. package/src/loadable-hooks/useConnectionSpecPagination.ts +344 -0
  108. package/src/loadable-hooks/useImperativeExposedMutationField.ts +1 -1
  109. package/src/loadable-hooks/useImperativeLoadableField.ts +36 -12
  110. package/src/loadable-hooks/useSkipLimitPagination.ts +253 -94
  111. package/src/react/FragmentReader.tsx +15 -6
  112. package/src/react/IsographEnvironmentProvider.tsx +1 -1
  113. package/src/react/RenderAfterCommit__DO_NOT_USE.tsx +17 -0
  114. package/src/react/useImperativeReference.ts +50 -18
  115. package/src/react/useLazyReference.ts +79 -11
  116. package/src/react/useReadAndSubscribe.ts +33 -10
  117. package/src/react/useRerenderOnChange.ts +7 -2
  118. package/src/react/useResult.ts +30 -9
  119. package/src/tests/__isograph/Query/meName/entrypoint.ts +10 -29
  120. package/src/tests/__isograph/Query/meName/normalization_ast.ts +25 -0
  121. package/src/tests/__isograph/Query/meName/param_type.ts +5 -2
  122. package/src/tests/__isograph/Query/meName/query_text.ts +6 -0
  123. package/src/tests/__isograph/Query/meName/resolver_reader.ts +5 -0
  124. package/src/tests/__isograph/Query/meNameSuccessor/entrypoint.ts +10 -65
  125. package/src/tests/__isograph/Query/meNameSuccessor/normalization_ast.ts +56 -0
  126. package/src/tests/__isograph/Query/meNameSuccessor/param_type.ts +9 -6
  127. package/src/tests/__isograph/Query/meNameSuccessor/query_text.ts +13 -0
  128. package/src/tests/__isograph/Query/meNameSuccessor/resolver_reader.ts +10 -0
  129. package/src/tests/__isograph/Query/nodeField/entrypoint.ts +10 -28
  130. package/src/tests/__isograph/Query/nodeField/normalization_ast.ts +30 -0
  131. package/src/tests/__isograph/Query/nodeField/param_type.ts +7 -3
  132. package/src/tests/__isograph/Query/nodeField/parameters_type.ts +3 -0
  133. package/src/tests/__isograph/Query/nodeField/query_text.ts +6 -0
  134. package/src/tests/__isograph/Query/nodeField/resolver_reader.ts +5 -0
  135. package/src/tests/__isograph/Query/subquery/entrypoint.ts +28 -0
  136. package/src/tests/__isograph/Query/subquery/normalization_ast.ts +38 -0
  137. package/src/tests/__isograph/Query/subquery/output_type.ts +3 -0
  138. package/src/tests/__isograph/Query/subquery/param_type.ts +12 -0
  139. package/src/tests/__isograph/Query/subquery/parameters_type.ts +3 -0
  140. package/src/tests/__isograph/Query/subquery/query_text.ts +8 -0
  141. package/src/tests/__isograph/Query/subquery/resolver_reader.ts +52 -0
  142. package/src/tests/__isograph/iso.ts +24 -12
  143. package/src/tests/garbageCollection.test.ts +53 -45
  144. package/src/tests/meNameSuccessor.ts +8 -3
  145. package/src/tests/nodeQuery.ts +7 -4
  146. package/src/tests/normalizeData.test.ts +120 -0
  147. package/src/tests/tsconfig.json +3 -3
  148. package/tsconfig.json +2 -2
  149. package/tsconfig.pkg.json +7 -3
  150. package/vitest.config.ts +20 -0
  151. package/src/tests/isograph.config.json +0 -7
@@ -2,40 +2,22 @@ import type {IsographEntrypoint, NormalizationAst, RefetchQueryNormalizationArti
2
2
  import {Query__nodeField__param} from './param_type';
3
3
  import {Query__nodeField__output_type} from './output_type';
4
4
  import readerResolver from './resolver_reader';
5
+ import queryText from './query_text';
6
+ import normalizationAst from './normalization_ast';
5
7
  const nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[] = [];
6
8
 
7
- const queryText = 'query nodeField ($id: ID!) {\
8
- node____id___v_id: node(id: $id) {\
9
- id,\
10
- },\
11
- }';
12
-
13
- const normalizationAst: NormalizationAst = [
14
- {
15
- kind: "Linked",
16
- fieldName: "node",
17
- arguments: [
18
- [
19
- "id",
20
- { kind: "Variable", name: "id" },
21
- ],
22
- ],
23
- selections: [
24
- {
25
- kind: "Scalar",
26
- fieldName: "id",
27
- arguments: null,
28
- },
29
- ],
30
- },
31
- ];
32
9
  const artifact: IsographEntrypoint<
33
10
  Query__nodeField__param,
34
- Query__nodeField__output_type
11
+ Query__nodeField__output_type,
12
+ NormalizationAst
35
13
  > = {
36
14
  kind: "Entrypoint",
37
- queryText,
38
- normalizationAst,
15
+ networkRequestInfo: {
16
+ kind: "NetworkRequestInfo",
17
+ queryText,
18
+ normalizationAst,
19
+ },
20
+ concreteType: "Query",
39
21
  readerWithRefetchQueries: {
40
22
  kind: "ReaderWithRefetchQueries",
41
23
  nestedRefetchQueries,
@@ -0,0 +1,30 @@
1
+ import type {NormalizationAst} from '@isograph/react';
2
+ const normalizationAst: NormalizationAst = {
3
+ kind: "NormalizationAst",
4
+ selections: [
5
+ {
6
+ kind: "Linked",
7
+ fieldName: "node",
8
+ arguments: [
9
+ [
10
+ "id",
11
+ { kind: "Variable", name: "id" },
12
+ ],
13
+ ],
14
+ concreteType: null,
15
+ selections: [
16
+ {
17
+ kind: "Scalar",
18
+ fieldName: "__typename",
19
+ arguments: null,
20
+ },
21
+ {
22
+ kind: "Scalar",
23
+ fieldName: "id",
24
+ arguments: null,
25
+ },
26
+ ],
27
+ },
28
+ ],
29
+ };
30
+ export default normalizationAst;
@@ -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
+ };
@@ -0,0 +1,6 @@
1
+ export default 'query nodeField ($id: ID!) {\
2
+ node____id___v_id: node(id: $id) {\
3
+ __typename,\
4
+ id,\
5
+ },\
6
+ }';
@@ -14,12 +14,15 @@ const readerAst: ReaderAst<Query__nodeField__param> = [
14
14
  { kind: "Variable", name: "id" },
15
15
  ],
16
16
  ],
17
+ condition: null,
18
+ isUpdatable: false,
17
19
  selections: [
18
20
  {
19
21
  kind: "Scalar",
20
22
  fieldName: "id",
21
23
  alias: null,
22
24
  arguments: null,
25
+ isUpdatable: false,
23
26
  },
24
27
  ],
25
28
  },
@@ -30,8 +33,10 @@ const artifact: EagerReaderArtifact<
30
33
  Query__nodeField__output_type
31
34
  > = {
32
35
  kind: "EagerReaderArtifact",
36
+ fieldName: "Query.nodeField",
33
37
  resolver,
34
38
  readerAst,
39
+ hasUpdatable: false,
35
40
  };
36
41
 
37
42
  export default artifact;
@@ -0,0 +1,28 @@
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
+ import queryText from './query_text';
6
+ import normalizationAst from './normalization_ast';
7
+ const nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[] = [];
8
+
9
+ const artifact: IsographEntrypoint<
10
+ Query__subquery__param,
11
+ Query__subquery__output_type,
12
+ NormalizationAst
13
+ > = {
14
+ kind: "Entrypoint",
15
+ networkRequestInfo: {
16
+ kind: "NetworkRequestInfo",
17
+ queryText,
18
+ normalizationAst,
19
+ },
20
+ concreteType: "Query",
21
+ readerWithRefetchQueries: {
22
+ kind: "ReaderWithRefetchQueries",
23
+ nestedRefetchQueries,
24
+ readerArtifact: readerResolver,
25
+ },
26
+ };
27
+
28
+ export default artifact;
@@ -0,0 +1,38 @@
1
+ import type {NormalizationAst} from '@isograph/react';
2
+ const normalizationAst: NormalizationAst = {
3
+ kind: "NormalizationAst",
4
+ selections: [
5
+ {
6
+ kind: "Linked",
7
+ fieldName: "query",
8
+ arguments: null,
9
+ concreteType: "Query",
10
+ selections: [
11
+ {
12
+ kind: "Linked",
13
+ fieldName: "node",
14
+ arguments: [
15
+ [
16
+ "id",
17
+ { kind: "Variable", name: "id" },
18
+ ],
19
+ ],
20
+ concreteType: null,
21
+ selections: [
22
+ {
23
+ kind: "Scalar",
24
+ fieldName: "__typename",
25
+ arguments: null,
26
+ },
27
+ {
28
+ kind: "Scalar",
29
+ fieldName: "id",
30
+ arguments: null,
31
+ },
32
+ ],
33
+ },
34
+ ],
35
+ },
36
+ ],
37
+ };
38
+ export default normalizationAst;
@@ -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,8 @@
1
+ export default 'query subquery ($id: ID!) {\
2
+ query {\
3
+ node____id___v_id: node(id: $id) {\
4
+ __typename,\
5
+ id,\
6
+ },\
7
+ },\
8
+ }';
@@ -0,0 +1,52 @@
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
+ isUpdatable: false,
14
+ selections: [
15
+ {
16
+ kind: "Linked",
17
+ fieldName: "node",
18
+ alias: null,
19
+ arguments: [
20
+ [
21
+ "id",
22
+ { kind: "Variable", name: "id" },
23
+ ],
24
+ ],
25
+ condition: null,
26
+ isUpdatable: false,
27
+ selections: [
28
+ {
29
+ kind: "Scalar",
30
+ fieldName: "id",
31
+ alias: null,
32
+ arguments: null,
33
+ isUpdatable: false,
34
+ },
35
+ ],
36
+ },
37
+ ],
38
+ },
39
+ ];
40
+
41
+ const artifact: EagerReaderArtifact<
42
+ Query__subquery__param,
43
+ Query__subquery__output_type
44
+ > = {
45
+ kind: "EagerReaderArtifact",
46
+ fieldName: "Query.subquery",
47
+ resolver,
48
+ readerAst,
49
+ hasUpdatable: false,
50
+ };
51
+
52
+ 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,17 @@ 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
- | IsographEntrypoint<any, any>
94
+ | IsographEntrypoint<any, 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`. If you cannot use the babel transform, ' +
99
+ 'set options.no_babel_transform to true in your Isograph config. ');
88
100
  }
@@ -1,41 +1,48 @@
1
- import { describe, test, expect } from 'vitest';
2
- import {
3
- ROOT_ID,
4
- createIsographEnvironment,
5
- } from '../core/IsographEnvironment';
1
+ import { describe, expect, test } from 'vitest';
6
2
  import {
7
3
  garbageCollectEnvironment,
8
4
  retainQuery,
9
5
  } from '../core/garbageCollection';
6
+ import {
7
+ createIsographEnvironment,
8
+ ROOT_ID,
9
+ type IsographStore,
10
+ } from '../core/IsographEnvironment';
10
11
  import { iso } from './__isograph/iso';
12
+ import { meNameSuccessorRetainedQuery } from './meNameSuccessor';
11
13
  import { nodeFieldRetainedQuery } from './nodeQuery';
12
14
 
13
- const getDefaultStore = () => ({
14
- [ROOT_ID]: {
15
- me: { __link: '0' },
16
- you: { __link: '1' },
17
- node____id___0: {
18
- __link: '0',
15
+ const getDefaultStore = (): IsographStore => ({
16
+ Query: {
17
+ [ROOT_ID]: {
18
+ me: { __link: '0', __typename: 'Economist' },
19
+ you: { __link: '1', __typename: 'Economist' },
20
+ node____id___0: {
21
+ __link: '0',
22
+ __typename: 'Economist',
23
+ },
19
24
  },
20
25
  },
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' },
26
+ Economist: {
27
+ 0: {
28
+ __typename: 'Economist',
29
+ id: '0',
30
+ name: 'Jeremy Bentham',
31
+ successor: { __link: '1', __typename: 'Economist' },
32
+ },
33
+ 1: {
34
+ __typename: 'Economist',
35
+ id: '1',
36
+ name: 'John Stuart Mill',
37
+ predecessor: { __link: '0', __typename: 'Economist' },
38
+ successor: { __link: '2', __typename: 'Economist' },
39
+ },
40
+ 2: {
41
+ __typename: 'Economist',
42
+ id: '2',
43
+ name: 'Henry Sidgwick',
44
+ predecessor: { __link: '1', __typename: 'Economist' },
45
+ },
39
46
  },
40
47
  });
41
48
 
@@ -46,12 +53,13 @@ export const meNameField = iso(`
46
53
  }
47
54
  }
48
55
  `)(() => {});
49
- import meNameEntrypoint from './__isograph/Query/meName/entrypoint';
50
- import { meNameSuccessorRetainedQuery } from './meNameSuccessor';
51
- iso(`entrypoint Query.meName`);
56
+
57
+ const meNameEntrypoint = iso(`entrypoint Query.meName`);
52
58
  const meNameRetainedQuery = {
53
- normalizationAst: meNameEntrypoint.normalizationAst,
59
+ normalizationAst:
60
+ meNameEntrypoint.networkRequestInfo.normalizationAst.selections,
54
61
  variables: {},
62
+ root: { __link: ROOT_ID, __typename: 'Query' },
55
63
  };
56
64
 
57
65
  describe('garbage collection', () => {
@@ -63,13 +71,13 @@ describe('garbage collection', () => {
63
71
  null as any,
64
72
  );
65
73
 
66
- expect(store[1]).not.toBe(undefined);
74
+ expect(store.Economist?.[1]).not.toBe(undefined);
67
75
 
68
76
  // TODO enable babel so we don't have to do this
69
77
  retainQuery(environment, meNameRetainedQuery);
70
78
  garbageCollectEnvironment(environment);
71
79
 
72
- expect(store[1]).toBe(undefined);
80
+ expect(store.Economist?.[1]).toBe(undefined);
73
81
  });
74
82
 
75
83
  test('Referenced records should not be garbage collected', () => {
@@ -80,13 +88,13 @@ describe('garbage collection', () => {
80
88
  null as any,
81
89
  );
82
90
 
83
- expect(store[0]).not.toBe(undefined);
91
+ expect(store.Economist?.[0]).not.toBe(undefined);
84
92
 
85
93
  // TODO enable babel so we don't have to do this
86
94
  retainQuery(environment, meNameRetainedQuery);
87
95
  garbageCollectEnvironment(environment);
88
96
 
89
- expect(store[0]).not.toBe(undefined);
97
+ expect(store.Economist?.[0]).not.toBe(undefined);
90
98
  });
91
99
 
92
100
  test('Referenced records should not be garbage collected, and this should work with variables', () => {
@@ -97,12 +105,12 @@ describe('garbage collection', () => {
97
105
  null as any,
98
106
  );
99
107
 
100
- expect(store[0]).not.toBe(undefined);
108
+ expect(store.Economist?.[0]).not.toBe(undefined);
101
109
 
102
110
  retainQuery(environment, nodeFieldRetainedQuery);
103
111
  garbageCollectEnvironment(environment);
104
112
 
105
- expect(store[0]).not.toBe(undefined);
113
+ expect(store.Economist?.[0]).not.toBe(undefined);
106
114
  });
107
115
 
108
116
  test('Referenced records should not be garbage collected, and this should work through multiple levels', () => {
@@ -116,12 +124,12 @@ describe('garbage collection', () => {
116
124
  retainQuery(environment, meNameSuccessorRetainedQuery);
117
125
  garbageCollectEnvironment(environment);
118
126
 
119
- expect(store[0]).not.toBe(undefined);
120
- expect(store[1]).not.toBe(undefined);
121
- expect(store[2]).not.toBe(undefined);
127
+ expect(store.Economist?.[0]).not.toBe(undefined);
128
+ expect(store.Economist?.[1]).not.toBe(undefined);
129
+ expect(store.Economist?.[2]).not.toBe(undefined);
122
130
  });
123
131
 
124
- test('ROOT_ID should not be garbage collected, even if there are no retained queries', () => {
132
+ test('ROOT_ID should be garbage collected, if there are no retained queries', () => {
125
133
  const store = getDefaultStore();
126
134
  const environment = createIsographEnvironment(
127
135
  store,
@@ -130,7 +138,7 @@ describe('garbage collection', () => {
130
138
  );
131
139
  garbageCollectEnvironment(environment);
132
140
 
133
- expect(store[ROOT_ID]).not.toBe(undefined);
134
- expect(store[0]).toBe(undefined);
141
+ expect(store.Query?.[ROOT_ID]).toBe(undefined);
142
+ expect(store.Economist?.[0]).toBe(undefined);
135
143
  });
136
144
  });
@@ -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.selections,
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,10 @@ 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:
17
+ nodeFieldEntrypoint.networkRequestInfo.normalizationAst.selections,
16
18
  variables: { id: 0 },
19
+ root: { __link: ROOT_ID, __typename: 'Query' },
17
20
  };