@isograph/react 0.0.0-main-05f9fa46 → 0.0.0-main-0300c896
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 +1 -1
- package/dist/core/FragmentReference.d.ts +3 -3
- package/dist/core/FragmentReference.d.ts.map +1 -1
- package/dist/core/cache.d.ts +1 -0
- package/dist/core/cache.d.ts.map +1 -1
- package/dist/core/cache.js +1 -0
- package/dist/core/componentCache.d.ts.map +1 -1
- package/dist/core/componentCache.js +1 -1
- package/dist/core/makeNetworkRequest.js +1 -1
- package/dist/core/read.d.ts +1 -1
- package/dist/core/read.d.ts.map +1 -1
- package/dist/core/read.js +4 -4
- package/dist/core/startUpdate.d.ts +7 -4
- package/dist/core/startUpdate.d.ts.map +1 -1
- package/dist/core/startUpdate.js +144 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/loadable-hooks/useConnectionSpecPagination.d.ts.map +1 -1
- package/dist/loadable-hooks/useConnectionSpecPagination.js +1 -1
- package/dist/loadable-hooks/useSkipLimitPagination.d.ts.map +1 -1
- package/dist/loadable-hooks/useSkipLimitPagination.js +1 -1
- package/dist/react/useResult.d.ts.map +1 -1
- package/dist/react/useResult.js +1 -1
- package/package.json +4 -4
- package/src/core/FragmentReference.ts +8 -5
- package/src/core/cache.ts +1 -1
- package/src/core/componentCache.ts +5 -1
- package/src/core/makeNetworkRequest.ts +1 -0
- package/src/core/read.ts +4 -0
- package/src/core/startUpdate.ts +304 -7
- package/src/index.ts +1 -0
- package/src/loadable-hooks/useConnectionSpecPagination.ts +1 -0
- package/src/loadable-hooks/useSkipLimitPagination.ts +1 -0
- package/src/react/useResult.ts +1 -0
- package/src/tests/__isograph/Node/asEconomist/resolver_reader.ts +28 -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/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/iso.ts +20 -0
- package/src/tests/startUpdate.test.ts +205 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type {IsographEntrypoint, NormalizationAst, RefetchQueryNormalizationArtifactWrapper} from '@isograph/react';
|
|
2
|
+
import {Query__startUpdate__param} from './param_type';
|
|
3
|
+
import {Query__startUpdate__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__startUpdate__param,
|
|
11
|
+
Query__startUpdate__output_type,
|
|
12
|
+
NormalizationAst
|
|
13
|
+
> = {
|
|
14
|
+
kind: "Entrypoint",
|
|
15
|
+
networkRequestInfo: {
|
|
16
|
+
kind: "NetworkRequestInfo",
|
|
17
|
+
operation: {
|
|
18
|
+
kind: "Operation",
|
|
19
|
+
text: queryText,
|
|
20
|
+
},
|
|
21
|
+
normalizationAst,
|
|
22
|
+
},
|
|
23
|
+
concreteType: "Query",
|
|
24
|
+
readerWithRefetchQueries: {
|
|
25
|
+
kind: "ReaderWithRefetchQueries",
|
|
26
|
+
nestedRefetchQueries,
|
|
27
|
+
readerArtifact: readerResolver,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default artifact;
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
kind: "InlineFragment",
|
|
28
|
+
type: "Economist",
|
|
29
|
+
selections: [
|
|
30
|
+
{
|
|
31
|
+
kind: "Scalar",
|
|
32
|
+
fieldName: "__typename",
|
|
33
|
+
arguments: null,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
kind: "Scalar",
|
|
37
|
+
fieldName: "id",
|
|
38
|
+
arguments: null,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
kind: "Scalar",
|
|
42
|
+
fieldName: "name",
|
|
43
|
+
arguments: null,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
export default normalizationAst;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StartUpdate } from '@isograph/react';
|
|
2
|
+
import type { Query__startUpdate__parameters } from './parameters_type';
|
|
3
|
+
|
|
4
|
+
export type Query__startUpdate__param = {
|
|
5
|
+
readonly data: {
|
|
6
|
+
readonly node: ({
|
|
7
|
+
/**
|
|
8
|
+
A client pointer for the Economist type.
|
|
9
|
+
*/
|
|
10
|
+
readonly asEconomist: ({
|
|
11
|
+
readonly name: string,
|
|
12
|
+
} | null),
|
|
13
|
+
} | null),
|
|
14
|
+
},
|
|
15
|
+
readonly parameters: Query__startUpdate__parameters,
|
|
16
|
+
readonly startUpdate: StartUpdate<{
|
|
17
|
+
readonly node: ({
|
|
18
|
+
/**
|
|
19
|
+
A client pointer for the Economist type.
|
|
20
|
+
*/
|
|
21
|
+
readonly asEconomist: ({
|
|
22
|
+
name: string,
|
|
23
|
+
} | null),
|
|
24
|
+
} | null),
|
|
25
|
+
}>,
|
|
26
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { EagerReaderArtifact, ReaderAst } from '@isograph/react';
|
|
2
|
+
import { Query__startUpdate__param } from './param_type';
|
|
3
|
+
import { Query__startUpdate__output_type } from './output_type';
|
|
4
|
+
import { startUpdate as resolver } from '../../../startUpdate.test';
|
|
5
|
+
import Node__asEconomist__resolver_reader from '../../Node/asEconomist/resolver_reader';
|
|
6
|
+
|
|
7
|
+
const readerAst: ReaderAst<Query__startUpdate__param> = [
|
|
8
|
+
{
|
|
9
|
+
kind: "Linked",
|
|
10
|
+
fieldName: "node",
|
|
11
|
+
alias: null,
|
|
12
|
+
arguments: [
|
|
13
|
+
[
|
|
14
|
+
"id",
|
|
15
|
+
{ kind: "Variable", name: "id" },
|
|
16
|
+
],
|
|
17
|
+
],
|
|
18
|
+
condition: null,
|
|
19
|
+
isUpdatable: false,
|
|
20
|
+
selections: [
|
|
21
|
+
{
|
|
22
|
+
kind: "Linked",
|
|
23
|
+
fieldName: "asEconomist",
|
|
24
|
+
alias: null,
|
|
25
|
+
arguments: null,
|
|
26
|
+
condition: Node__asEconomist__resolver_reader,
|
|
27
|
+
isUpdatable: false,
|
|
28
|
+
selections: [
|
|
29
|
+
{
|
|
30
|
+
kind: "Scalar",
|
|
31
|
+
fieldName: "name",
|
|
32
|
+
alias: null,
|
|
33
|
+
arguments: null,
|
|
34
|
+
isUpdatable: true,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
refetchQueryIndex: null,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
refetchQueryIndex: null,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const artifact: EagerReaderArtifact<
|
|
45
|
+
Query__startUpdate__param,
|
|
46
|
+
Query__startUpdate__output_type
|
|
47
|
+
> = {
|
|
48
|
+
kind: "EagerReaderArtifact",
|
|
49
|
+
fieldName: "Query.startUpdate",
|
|
50
|
+
resolver,
|
|
51
|
+
readerAst,
|
|
52
|
+
hasUpdatable: true,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default artifact;
|
|
@@ -1,11 +1,15 @@
|
|
|
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.
|
|
@@ -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
|
+
});
|