@isograph/react 0.0.0-main-fbe23de7 → 0.0.0-main-d3ef6e33
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 +45 -25
- package/package.json +3 -3
- package/src/core/read.ts +59 -37
package/dist/core/read.js
CHANGED
@@ -228,31 +228,37 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
228
228
|
};
|
229
229
|
}
|
230
230
|
else {
|
231
|
-
target[field.alias] = (args) =>
|
232
|
-
//
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
231
|
+
target[field.alias] = (args) => {
|
232
|
+
// TODO we should use the reader AST for this
|
233
|
+
const includeReadOutData = (variables, readOutData) => {
|
234
|
+
variables.id = readOutData.id;
|
235
|
+
return variables;
|
236
|
+
};
|
237
|
+
const localVariables = includeReadOutData(args !== null && args !== void 0 ? args : {}, refetchReaderParams.data);
|
238
|
+
writeQueryArgsToVariables(localVariables, field.queryArguments, variables);
|
239
|
+
return [
|
240
|
+
// Stable id
|
241
|
+
root +
|
242
|
+
'/' +
|
243
|
+
field.name +
|
244
|
+
'/' +
|
245
|
+
stableStringifyArgs(localVariables),
|
246
|
+
// Fetcher
|
247
|
+
() => {
|
248
|
+
const [networkRequest, disposeNetworkRequest] = (0, makeNetworkRequest_1.makeNetworkRequest)(environment, field.entrypoint, localVariables);
|
249
|
+
const fragmentReference = {
|
250
|
+
kind: 'FragmentReference',
|
251
|
+
readerArtifact: field.entrypoint.readerArtifact,
|
252
|
+
// TODO localVariables is not guaranteed to have an id field
|
253
|
+
root: localVariables.id,
|
254
|
+
variables: localVariables,
|
255
|
+
nestedRefetchQueries: field.entrypoint.nestedRefetchQueries,
|
256
|
+
networkRequest,
|
257
|
+
};
|
258
|
+
return [fragmentReference, disposeNetworkRequest];
|
259
|
+
},
|
260
|
+
];
|
261
|
+
};
|
256
262
|
}
|
257
263
|
break;
|
258
264
|
}
|
@@ -323,3 +329,17 @@ function writeQueryArgsToVariables(targetVariables, queryArgs, variables) {
|
|
323
329
|
}
|
324
330
|
}
|
325
331
|
}
|
332
|
+
// TODO use a description of the params for this?
|
333
|
+
// TODO call stableStringifyArgs on the variable values, as well.
|
334
|
+
// This doesn't matter for now, since we are just using primitive values
|
335
|
+
// in the demo.
|
336
|
+
function stableStringifyArgs(args) {
|
337
|
+
const keys = Object.keys(args);
|
338
|
+
keys.sort();
|
339
|
+
let s = '';
|
340
|
+
for (const key of keys) {
|
341
|
+
// @ts-expect-error
|
342
|
+
s += `${key}=${JSON.stringify(args[key])};`;
|
343
|
+
}
|
344
|
+
return s;
|
345
|
+
}
|
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-d3ef6e33",
|
4
4
|
"description": "Use Isograph with React",
|
5
5
|
"homepage": "https://isograph.dev",
|
6
6
|
"main": "dist/index.js",
|
@@ -17,8 +17,8 @@
|
|
17
17
|
"tsc": "tsc"
|
18
18
|
},
|
19
19
|
"dependencies": {
|
20
|
-
"@isograph/disposable-types": "0.0.0-main-
|
21
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
20
|
+
"@isograph/disposable-types": "0.0.0-main-d3ef6e33",
|
21
|
+
"@isograph/react-disposable-state": "0.0.0-main-d3ef6e33",
|
22
22
|
"react": "^18.2.0"
|
23
23
|
},
|
24
24
|
"devDependencies": {
|
package/src/core/read.ts
CHANGED
@@ -338,43 +338,50 @@ function readData<TReadFromStore>(
|
|
338
338
|
nestedReason: refetchReaderParams,
|
339
339
|
};
|
340
340
|
} else {
|
341
|
-
target[field.alias] = (args: any) =>
|
342
|
-
//
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
341
|
+
target[field.alias] = (args: any) => {
|
342
|
+
// TODO we should use the reader AST for this
|
343
|
+
const includeReadOutData = (variables: any, readOutData: any) => {
|
344
|
+
variables.id = readOutData.id;
|
345
|
+
return variables;
|
346
|
+
};
|
347
|
+
const localVariables = includeReadOutData(
|
348
|
+
args ?? {},
|
349
|
+
refetchReaderParams.data,
|
350
|
+
);
|
351
|
+
writeQueryArgsToVariables(
|
352
|
+
localVariables,
|
353
|
+
field.queryArguments,
|
354
|
+
variables,
|
355
|
+
);
|
356
|
+
|
357
|
+
return [
|
358
|
+
// Stable id
|
359
|
+
root +
|
360
|
+
'/' +
|
361
|
+
field.name +
|
362
|
+
'/' +
|
363
|
+
stableStringifyArgs(localVariables),
|
364
|
+
// Fetcher
|
365
|
+
() => {
|
366
|
+
const [networkRequest, disposeNetworkRequest] =
|
367
|
+
makeNetworkRequest(
|
368
|
+
environment,
|
369
|
+
field.entrypoint,
|
370
|
+
localVariables,
|
371
|
+
);
|
372
|
+
const fragmentReference = {
|
373
|
+
kind: 'FragmentReference',
|
374
|
+
readerArtifact: field.entrypoint.readerArtifact,
|
375
|
+
// TODO localVariables is not guaranteed to have an id field
|
376
|
+
root: localVariables.id,
|
377
|
+
variables: localVariables,
|
378
|
+
nestedRefetchQueries: field.entrypoint.nestedRefetchQueries,
|
379
|
+
networkRequest,
|
380
|
+
} as FragmentReference<any, any>;
|
381
|
+
return [fragmentReference, disposeNetworkRequest];
|
382
|
+
},
|
383
|
+
];
|
384
|
+
};
|
378
385
|
}
|
379
386
|
break;
|
380
387
|
}
|
@@ -464,3 +471,18 @@ export type NetworkRequestReaderOptions = {
|
|
464
471
|
suspendIfInFlight?: boolean;
|
465
472
|
throwOnNetworkError?: boolean;
|
466
473
|
};
|
474
|
+
|
475
|
+
// TODO use a description of the params for this?
|
476
|
+
// TODO call stableStringifyArgs on the variable values, as well.
|
477
|
+
// This doesn't matter for now, since we are just using primitive values
|
478
|
+
// in the demo.
|
479
|
+
function stableStringifyArgs(args: Object) {
|
480
|
+
const keys = Object.keys(args);
|
481
|
+
keys.sort();
|
482
|
+
let s = '';
|
483
|
+
for (const key of keys) {
|
484
|
+
// @ts-expect-error
|
485
|
+
s += `${key}=${JSON.stringify(args[key])};`;
|
486
|
+
}
|
487
|
+
return s;
|
488
|
+
}
|