@isograph/react 0.0.0-main-684823b0 → 0.0.0-main-33a95299

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/read.js CHANGED
@@ -133,6 +133,8 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, mutab
133
133
  break;
134
134
  }
135
135
  case 'ImperativelyLoadedField': {
136
+ // First, we read the data using the refetch reader AST (i.e. read out the
137
+ // id field).
136
138
  const data = readData(environment, field.refetchReaderArtifact.readerAst, root, variables,
137
139
  // Refetch fields just read the id, and don't need refetch query artifacts
138
140
  [], mutableEncounteredRecords);
@@ -151,11 +153,13 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, mutab
151
153
  const refetchQuery = nestedRefetchQueries[refetchQueryIndex];
152
154
  const refetchQueryArtifact = refetchQuery.artifact;
153
155
  const allowedVariables = refetchQuery.allowedVariables;
156
+ // Second, we allow the user to call the resolver, which will ultimately
157
+ // use the resolver reader AST to get the resolver parameters.
154
158
  target[field.alias] = [
155
159
  // DataId
156
160
  root + '__' + field.name,
157
161
  // Fetcher
158
- field.refetchReaderArtifact.resolver(environment, refetchQueryArtifact, data.data, filterVariables(variables, allowedVariables), root, field.resolverReaderArtifact),
162
+ field.refetchReaderArtifact.resolver(environment, refetchQueryArtifact, data.data, filterVariables(variables, allowedVariables), root, field.resolverReaderArtifact, field.usedRefetchQueries.map((id) => nestedRefetchQueries[id])),
159
163
  ];
160
164
  }
161
165
  break;
package/dist/reader.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { ItemCleanupPair } from '@isograph/disposable-types';
3
3
  import { FragmentReference } from './FragmentReference';
4
4
  import { ComponentOrFieldName, DataId, IsographEnvironment } from './IsographEnvironment';
5
- import { RefetchQueryNormalizationArtifact } from './entrypoint';
5
+ import { RefetchQueryNormalizationArtifact, RefetchQueryNormalizationArtifactWrapper } from './entrypoint';
6
6
  import { Arguments } from './util';
7
7
  export type TopLevelReaderArtifact<TReadFromStore extends Object, TClientFieldValue, TComponentProps extends Record<string, never>> = EagerReaderArtifact<TReadFromStore, TClientFieldValue> | ComponentReaderArtifact<TReadFromStore, TComponentProps>;
8
8
  export type EagerReaderArtifact<TReadFromStore extends Object, TClientFieldValue> = {
@@ -19,12 +19,12 @@ export type ComponentReaderArtifact<TReadFromStore extends Object, TComponentPro
19
19
  export type RefetchReaderArtifact = {
20
20
  readonly kind: 'RefetchReaderArtifact';
21
21
  readonly readerAst: ReaderAst<unknown>;
22
- readonly resolver: (environment: IsographEnvironment, artifact: RefetchQueryNormalizationArtifact, variables: any, filteredVariables: any, rootId: DataId, readerArtifact: TopLevelReaderArtifact<any, any, any> | null) => () => void;
22
+ readonly resolver: (environment: IsographEnvironment, artifact: RefetchQueryNormalizationArtifact, variables: any, filteredVariables: any, rootId: DataId, readerArtifact: TopLevelReaderArtifact<any, any, any> | null, nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[]) => () => void;
23
23
  };
24
24
  export type MutationReaderArtifact<TReadFromStore extends Object> = {
25
25
  readonly kind: 'MutationReaderArtifact';
26
26
  readonly readerAst: ReaderAst<unknown>;
27
- readonly resolver: (environment: IsographEnvironment, entrypoint: RefetchQueryNormalizationArtifact, readOutData: TReadFromStore, filteredVariables: any, rootId: DataId, readerArtifact: TopLevelReaderArtifact<any, any, any> | null) => (mutationParams: any) => void;
27
+ readonly resolver: (environment: IsographEnvironment, entrypoint: RefetchQueryNormalizationArtifact, readOutData: TReadFromStore, filteredVariables: any, rootId: DataId, readerArtifact: TopLevelReaderArtifact<any, any, any> | null, nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[]) => (mutationParams: any) => void;
28
28
  };
29
29
  export type ReaderAstNode = ReaderScalarField | ReaderLinkedField | ReaderResolverField | ReaderImperativelyLoadedField;
30
30
  export type ReaderAst<TReadFromStore> = ReadonlyArray<ReaderAstNode>;
@@ -55,6 +55,7 @@ export type ReaderImperativelyLoadedField = {
55
55
  readonly resolverReaderArtifact: TopLevelReaderArtifact<any, any, any> | null;
56
56
  readonly refetchQuery: number;
57
57
  readonly name: string;
58
+ readonly usedRefetchQueries: number[];
58
59
  };
59
60
  export type LoadableField<T> = [
60
61
  string,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isograph/react",
3
- "version": "0.0.0-main-684823b0",
3
+ "version": "0.0.0-main-33a95299",
4
4
  "description": "Use Isograph with React",
5
5
  "homepage": "https://isograph.dev",
6
6
  "main": "dist/index.js",
@@ -16,8 +16,8 @@
16
16
  "prepack": "yarn run test && yarn run compile"
17
17
  },
18
18
  "dependencies": {
19
- "@isograph/disposable-types": "0.0.0-main-684823b0",
20
- "@isograph/react-disposable-state": "0.0.0-main-684823b0",
19
+ "@isograph/disposable-types": "0.0.0-main-33a95299",
20
+ "@isograph/react-disposable-state": "0.0.0-main-33a95299",
21
21
  "react": "^18.2.0"
22
22
  },
23
23
  "devDependencies": {
package/src/read.ts CHANGED
@@ -194,6 +194,8 @@ function readData<TReadFromStore>(
194
194
  break;
195
195
  }
196
196
  case 'ImperativelyLoadedField': {
197
+ // First, we read the data using the refetch reader AST (i.e. read out the
198
+ // id field).
197
199
  const data = readData(
198
200
  environment,
199
201
  field.refetchReaderArtifact.readerAst,
@@ -218,6 +220,8 @@ function readData<TReadFromStore>(
218
220
  const refetchQueryArtifact = refetchQuery.artifact;
219
221
  const allowedVariables = refetchQuery.allowedVariables;
220
222
 
223
+ // Second, we allow the user to call the resolver, which will ultimately
224
+ // use the resolver reader AST to get the resolver parameters.
221
225
  target[field.alias] = [
222
226
  // DataId
223
227
  root + '__' + field.name,
@@ -229,6 +233,7 @@ function readData<TReadFromStore>(
229
233
  filterVariables(variables, allowedVariables),
230
234
  root,
231
235
  field.resolverReaderArtifact,
236
+ field.usedRefetchQueries.map((id) => nestedRefetchQueries[id]),
232
237
  ),
233
238
  ];
234
239
  }
package/src/reader.ts CHANGED
@@ -5,7 +5,10 @@ import {
5
5
  DataId,
6
6
  IsographEnvironment,
7
7
  } from './IsographEnvironment';
8
- import { RefetchQueryNormalizationArtifact } from './entrypoint';
8
+ import {
9
+ RefetchQueryNormalizationArtifact,
10
+ RefetchQueryNormalizationArtifactWrapper,
11
+ } from './entrypoint';
9
12
  import { Arguments } from './util';
10
13
 
11
14
  export type TopLevelReaderArtifact<
@@ -51,6 +54,7 @@ export type RefetchReaderArtifact = {
51
54
  rootId: DataId,
52
55
  readerArtifact: TopLevelReaderArtifact<any, any, any> | null,
53
56
  // TODO type this better
57
+ nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
54
58
  ) => () => void;
55
59
  };
56
60
 
@@ -67,6 +71,7 @@ export type MutationReaderArtifact<TReadFromStore extends Object> = {
67
71
  rootId: DataId,
68
72
  readerArtifact: TopLevelReaderArtifact<any, any, any> | null,
69
73
  // TODO type this better
74
+ nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
70
75
  ) => (mutationParams: any) => void;
71
76
  };
72
77
 
@@ -111,6 +116,7 @@ export type ReaderImperativelyLoadedField = {
111
116
  readonly resolverReaderArtifact: TopLevelReaderArtifact<any, any, any> | null;
112
117
  readonly refetchQuery: number;
113
118
  readonly name: string;
119
+ readonly usedRefetchQueries: number[];
114
120
  };
115
121
 
116
122
  export type LoadableField<T> = [