@isograph/react 0.0.0-main-55364d41 → 0.0.0-main-2c275831

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/index.js CHANGED
@@ -10,8 +10,8 @@ Object.defineProperty(exports, "makeNetworkRequest", { enumerable: true, get: fu
10
10
  Object.defineProperty(exports, "subscribe", { enumerable: true, get: function () { return cache_2.subscribe; } });
11
11
  Object.defineProperty(exports, "clearStore", { enumerable: true, get: function () { return cache_2.clearStore; } });
12
12
  function assertIsEntrypoint(value) {
13
- if (typeof value === "function")
14
- throw new Error("Not a string");
13
+ if (typeof value === 'function')
14
+ throw new Error('Not a string');
15
15
  }
16
16
  function iso(_queryText) {
17
17
  // The name `identity` here is a bit of a double entendre.
@@ -26,6 +26,10 @@ function iso(_queryText) {
26
26
  };
27
27
  }
28
28
  exports.iso = iso;
29
+ // Note: we cannot write TEntrypoint extends IsographEntrypoint<any, any, any>, or else
30
+ // if we do not explicitly pass a type, the read out type will be any.
31
+ // We cannot write TEntrypoint extends IsographEntrypoint<never, never, never>, or else
32
+ // any actual Entrypoint we pass will not be valid.
29
33
  function useLazyReference(entrypoint, variables) {
30
34
  assertIsEntrypoint(entrypoint);
31
35
  // Typechecking fails here... TODO investigate
@@ -35,7 +39,7 @@ function useLazyReference(entrypoint, variables) {
35
39
  const data = (0, react_disposable_state_1.useLazyDisposableState)(cache).state;
36
40
  return {
37
41
  queryReference: {
38
- kind: "FragmentReference",
42
+ kind: 'FragmentReference',
39
43
  readerArtifact: entrypoint.readerArtifact,
40
44
  root: cache_1.ROOT_ID,
41
45
  variables,
@@ -47,30 +51,30 @@ exports.useLazyReference = useLazyReference;
47
51
  function read(fragmentReference) {
48
52
  var _a, _b;
49
53
  const variant = fragmentReference.readerArtifact.variant;
50
- if (variant.kind === "Eager") {
54
+ if (variant.kind === 'Eager') {
51
55
  const data = readData(fragmentReference.readerArtifact.readerAst, fragmentReference.root, (_a = fragmentReference.variables) !== null && _a !== void 0 ? _a : {}, fragmentReference.nestedRefetchQueries);
52
- if (data.kind === "MissingData") {
56
+ if (data.kind === 'MissingData') {
53
57
  throw (0, cache_1.onNextChange)();
54
58
  }
55
59
  else {
56
60
  return fragmentReference.readerArtifact.resolver(data.data);
57
61
  }
58
62
  }
59
- else if (variant.kind === "Component") {
63
+ else if (variant.kind === 'Component') {
60
64
  // @ts-ignore
61
65
  return (0, componentCache_1.getOrCreateCachedComponent)(fragmentReference.root, variant.componentName, fragmentReference.readerArtifact, (_b = fragmentReference.variables) !== null && _b !== void 0 ? _b : {}, fragmentReference.nestedRefetchQueries);
62
66
  }
63
67
  // Why can't Typescript realize that this is unreachable??
64
- throw new Error("This is unreachable");
68
+ throw new Error('This is unreachable');
65
69
  }
66
70
  exports.read = read;
67
71
  function readButDoNotEvaluate(reference) {
68
72
  var _a;
69
73
  const response = readData(reference.readerArtifact.readerAst, reference.root, (_a = reference.variables) !== null && _a !== void 0 ? _a : {}, reference.nestedRefetchQueries);
70
- if (typeof window !== "undefined" && window.__LOG) {
71
- console.log("done reading", { response });
74
+ if (typeof window !== 'undefined' && window.__LOG) {
75
+ console.log('done reading', { response });
72
76
  }
73
- if (response.kind === "MissingData") {
77
+ if (response.kind === 'MissingData') {
74
78
  throw (0, cache_1.onNextChange)();
75
79
  }
76
80
  else {
@@ -82,29 +86,29 @@ function readData(ast, root, variables, nestedRefetchQueries) {
82
86
  var _a, _b, _c, _d;
83
87
  let storeRecord = (0, cache_1.getStore)()[root];
84
88
  if (storeRecord === undefined) {
85
- return { kind: "MissingData", reason: "No record for root " + root };
89
+ return { kind: 'MissingData', reason: 'No record for root ' + root };
86
90
  }
87
91
  if (storeRecord === null) {
88
- return { kind: "Success", data: null };
92
+ return { kind: 'Success', data: null };
89
93
  }
90
94
  let target = {};
91
95
  for (const field of ast) {
92
96
  switch (field.kind) {
93
- case "Scalar": {
97
+ case 'Scalar': {
94
98
  const storeRecordName = (0, cache_1.getParentRecordKey)(field, variables);
95
99
  const value = storeRecord[storeRecordName];
96
100
  // TODO consider making scalars into discriminated unions. This probably has
97
101
  // to happen for when we handle errors.
98
102
  if (value === undefined) {
99
103
  return {
100
- kind: "MissingData",
101
- reason: "No value for " + storeRecordName + " on root " + root,
104
+ kind: 'MissingData',
105
+ reason: 'No value for ' + storeRecordName + ' on root ' + root,
102
106
  };
103
107
  }
104
108
  target[(_a = field.alias) !== null && _a !== void 0 ? _a : field.fieldName] = value;
105
109
  break;
106
110
  }
107
- case "Linked": {
111
+ case 'Linked': {
108
112
  const storeRecordName = (0, cache_1.getParentRecordKey)(field, variables);
109
113
  const value = storeRecord[storeRecordName];
110
114
  if (Array.isArray(value)) {
@@ -113,12 +117,12 @@ function readData(ast, root, variables, nestedRefetchQueries) {
113
117
  const link = assertLink(item);
114
118
  if (link === undefined) {
115
119
  return {
116
- kind: "MissingData",
117
- reason: "No link for " +
120
+ kind: 'MissingData',
121
+ reason: 'No link for ' +
118
122
  storeRecordName +
119
- " on root " +
123
+ ' on root ' +
120
124
  root +
121
- ". Link is " +
125
+ '. Link is ' +
122
126
  JSON.stringify(item),
123
127
  };
124
128
  }
@@ -127,14 +131,14 @@ function readData(ast, root, variables, nestedRefetchQueries) {
127
131
  continue;
128
132
  }
129
133
  const result = readData(field.selections, link.__link, variables, nestedRefetchQueries);
130
- if (result.kind === "MissingData") {
134
+ if (result.kind === 'MissingData') {
131
135
  return {
132
- kind: "MissingData",
133
- reason: "Missing data for " +
136
+ kind: 'MissingData',
137
+ reason: 'Missing data for ' +
134
138
  storeRecordName +
135
- " on root " +
139
+ ' on root ' +
136
140
  root +
137
- ". Link is " +
141
+ '. Link is ' +
138
142
  JSON.stringify(item),
139
143
  nestedReason: result,
140
144
  };
@@ -150,12 +154,12 @@ function readData(ast, root, variables, nestedRefetchQueries) {
150
154
  const altLink = missingFieldHandler(storeRecord, root, field.fieldName, field.arguments, variables);
151
155
  if (altLink === undefined) {
152
156
  return {
153
- kind: "MissingData",
154
- reason: "No link for " +
157
+ kind: 'MissingData',
158
+ reason: 'No link for ' +
155
159
  storeRecordName +
156
- " on root " +
160
+ ' on root ' +
157
161
  root +
158
- ". Link is " +
162
+ '. Link is ' +
159
163
  JSON.stringify(value),
160
164
  };
161
165
  }
@@ -169,34 +173,34 @@ function readData(ast, root, variables, nestedRefetchQueries) {
169
173
  }
170
174
  const targetId = link.__link;
171
175
  const data = readData(field.selections, targetId, variables, nestedRefetchQueries);
172
- if (data.kind === "MissingData") {
176
+ if (data.kind === 'MissingData') {
173
177
  return {
174
- kind: "MissingData",
175
- reason: "Missing data for " + storeRecordName + " on root " + root,
178
+ kind: 'MissingData',
179
+ reason: 'Missing data for ' + storeRecordName + ' on root ' + root,
176
180
  nestedReason: data,
177
181
  };
178
182
  }
179
183
  target[(_d = field.alias) !== null && _d !== void 0 ? _d : field.fieldName] = data.data;
180
184
  break;
181
185
  }
182
- case "RefetchField": {
186
+ case 'RefetchField': {
183
187
  const data = readData(field.readerArtifact.readerAst, root, variables,
184
188
  // Refetch fields just read the id, and don't need refetch query artifacts
185
189
  []);
186
- if (typeof window !== "undefined" && window.__LOG) {
187
- console.log("refetch field data", data, field);
190
+ if (typeof window !== 'undefined' && window.__LOG) {
191
+ console.log('refetch field data', data, field);
188
192
  }
189
- if (data.kind === "MissingData") {
193
+ if (data.kind === 'MissingData') {
190
194
  return {
191
- kind: "MissingData",
192
- reason: "Missing data for " + field.alias + " on root " + root,
195
+ kind: 'MissingData',
196
+ reason: 'Missing data for ' + field.alias + ' on root ' + root,
193
197
  nestedReason: data,
194
198
  };
195
199
  }
196
200
  else {
197
201
  const refetchQueryIndex = field.refetchQuery;
198
202
  if (refetchQueryIndex == null) {
199
- throw new Error("refetchQuery is null in RefetchField");
203
+ throw new Error('refetchQuery is null in RefetchField');
200
204
  }
201
205
  const refetchQuery = nestedRefetchQueries[refetchQueryIndex];
202
206
  const refetchQueryArtifact = refetchQuery.artifact;
@@ -205,24 +209,24 @@ function readData(ast, root, variables, nestedRefetchQueries) {
205
209
  }
206
210
  break;
207
211
  }
208
- case "MutationField": {
212
+ case 'MutationField': {
209
213
  const data = readData(field.readerArtifact.readerAst, root, variables,
210
214
  // Refetch fields just read the id, and don't need refetch query artifacts
211
215
  []);
212
- if (typeof window !== "undefined" && window.__LOG) {
213
- console.log("refetch field data", data, field);
216
+ if (typeof window !== 'undefined' && window.__LOG) {
217
+ console.log('refetch field data', data, field);
214
218
  }
215
- if (data.kind === "MissingData") {
219
+ if (data.kind === 'MissingData') {
216
220
  return {
217
- kind: "MissingData",
218
- reason: "Missing data for " + field.alias + " on root " + root,
221
+ kind: 'MissingData',
222
+ reason: 'Missing data for ' + field.alias + ' on root ' + root,
219
223
  nestedReason: data,
220
224
  };
221
225
  }
222
226
  else {
223
227
  const refetchQueryIndex = field.refetchQuery;
224
228
  if (refetchQueryIndex == null) {
225
- throw new Error("refetchQuery is null in MutationField");
229
+ throw new Error('refetchQuery is null in MutationField');
226
230
  }
227
231
  const refetchQuery = nestedRefetchQueries[refetchQueryIndex];
228
232
  const refetchQueryArtifact = refetchQuery.artifact;
@@ -231,16 +235,16 @@ function readData(ast, root, variables, nestedRefetchQueries) {
231
235
  }
232
236
  break;
233
237
  }
234
- case "Resolver": {
238
+ case 'Resolver': {
235
239
  const usedRefetchQueries = field.usedRefetchQueries;
236
240
  const resolverRefetchQueries = usedRefetchQueries.map((index) => nestedRefetchQueries[index]);
237
241
  const variant = field.readerArtifact.variant;
238
- if (variant.kind === "Eager") {
242
+ if (variant.kind === 'Eager') {
239
243
  const data = readData(field.readerArtifact.readerAst, root, variables, resolverRefetchQueries);
240
- if (data.kind === "MissingData") {
244
+ if (data.kind === 'MissingData') {
241
245
  return {
242
- kind: "MissingData",
243
- reason: "Missing data for " + field.alias + " on root " + root,
246
+ kind: 'MissingData',
247
+ reason: 'Missing data for ' + field.alias + ' on root ' + root,
244
248
  nestedReason: data,
245
249
  };
246
250
  }
@@ -248,14 +252,14 @@ function readData(ast, root, variables, nestedRefetchQueries) {
248
252
  target[field.alias] = field.readerArtifact.resolver(data.data);
249
253
  }
250
254
  }
251
- else if (variant.kind === "Component") {
255
+ else if (variant.kind === 'Component') {
252
256
  target[field.alias] = (0, componentCache_1.getOrCreateCachedComponent)(root, variant.componentName, field.readerArtifact, variables, resolverRefetchQueries);
253
257
  }
254
258
  break;
255
259
  }
256
260
  }
257
261
  }
258
- return { kind: "Success", data: target };
262
+ return { kind: 'Success', data: target };
259
263
  }
260
264
  let customMissingFieldHandler = null;
261
265
  function missingFieldHandler(storeRecord, root, fieldName, arguments_, variables) {
@@ -267,8 +271,8 @@ function missingFieldHandler(storeRecord, root, fieldName, arguments_, variables
267
271
  }
268
272
  }
269
273
  function defaultMissingFieldHandler(storeRecord, root, fieldName, arguments_, variables) {
270
- if (fieldName === "node" || fieldName === "user") {
271
- const variable = arguments_ === null || arguments_ === void 0 ? void 0 : arguments_["id"];
274
+ if (fieldName === 'node' || fieldName === 'user') {
275
+ const variable = arguments_ === null || arguments_ === void 0 ? void 0 : arguments_['id'];
272
276
  const value = variables === null || variables === void 0 ? void 0 : variables[variable];
273
277
  // TODO can we handle explicit nulls here too? Probably, after wrapping in objects
274
278
  if (value != null) {
@@ -283,15 +287,15 @@ function setMissingFieldHandler(handler) {
283
287
  exports.setMissingFieldHandler = setMissingFieldHandler;
284
288
  function assertLink(link) {
285
289
  if (Array.isArray(link)) {
286
- throw new Error("Unexpected array");
290
+ throw new Error('Unexpected array');
287
291
  }
288
- if (typeof link === "object") {
292
+ if (typeof link === 'object') {
289
293
  return link;
290
294
  }
291
295
  if (link === undefined) {
292
296
  return undefined;
293
297
  }
294
- throw new Error("Invalid link");
298
+ throw new Error('Invalid link');
295
299
  }
296
300
  function filterVariables(variables, allowedVariables) {
297
301
  const result = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isograph/react",
3
- "version": "0.0.0-main-55364d41",
3
+ "version": "0.0.0-main-2c275831",
4
4
  "description": "Use Isograph with React",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,8 +15,8 @@
15
15
  "prepack": "yarn run test && yarn run compile"
16
16
  },
17
17
  "dependencies": {
18
- "@isograph/disposable-types": "0.0.0-main-55364d41",
19
- "@isograph/react-disposable-state": "0.0.0-main-55364d41",
18
+ "@isograph/disposable-types": "0.0.0-main-2c275831",
19
+ "@isograph/react-disposable-state": "0.0.0-main-2c275831",
20
20
  "react": "^18.2.0"
21
21
  },
22
22
  "devDependencies": {
@@ -1,4 +1,4 @@
1
- const NOT_SET: Symbol = Symbol("NOT_SET");
1
+ const NOT_SET: Symbol = Symbol('NOT_SET');
2
2
  type NotSet = typeof NOT_SET;
3
3
 
4
4
  /**