@isograph/react 0.3.1 → 0.4.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-libs.log +5 -0
- package/dist/core/FragmentReference.d.ts +5 -5
- package/dist/core/FragmentReference.d.ts.map +1 -1
- package/dist/core/IsographEnvironment.d.ts +15 -10
- package/dist/core/IsographEnvironment.d.ts.map +1 -1
- package/dist/core/PromiseWrapper.d.ts +4 -4
- package/dist/core/PromiseWrapper.d.ts.map +1 -1
- package/dist/core/PromiseWrapper.js +2 -9
- package/dist/core/areEqualWithDeepComparison.d.ts +1 -3
- package/dist/core/areEqualWithDeepComparison.d.ts.map +1 -1
- package/dist/core/areEqualWithDeepComparison.js +0 -2
- package/dist/core/brand.d.ts +2 -0
- package/dist/core/brand.d.ts.map +1 -0
- package/dist/core/brand.js +2 -0
- package/dist/core/cache.d.ts +7 -6
- package/dist/core/cache.d.ts.map +1 -1
- package/dist/core/cache.js +57 -36
- package/dist/core/check.d.ts +3 -3
- package/dist/core/check.d.ts.map +1 -1
- package/dist/core/componentCache.d.ts.map +1 -1
- package/dist/core/componentCache.js +3 -2
- package/dist/core/entrypoint.d.ts +20 -2
- package/dist/core/entrypoint.d.ts.map +1 -1
- package/dist/core/garbageCollection.d.ts +2 -2
- package/dist/core/garbageCollection.d.ts.map +1 -1
- package/dist/core/logging.d.ts +13 -4
- package/dist/core/logging.d.ts.map +1 -1
- package/dist/core/makeNetworkRequest.d.ts +3 -3
- package/dist/core/makeNetworkRequest.d.ts.map +1 -1
- package/dist/core/makeNetworkRequest.js +15 -15
- package/dist/core/read.d.ts +8 -8
- package/dist/core/read.d.ts.map +1 -1
- package/dist/core/read.js +98 -29
- package/dist/core/reader.d.ts +12 -8
- package/dist/core/reader.d.ts.map +1 -1
- package/dist/core/startUpdate.d.ts +7 -4
- package/dist/core/startUpdate.d.ts.map +1 -1
- package/dist/core/startUpdate.js +153 -5
- package/dist/core/util.d.ts +2 -1
- package/dist/core/util.d.ts.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/loadable-hooks/useConnectionSpecPagination.d.ts.map +1 -1
- package/dist/loadable-hooks/useConnectionSpecPagination.js +1 -1
- package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts +1 -1
- package/dist/loadable-hooks/useImperativeExposedMutationField.d.ts.map +1 -1
- package/dist/loadable-hooks/useImperativeExposedMutationField.js +1 -1
- package/dist/loadable-hooks/useImperativeLoadableField.d.ts +1 -1
- 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.map +1 -1
- package/dist/loadable-hooks/useSkipLimitPagination.js +1 -1
- package/dist/react/FragmentReader.d.ts +7 -13
- package/dist/react/FragmentReader.d.ts.map +1 -1
- package/dist/react/FragmentReader.js +3 -30
- package/dist/react/FragmentRenderer.d.ts +15 -0
- package/dist/react/FragmentRenderer.d.ts.map +1 -0
- package/dist/react/FragmentRenderer.js +35 -0
- package/dist/react/LoadableFieldReader.d.ts +12 -0
- package/dist/react/LoadableFieldReader.d.ts.map +1 -0
- package/dist/react/LoadableFieldReader.js +10 -0
- package/dist/react/LoadableFieldRenderer.d.ts +13 -0
- package/dist/react/LoadableFieldRenderer.d.ts.map +1 -0
- package/dist/react/LoadableFieldRenderer.js +37 -0
- package/dist/react/useImperativeReference.d.ts.map +1 -1
- package/dist/react/useImperativeReference.js +6 -6
- package/dist/react/useResult.d.ts.map +1 -1
- package/dist/react/useResult.js +1 -1
- package/package.json +4 -5
- package/src/core/FragmentReference.ts +16 -7
- package/src/core/IsographEnvironment.ts +20 -10
- package/src/core/PromiseWrapper.ts +13 -16
- package/src/core/areEqualWithDeepComparison.ts +5 -5
- package/src/core/brand.ts +18 -0
- package/src/core/cache.ts +74 -51
- package/src/core/check.ts +4 -4
- package/src/core/componentCache.ts +7 -2
- package/src/core/entrypoint.ts +32 -5
- package/src/core/garbageCollection.ts +3 -3
- package/src/core/logging.ts +16 -4
- package/src/core/makeNetworkRequest.ts +48 -23
- package/src/core/read.ts +153 -48
- package/src/core/reader.ts +11 -7
- package/src/core/startUpdate.ts +313 -7
- package/src/core/util.ts +4 -2
- package/src/index.ts +11 -3
- package/src/loadable-hooks/useConnectionSpecPagination.ts +1 -0
- package/src/loadable-hooks/useImperativeExposedMutationField.ts +2 -2
- package/src/loadable-hooks/useImperativeLoadableField.ts +2 -2
- package/src/loadable-hooks/useSkipLimitPagination.ts +1 -0
- package/src/react/FragmentReader.tsx +23 -39
- package/src/react/FragmentRenderer.tsx +46 -0
- package/src/react/LoadableFieldReader.tsx +40 -0
- package/src/react/LoadableFieldRenderer.tsx +41 -0
- package/src/react/useImperativeReference.ts +9 -8
- package/src/react/useResult.ts +1 -0
- package/src/tests/__isograph/Economist/link/output_type.ts +2 -0
- package/src/tests/__isograph/Node/asEconomist/resolver_reader.ts +28 -0
- package/src/tests/__isograph/Node/link/output_type.ts +3 -0
- package/src/tests/__isograph/Query/linkedUpdate/entrypoint.ts +31 -0
- package/src/tests/__isograph/Query/linkedUpdate/normalization_ast.ts +95 -0
- package/src/tests/__isograph/Query/linkedUpdate/output_type.ts +3 -0
- package/src/tests/__isograph/Query/linkedUpdate/param_type.ts +51 -0
- package/src/tests/__isograph/Query/linkedUpdate/query_text.ts +20 -0
- package/src/tests/__isograph/Query/linkedUpdate/resolver_reader.ts +93 -0
- package/src/tests/__isograph/Query/meName/entrypoint.ts +4 -1
- package/src/tests/__isograph/Query/meName/query_text.ts +1 -1
- package/src/tests/__isograph/Query/meName/resolver_reader.ts +1 -0
- package/src/tests/__isograph/Query/meNameSuccessor/entrypoint.ts +4 -1
- package/src/tests/__isograph/Query/meNameSuccessor/query_text.ts +1 -1
- package/src/tests/__isograph/Query/meNameSuccessor/resolver_reader.ts +3 -0
- package/src/tests/__isograph/Query/nodeField/entrypoint.ts +4 -1
- package/src/tests/__isograph/Query/nodeField/query_text.ts +1 -1
- package/src/tests/__isograph/Query/nodeField/resolver_reader.ts +1 -0
- package/src/tests/__isograph/Query/startUpdate/entrypoint.ts +31 -0
- package/src/tests/__isograph/Query/startUpdate/normalization_ast.ts +51 -0
- package/src/tests/__isograph/Query/startUpdate/output_type.ts +3 -0
- package/src/tests/__isograph/Query/startUpdate/param_type.ts +26 -0
- package/src/tests/__isograph/Query/startUpdate/parameters_type.ts +3 -0
- package/src/tests/__isograph/Query/startUpdate/query_text.ts +11 -0
- package/src/tests/__isograph/Query/startUpdate/resolver_reader.ts +55 -0
- package/src/tests/__isograph/Query/subquery/entrypoint.ts +4 -1
- package/src/tests/__isograph/Query/subquery/query_text.ts +1 -1
- package/src/tests/__isograph/Query/subquery/resolver_reader.ts +2 -0
- package/src/tests/__isograph/iso.ts +21 -1
- package/src/tests/__isograph/tsconfig.json +8 -0
- package/src/tests/normalizeData.test.ts +0 -1
- package/src/tests/startUpdate.test.ts +205 -0
- package/.turbo/turbo-compile-typescript.log +0 -4
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import type { IsographEntrypoint } from '@isograph/react';
|
|
2
|
+
import { type Query__linkedUpdate__param } from './Query/linkedUpdate/param_type';
|
|
2
3
|
import { type Query__meNameSuccessor__param } from './Query/meNameSuccessor/param_type';
|
|
3
4
|
import { type Query__meName__param } from './Query/meName/param_type';
|
|
4
5
|
import { type Query__nodeField__param } from './Query/nodeField/param_type';
|
|
6
|
+
import { type Query__startUpdate__param } from './Query/startUpdate/param_type';
|
|
5
7
|
import { type Query__subquery__param } from './Query/subquery/param_type';
|
|
8
|
+
import entrypoint_Query__linkedUpdate from '../__isograph/Query/linkedUpdate/entrypoint';
|
|
6
9
|
import entrypoint_Query__meNameSuccessor from '../__isograph/Query/meNameSuccessor/entrypoint';
|
|
7
10
|
import entrypoint_Query__meName from '../__isograph/Query/meName/entrypoint';
|
|
8
11
|
import entrypoint_Query__nodeField from '../__isograph/Query/nodeField/entrypoint';
|
|
12
|
+
import entrypoint_Query__startUpdate from '../__isograph/Query/startUpdate/entrypoint';
|
|
9
13
|
import entrypoint_Query__subquery from '../__isograph/Query/subquery/entrypoint';
|
|
10
14
|
|
|
11
15
|
// This is the type given to regular client fields.
|
|
12
16
|
// This means that the type of the exported iso literal is exactly
|
|
13
17
|
// the type of the passed-in function, which takes one parameter
|
|
14
18
|
// of type TParam.
|
|
15
|
-
type IdentityWithParam<TParam extends object> = <TClientFieldReturn>(
|
|
19
|
+
type IdentityWithParam<TParam extends object, TReturnConstraint = unknown> = <TClientFieldReturn extends TReturnConstraint>(
|
|
16
20
|
clientField: (param: TParam) => TClientFieldReturn
|
|
17
21
|
) => (param: TParam) => TClientFieldReturn;
|
|
18
22
|
|
|
@@ -56,6 +60,10 @@ type MatchesWhitespaceAndString<
|
|
|
56
60
|
T
|
|
57
61
|
> = Whitespace<T> extends `${TString}${string}` ? T : never;
|
|
58
62
|
|
|
63
|
+
export function iso<T>(
|
|
64
|
+
param: T & MatchesWhitespaceAndString<'field Query.linkedUpdate', T>
|
|
65
|
+
): IdentityWithParam<Query__linkedUpdate__param>;
|
|
66
|
+
|
|
59
67
|
export function iso<T>(
|
|
60
68
|
param: T & MatchesWhitespaceAndString<'field Query.meNameSuccessor', T>
|
|
61
69
|
): IdentityWithParam<Query__meNameSuccessor__param>;
|
|
@@ -68,10 +76,18 @@ export function iso<T>(
|
|
|
68
76
|
param: T & MatchesWhitespaceAndString<'field Query.nodeField', T>
|
|
69
77
|
): IdentityWithParam<Query__nodeField__param>;
|
|
70
78
|
|
|
79
|
+
export function iso<T>(
|
|
80
|
+
param: T & MatchesWhitespaceAndString<'field Query.startUpdate', T>
|
|
81
|
+
): IdentityWithParam<Query__startUpdate__param>;
|
|
82
|
+
|
|
71
83
|
export function iso<T>(
|
|
72
84
|
param: T & MatchesWhitespaceAndString<'field Query.subquery', T>
|
|
73
85
|
): IdentityWithParam<Query__subquery__param>;
|
|
74
86
|
|
|
87
|
+
export function iso<T>(
|
|
88
|
+
param: T & MatchesWhitespaceAndString<'entrypoint Query.linkedUpdate', T>
|
|
89
|
+
): typeof entrypoint_Query__linkedUpdate;
|
|
90
|
+
|
|
75
91
|
export function iso<T>(
|
|
76
92
|
param: T & MatchesWhitespaceAndString<'entrypoint Query.meNameSuccessor', T>
|
|
77
93
|
): typeof entrypoint_Query__meNameSuccessor;
|
|
@@ -84,6 +100,10 @@ export function iso<T>(
|
|
|
84
100
|
param: T & MatchesWhitespaceAndString<'entrypoint Query.nodeField', T>
|
|
85
101
|
): typeof entrypoint_Query__nodeField;
|
|
86
102
|
|
|
103
|
+
export function iso<T>(
|
|
104
|
+
param: T & MatchesWhitespaceAndString<'entrypoint Query.startUpdate', T>
|
|
105
|
+
): typeof entrypoint_Query__startUpdate;
|
|
106
|
+
|
|
87
107
|
export function iso<T>(
|
|
88
108
|
param: T & MatchesWhitespaceAndString<'entrypoint Query.subquery', T>
|
|
89
109
|
): typeof entrypoint_Query__subquery;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import { getOrCreateCacheForArtifact } from '../core/cache';
|
|
3
|
+
import type { ExtractUpdatableData } from '../core/FragmentReference';
|
|
4
|
+
import {
|
|
5
|
+
createIsographEnvironment,
|
|
6
|
+
ROOT_ID,
|
|
7
|
+
type IsographStore,
|
|
8
|
+
} from '../core/IsographEnvironment';
|
|
9
|
+
import { createUpdatableProxy } from '../core/startUpdate';
|
|
10
|
+
import { iso } from './__isograph/iso';
|
|
11
|
+
import type { Query__linkedUpdate__param } from './__isograph/Query/linkedUpdate/param_type';
|
|
12
|
+
import type { Query__startUpdate__param } from './__isograph/Query/startUpdate/param_type';
|
|
13
|
+
|
|
14
|
+
const getDefaultStore = (): IsographStore => ({
|
|
15
|
+
Query: {
|
|
16
|
+
[ROOT_ID]: {
|
|
17
|
+
node____id___0: {
|
|
18
|
+
__link: '0',
|
|
19
|
+
__typename: 'Economist',
|
|
20
|
+
},
|
|
21
|
+
node____id___1: {
|
|
22
|
+
__link: '1',
|
|
23
|
+
__typename: 'Economist',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
Economist: {
|
|
28
|
+
0: {
|
|
29
|
+
__typename: 'Economist',
|
|
30
|
+
id: '0',
|
|
31
|
+
name: 'Jeremy Bentham',
|
|
32
|
+
},
|
|
33
|
+
1: {
|
|
34
|
+
__typename: 'Economist',
|
|
35
|
+
id: '1',
|
|
36
|
+
name: 'John Stuart Mill',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const startUpdate = iso(`
|
|
42
|
+
field Query.startUpdate($id: ID!) {
|
|
43
|
+
node(id: $id) {
|
|
44
|
+
asEconomist {
|
|
45
|
+
name @updatable
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
`)(() => {});
|
|
50
|
+
|
|
51
|
+
export const linkedUpdate = iso(`
|
|
52
|
+
field Query.linkedUpdate {
|
|
53
|
+
node(id: 0) @updatable {
|
|
54
|
+
asEconomist {
|
|
55
|
+
name @updatable
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
john_stuart_mill: node(id: 1) {
|
|
59
|
+
link
|
|
60
|
+
asEconomist {
|
|
61
|
+
name
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
`)(() => {});
|
|
66
|
+
|
|
67
|
+
describe('startUpdate', () => {
|
|
68
|
+
let environment: ReturnType<typeof createIsographEnvironment>;
|
|
69
|
+
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
const store = getDefaultStore();
|
|
72
|
+
const networkFunction = vi
|
|
73
|
+
.fn()
|
|
74
|
+
.mockRejectedValue(new Error('Fetch failed'));
|
|
75
|
+
environment = createIsographEnvironment(store, networkFunction);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('linked field', () => {
|
|
79
|
+
let data: ExtractUpdatableData<Query__linkedUpdate__param>;
|
|
80
|
+
|
|
81
|
+
beforeEach(() => {
|
|
82
|
+
const [_cacheItem, item, _disposeOfTemporaryRetain] =
|
|
83
|
+
getOrCreateCacheForArtifact(
|
|
84
|
+
environment,
|
|
85
|
+
iso(`entrypoint Query.linkedUpdate`),
|
|
86
|
+
{},
|
|
87
|
+
).getOrPopulateAndTemporaryRetain();
|
|
88
|
+
|
|
89
|
+
data = createUpdatableProxy(
|
|
90
|
+
environment,
|
|
91
|
+
item,
|
|
92
|
+
{
|
|
93
|
+
suspendIfInFlight: true,
|
|
94
|
+
throwOnNetworkError: true,
|
|
95
|
+
},
|
|
96
|
+
new Map(),
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('updates updatable scalar nested in updatable object', () => {
|
|
101
|
+
data.node!.asEconomist!.name = 'Updated Jeremy Bentham';
|
|
102
|
+
|
|
103
|
+
expect(environment.store).toMatchObject({
|
|
104
|
+
Economist: {
|
|
105
|
+
'0': {
|
|
106
|
+
name: 'Updated Jeremy Bentham',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('updates linked field in data', () => {
|
|
113
|
+
data.node = data.john_stuart_mill;
|
|
114
|
+
|
|
115
|
+
expect(data).toMatchObject({
|
|
116
|
+
node: {
|
|
117
|
+
asEconomist: {
|
|
118
|
+
name: 'John Stuart Mill',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('updates scalar in old object after setting linked field', () => {
|
|
125
|
+
let jeremy = data.node;
|
|
126
|
+
data.node = data.john_stuart_mill;
|
|
127
|
+
jeremy!.asEconomist!.name = 'Updated Jeremy Bentham';
|
|
128
|
+
|
|
129
|
+
expect(environment.store).toMatchObject({
|
|
130
|
+
Economist: {
|
|
131
|
+
'0': {
|
|
132
|
+
name: 'Updated Jeremy Bentham',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
Query: {
|
|
136
|
+
__ROOT: {
|
|
137
|
+
node____id___0: {
|
|
138
|
+
__link: '1',
|
|
139
|
+
__typename: 'Economist',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe('scalar field', () => {
|
|
148
|
+
let data: ExtractUpdatableData<Query__startUpdate__param>;
|
|
149
|
+
|
|
150
|
+
beforeEach(() => {
|
|
151
|
+
const [_cacheItem, item, _disposeOfTemporaryRetain] =
|
|
152
|
+
getOrCreateCacheForArtifact(
|
|
153
|
+
environment,
|
|
154
|
+
iso(`entrypoint Query.startUpdate`),
|
|
155
|
+
{
|
|
156
|
+
id: '0',
|
|
157
|
+
},
|
|
158
|
+
).getOrPopulateAndTemporaryRetain();
|
|
159
|
+
|
|
160
|
+
data = createUpdatableProxy(
|
|
161
|
+
environment,
|
|
162
|
+
item,
|
|
163
|
+
{
|
|
164
|
+
suspendIfInFlight: true,
|
|
165
|
+
throwOnNetworkError: true,
|
|
166
|
+
},
|
|
167
|
+
new Map(),
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('reads data', () => {
|
|
172
|
+
expect(data).toStrictEqual({
|
|
173
|
+
node: {
|
|
174
|
+
asEconomist: {
|
|
175
|
+
name: 'Jeremy Bentham',
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('updates scalar in cache', () => {
|
|
182
|
+
data.node!.asEconomist!.name = 'Foo';
|
|
183
|
+
|
|
184
|
+
expect(environment.store).toMatchObject({
|
|
185
|
+
Economist: {
|
|
186
|
+
0: {
|
|
187
|
+
name: 'Foo',
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('updates scalar in data', () => {
|
|
194
|
+
data.node!.asEconomist!.name = 'Foo';
|
|
195
|
+
|
|
196
|
+
expect(data).toStrictEqual({
|
|
197
|
+
node: {
|
|
198
|
+
asEconomist: {
|
|
199
|
+
name: 'Foo',
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|