@isograph/react 0.0.0-main-a779c3fa → 0.0.0-main-e7ae4c32
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/read.js +27 -0
- package/dist/core/reader.d.ts +4 -0
- package/package.json +4 -4
- package/src/core/read.ts +37 -0
- package/src/core/reader.ts +4 -0
- package/src/tests/__isograph/Query/meName/resolver_reader.ts +1 -0
- package/src/tests/__isograph/Query/meNameSuccessor/resolver_reader.ts +3 -0
- package/src/tests/__isograph/Query/nodeField/resolver_reader.ts +1 -0
package/dist/core/read.js
CHANGED
|
@@ -124,6 +124,33 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
124
124
|
break;
|
|
125
125
|
}
|
|
126
126
|
let link = (0, IsographEnvironment_1.assertLink)(value);
|
|
127
|
+
if (field.condition) {
|
|
128
|
+
const data = readData(environment, field.condition.readerAst, root, variables, nestedRefetchQueries, networkRequest, networkRequestOptions, mutableEncounteredRecords);
|
|
129
|
+
if (data.kind === 'MissingData') {
|
|
130
|
+
return {
|
|
131
|
+
kind: 'MissingData',
|
|
132
|
+
reason: 'Missing data for ' +
|
|
133
|
+
storeRecordName +
|
|
134
|
+
' on root ' +
|
|
135
|
+
root.__link,
|
|
136
|
+
nestedReason: data,
|
|
137
|
+
recordLink: data.recordLink,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const condition = field.condition.resolver({
|
|
141
|
+
data: data.data,
|
|
142
|
+
parameters: {},
|
|
143
|
+
});
|
|
144
|
+
if (condition === true) {
|
|
145
|
+
link = root;
|
|
146
|
+
}
|
|
147
|
+
else if (condition === false) {
|
|
148
|
+
link = null;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
link = condition;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
127
154
|
if (link === undefined) {
|
|
128
155
|
// TODO make this configurable, and also generated and derived from the schema
|
|
129
156
|
const missingFieldHandler = (_c = environment.missingFieldHandler) !== null && _c !== void 0 ? _c : IsographEnvironment_1.defaultMissingFieldHandler;
|
package/dist/core/reader.d.ts
CHANGED
|
@@ -51,6 +51,10 @@ export type ReaderLinkedField = {
|
|
|
51
51
|
readonly alias: string | null;
|
|
52
52
|
readonly selections: ReaderAst<unknown>;
|
|
53
53
|
readonly arguments: Arguments | null;
|
|
54
|
+
readonly condition: EagerReaderArtifact<{
|
|
55
|
+
data: object;
|
|
56
|
+
parameters: object;
|
|
57
|
+
}, boolean | Link | null> | null;
|
|
54
58
|
};
|
|
55
59
|
export type ReaderNonLoadableResolverField = {
|
|
56
60
|
readonly kind: 'Resolver';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isograph/react",
|
|
3
|
-
"version": "0.0.0-main-
|
|
3
|
+
"version": "0.0.0-main-e7ae4c32",
|
|
4
4
|
"description": "Use Isograph with React",
|
|
5
5
|
"homepage": "https://isograph.dev",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"iso-watch": "../../target/debug/isograph_cli --config ./isograph.config.json --watch"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@isograph/disposable-types": "0.0.0-main-
|
|
23
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
|
24
|
-
"@isograph/reference-counted-pointer": "0.0.0-main-
|
|
22
|
+
"@isograph/disposable-types": "0.0.0-main-e7ae4c32",
|
|
23
|
+
"@isograph/react-disposable-state": "0.0.0-main-e7ae4c32",
|
|
24
|
+
"@isograph/reference-counted-pointer": "0.0.0-main-e7ae4c32"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "18.3.1"
|
package/src/core/read.ts
CHANGED
|
@@ -209,6 +209,43 @@ function readData<TReadFromStore>(
|
|
|
209
209
|
break;
|
|
210
210
|
}
|
|
211
211
|
let link = assertLink(value);
|
|
212
|
+
|
|
213
|
+
if (field.condition) {
|
|
214
|
+
const data = readData(
|
|
215
|
+
environment,
|
|
216
|
+
field.condition.readerAst,
|
|
217
|
+
root,
|
|
218
|
+
variables,
|
|
219
|
+
nestedRefetchQueries,
|
|
220
|
+
networkRequest,
|
|
221
|
+
networkRequestOptions,
|
|
222
|
+
mutableEncounteredRecords,
|
|
223
|
+
);
|
|
224
|
+
if (data.kind === 'MissingData') {
|
|
225
|
+
return {
|
|
226
|
+
kind: 'MissingData',
|
|
227
|
+
reason:
|
|
228
|
+
'Missing data for ' +
|
|
229
|
+
storeRecordName +
|
|
230
|
+
' on root ' +
|
|
231
|
+
root.__link,
|
|
232
|
+
nestedReason: data,
|
|
233
|
+
recordLink: data.recordLink,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const condition = field.condition.resolver({
|
|
237
|
+
data: data.data,
|
|
238
|
+
parameters: {},
|
|
239
|
+
});
|
|
240
|
+
if (condition === true) {
|
|
241
|
+
link = root;
|
|
242
|
+
} else if (condition === false) {
|
|
243
|
+
link = null;
|
|
244
|
+
} else {
|
|
245
|
+
link = condition;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
212
249
|
if (link === undefined) {
|
|
213
250
|
// TODO make this configurable, and also generated and derived from the schema
|
|
214
251
|
const missingFieldHandler =
|
package/src/core/reader.ts
CHANGED
|
@@ -96,6 +96,10 @@ export type ReaderLinkedField = {
|
|
|
96
96
|
readonly alias: string | null;
|
|
97
97
|
readonly selections: ReaderAst<unknown>;
|
|
98
98
|
readonly arguments: Arguments | null;
|
|
99
|
+
readonly condition: EagerReaderArtifact<
|
|
100
|
+
{ data: object; parameters: object },
|
|
101
|
+
boolean | Link | null
|
|
102
|
+
> | null;
|
|
99
103
|
};
|
|
100
104
|
|
|
101
105
|
export type ReaderNonLoadableResolverField = {
|
|
@@ -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",
|