relay-runtime 0.0.0-main-c3ad9027 → 0.0.0-main-74926b6f

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v0.0.0-main-c3ad9027
2
+ * Relay v0.0.0-main-74926b6f
3
3
  *
4
4
  * Copyright (c) Facebook, Inc. and its affiliates.
5
5
  *
@@ -14,6 +14,7 @@ var _require = require('./RelayConcreteVariables'),
14
14
  getFragmentVariables = _require.getFragmentVariables;
15
15
 
16
16
  var _require2 = require('./RelayStoreUtils'),
17
+ CLIENT_EDGE_TRAVERSAL_PATH = _require2.CLIENT_EDGE_TRAVERSAL_PATH,
17
18
  FRAGMENT_OWNER_KEY = _require2.FRAGMENT_OWNER_KEY,
18
19
  FRAGMENTS_KEY = _require2.FRAGMENTS_KEY,
19
20
  ID_KEY = _require2.ID_KEY,
@@ -61,12 +62,14 @@ function getSingularSelector(fragment, item) {
61
62
  var fragments = item[FRAGMENTS_KEY];
62
63
  var mixedOwner = item[FRAGMENT_OWNER_KEY];
63
64
  var isWithinUnmatchedTypeRefinement = item[IS_WITHIN_UNMATCHED_TYPE_REFINEMENT] === true;
65
+ var mixedClientEdgeTraversalPath = item[CLIENT_EDGE_TRAVERSAL_PATH];
64
66
 
65
- if (typeof dataID === 'string' && typeof fragments === 'object' && fragments !== null && typeof fragments[fragment.name] === 'object' && fragments[fragment.name] !== null && typeof mixedOwner === 'object' && mixedOwner !== null) {
67
+ if (typeof dataID === 'string' && typeof fragments === 'object' && fragments !== null && typeof fragments[fragment.name] === 'object' && fragments[fragment.name] !== null && typeof mixedOwner === 'object' && mixedOwner !== null && (mixedClientEdgeTraversalPath == null || Array.isArray(mixedClientEdgeTraversalPath))) {
66
68
  var owner = mixedOwner;
69
+ var clientEdgeTraversalPath = mixedClientEdgeTraversalPath;
67
70
  var argumentVariables = fragments[fragment.name];
68
71
  var fragmentVariables = getFragmentVariables(fragment, owner.variables, argumentVariables);
69
- return createReaderSelector(fragment, dataID, fragmentVariables, owner, isWithinUnmatchedTypeRefinement);
72
+ return createReaderSelector(fragment, dataID, fragmentVariables, owner, isWithinUnmatchedTypeRefinement, clientEdgeTraversalPath);
70
73
  }
71
74
 
72
75
  if (process.env.NODE_ENV !== "production") {
@@ -296,10 +299,12 @@ function areEqualSelectors(thisSelector, thatSelector) {
296
299
 
297
300
  function createReaderSelector(fragment, dataID, variables, request) {
298
301
  var isWithinUnmatchedTypeRefinement = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
302
+ var clientEdgeTraversalPath = arguments.length > 5 ? arguments[5] : undefined;
299
303
  return {
300
304
  kind: 'SingularReaderSelector',
301
305
  dataID: dataID,
302
306
  isWithinUnmatchedTypeRefinement: isWithinUnmatchedTypeRefinement,
307
+ clientEdgeTraversalPath: clientEdgeTraversalPath !== null && clientEdgeTraversalPath !== void 0 ? clientEdgeTraversalPath : null,
303
308
  node: fragment,
304
309
  variables: variables,
305
310
  owner: request
@@ -14,8 +14,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
14
14
 
15
15
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
16
 
17
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
18
+
17
19
  var _require = require('../util/RelayConcreteNode'),
18
20
  ACTOR_CHANGE = _require.ACTOR_CHANGE,
21
+ CLIENT_EDGE = _require.CLIENT_EDGE,
19
22
  CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
20
23
  CONDITION = _require.CONDITION,
21
24
  DEFER = _require.DEFER,
@@ -40,6 +43,7 @@ var _require2 = require('./RelayStoreReactFlightUtils'),
40
43
  getReactFlightClientResponse = _require2.getReactFlightClientResponse;
41
44
 
42
45
  var _require3 = require('./RelayStoreUtils'),
46
+ CLIENT_EDGE_TRAVERSAL_PATH = _require3.CLIENT_EDGE_TRAVERSAL_PATH,
43
47
  FRAGMENT_OWNER_KEY = _require3.FRAGMENT_OWNER_KEY,
44
48
  FRAGMENT_PROP_NAME_KEY = _require3.FRAGMENT_PROP_NAME_KEY,
45
49
  FRAGMENTS_KEY = _require3.FRAGMENTS_KEY,
@@ -73,6 +77,10 @@ function read(recordSource, selector, resolverCache) {
73
77
 
74
78
  var RelayReader = /*#__PURE__*/function () {
75
79
  function RelayReader(recordSource, selector, resolverCache) {
80
+ var _selector$clientEdgeT;
81
+
82
+ this._clientEdgeTraversalPath = RelayFeatureFlags.ENABLE_CLIENT_EDGES && ((_selector$clientEdgeT = selector.clientEdgeTraversalPath) === null || _selector$clientEdgeT === void 0 ? void 0 : _selector$clientEdgeT.length) ? (0, _toConsumableArray2["default"])(selector.clientEdgeTraversalPath) : [];
83
+ this._missingClientEdges = [];
76
84
  this._isMissingData = false;
77
85
  this._isWithinUnmatchedTypeRefinement = false;
78
86
  this._missingRequiredFields = null;
@@ -152,12 +160,30 @@ var RelayReader = /*#__PURE__*/function () {
152
160
  return {
153
161
  data: data,
154
162
  isMissingData: this._isMissingData && isDataExpectedToBePresent,
163
+ missingClientEdges: RelayFeatureFlags.ENABLE_CLIENT_EDGES && this._missingClientEdges.length ? this._missingClientEdges : null,
155
164
  seenRecords: this._seenRecords,
156
165
  selector: this._selector,
157
166
  missingRequiredFields: this._missingRequiredFields
158
167
  };
159
168
  };
160
169
 
170
+ _proto._markDataAsMissing = function _markDataAsMissing() {
171
+ this._isMissingData = true;
172
+
173
+ if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && this._clientEdgeTraversalPath.length) {
174
+ var top = this._clientEdgeTraversalPath[this._clientEdgeTraversalPath.length - 1]; // Top can be null if we've traversed past a client edge into an ordinary
175
+ // client extension field; we never want to fetch in response to missing
176
+ // data off of a client extension field.
177
+
178
+ if (top !== null) {
179
+ this._missingClientEdges.push({
180
+ request: top.readerClientEdge.operation,
181
+ clientEdgeDestinationID: top.clientEdgeDestinationID
182
+ });
183
+ }
184
+ }
185
+ };
186
+
161
187
  _proto._traverse = function _traverse(node, dataID, prevData) {
162
188
  var record = this._recordSource.get(dataID);
163
189
 
@@ -165,7 +191,7 @@ var RelayReader = /*#__PURE__*/function () {
165
191
 
166
192
  if (record == null) {
167
193
  if (record === undefined) {
168
- this._isMissingData = true;
194
+ this._markDataAsMissing();
169
195
  }
170
196
 
171
197
  return record;
@@ -321,7 +347,7 @@ var RelayReader = /*#__PURE__*/function () {
321
347
  this._isMissingData = parentIsMissingData;
322
348
  } else if (implementsInterface == null) {
323
349
  // Don't know if the type implements the interface or not
324
- this._isMissingData = true;
350
+ this._markDataAsMissing();
325
351
  }
326
352
  }
327
353
 
@@ -358,10 +384,22 @@ var RelayReader = /*#__PURE__*/function () {
358
384
  case CLIENT_EXTENSION:
359
385
  {
360
386
  var isMissingData = this._isMissingData;
387
+ var alreadyMissingClientEdges = this._missingClientEdges.length;
388
+
389
+ if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
390
+ this._clientEdgeTraversalPath.push(null);
391
+ }
392
+
393
+ var _hasExpectedData2 = this._traverseSelections(selection.selections, record, data); // The only case where we want to suspend due to missing data off of
394
+ // a client extension is if we reached a client edge that we might be
395
+ // able to fetch:
361
396
 
362
- var _hasExpectedData2 = this._traverseSelections(selection.selections, record, data);
363
397
 
364
- this._isMissingData = isMissingData;
398
+ this._isMissingData = isMissingData || this._missingClientEdges.length > alreadyMissingClientEdges;
399
+
400
+ if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
401
+ this._clientEdgeTraversalPath.pop();
402
+ }
365
403
 
366
404
  if (!_hasExpectedData2) {
367
405
  return false;
@@ -395,6 +433,15 @@ var RelayReader = /*#__PURE__*/function () {
395
433
 
396
434
  break;
397
435
 
436
+ case CLIENT_EDGE:
437
+ if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
438
+ this._readClientEdge(selection, record, data);
439
+ } else {
440
+ throw new Error('Client edges are not yet supported.');
441
+ }
442
+
443
+ break;
444
+
398
445
  default:
399
446
  selection;
400
447
  !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
@@ -434,6 +481,8 @@ var RelayReader = /*#__PURE__*/function () {
434
481
  _proto._readResolverField = function _readResolverField(field, record, data) {
435
482
  var _this = this;
436
483
 
484
+ var _field$alias;
485
+
437
486
  var resolverModule = field.resolverModule,
438
487
  fragment = field.fragment;
439
488
  var storageKey = getStorageKey(field, this._variables);
@@ -501,14 +550,53 @@ var RelayReader = /*#__PURE__*/function () {
501
550
  this._seenRecords.add(seenRecord);
502
551
  }
503
552
 
504
- data[storageKey] = result;
505
- return result;
553
+ var applicationName = (_field$alias = field.alias) !== null && _field$alias !== void 0 ? _field$alias : field.name;
554
+ data[applicationName] = result;
555
+ };
556
+
557
+ _proto._readClientEdge = function _readClientEdge(field, record, data) {
558
+ var _backingField$alias;
559
+
560
+ var backingField = field.backingField; // Because ReaderClientExtension doesn't have `alias` or `name` and so I don't know
561
+ // how to get its applicationName or storageKey yet:
562
+
563
+ !(backingField.kind !== 'ClientExtension') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Client extension client edges are not yet implemented.') : invariant(false) : void 0;
564
+ var applicationName = (_backingField$alias = backingField.alias) !== null && _backingField$alias !== void 0 ? _backingField$alias : backingField.name;
565
+ var backingFieldData = {};
566
+
567
+ this._traverseSelections([backingField], record, backingFieldData);
568
+
569
+ var destinationDataID = backingFieldData[applicationName];
570
+
571
+ if (destinationDataID == null) {
572
+ data[applicationName] = destinationDataID;
573
+ return;
574
+ }
575
+
576
+ !(typeof destinationDataID === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Plural client edges not are yet implemented') : invariant(false) : void 0; // FIXME support plural
577
+ // Not wrapping the push/pop in a try/finally because if we throw, the
578
+ // Reader object is not usable after that anyway.
579
+
580
+ this._clientEdgeTraversalPath.push({
581
+ readerClientEdge: field,
582
+ clientEdgeDestinationID: destinationDataID
583
+ });
584
+
585
+ var prevData = data[applicationName];
586
+ !(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevData) : invariant(false) : void 0;
587
+
588
+ var value = this._traverse(field.linkedField, destinationDataID, // $FlowFixMe[incompatible-variance]
589
+ prevData);
590
+
591
+ data[applicationName] = value;
592
+
593
+ this._clientEdgeTraversalPath.pop();
506
594
  };
507
595
 
508
596
  _proto._readFlightField = function _readFlightField(field, record, data) {
509
- var _field$alias;
597
+ var _field$alias2;
510
598
 
511
- var applicationName = (_field$alias = field.alias) !== null && _field$alias !== void 0 ? _field$alias : field.name;
599
+ var applicationName = (_field$alias2 = field.alias) !== null && _field$alias2 !== void 0 ? _field$alias2 : field.name;
512
600
  var storageKey = getStorageKey(field, this._variables);
513
601
  var reactFlightClientResponseRecordID = RelayModernRecord.getLinkedRecordID(record, storageKey);
514
602
 
@@ -516,7 +604,7 @@ var RelayReader = /*#__PURE__*/function () {
516
604
  data[applicationName] = reactFlightClientResponseRecordID;
517
605
 
518
606
  if (reactFlightClientResponseRecordID === undefined) {
519
- this._isMissingData = true;
607
+ this._markDataAsMissing();
520
608
  }
521
609
 
522
610
  return reactFlightClientResponseRecordID;
@@ -530,7 +618,7 @@ var RelayReader = /*#__PURE__*/function () {
530
618
  data[applicationName] = reactFlightClientResponseRecord;
531
619
 
532
620
  if (reactFlightClientResponseRecord === undefined) {
533
- this._isMissingData = true;
621
+ this._markDataAsMissing();
534
622
  }
535
623
 
536
624
  return reactFlightClientResponseRecord;
@@ -542,14 +630,14 @@ var RelayReader = /*#__PURE__*/function () {
542
630
  };
543
631
 
544
632
  _proto._readScalar = function _readScalar(field, record, data) {
545
- var _field$alias2;
633
+ var _field$alias3;
546
634
 
547
- var applicationName = (_field$alias2 = field.alias) !== null && _field$alias2 !== void 0 ? _field$alias2 : field.name;
635
+ var applicationName = (_field$alias3 = field.alias) !== null && _field$alias3 !== void 0 ? _field$alias3 : field.name;
548
636
  var storageKey = getStorageKey(field, this._variables);
549
637
  var value = RelayModernRecord.getValue(record, storageKey);
550
638
 
551
639
  if (value === undefined) {
552
- this._isMissingData = true;
640
+ this._markDataAsMissing();
553
641
  }
554
642
 
555
643
  data[applicationName] = value;
@@ -557,9 +645,9 @@ var RelayReader = /*#__PURE__*/function () {
557
645
  };
558
646
 
559
647
  _proto._readLink = function _readLink(field, record, data) {
560
- var _field$alias3;
648
+ var _field$alias4;
561
649
 
562
- var applicationName = (_field$alias3 = field.alias) !== null && _field$alias3 !== void 0 ? _field$alias3 : field.name;
650
+ var applicationName = (_field$alias4 = field.alias) !== null && _field$alias4 !== void 0 ? _field$alias4 : field.name;
563
651
  var storageKey = getStorageKey(field, this._variables);
564
652
  var linkedID = RelayModernRecord.getLinkedRecordID(record, storageKey);
565
653
 
@@ -567,7 +655,7 @@ var RelayReader = /*#__PURE__*/function () {
567
655
  data[applicationName] = linkedID;
568
656
 
569
657
  if (linkedID === undefined) {
570
- this._isMissingData = true;
658
+ this._markDataAsMissing();
571
659
  }
572
660
 
573
661
  return linkedID;
@@ -583,9 +671,9 @@ var RelayReader = /*#__PURE__*/function () {
583
671
  };
584
672
 
585
673
  _proto._readActorChange = function _readActorChange(field, record, data) {
586
- var _field$alias4;
674
+ var _field$alias5;
587
675
 
588
- var applicationName = (_field$alias4 = field.alias) !== null && _field$alias4 !== void 0 ? _field$alias4 : field.name;
676
+ var applicationName = (_field$alias5 = field.alias) !== null && _field$alias5 !== void 0 ? _field$alias5 : field.name;
589
677
  var storageKey = getStorageKey(field, this._variables);
590
678
  var externalRef = RelayModernRecord.getActorLinkedRecordID(record, storageKey);
591
679
 
@@ -593,7 +681,7 @@ var RelayReader = /*#__PURE__*/function () {
593
681
  data[applicationName] = externalRef;
594
682
 
595
683
  if (externalRef === undefined) {
596
- this._isMissingData = true;
684
+ this._markDataAsMissing();
597
685
  }
598
686
 
599
687
  return data[applicationName];
@@ -617,9 +705,9 @@ var RelayReader = /*#__PURE__*/function () {
617
705
  _proto._readPluralLink = function _readPluralLink(field, record, data) {
618
706
  var _this2 = this;
619
707
 
620
- var _field$alias5;
708
+ var _field$alias6;
621
709
 
622
- var applicationName = (_field$alias5 = field.alias) !== null && _field$alias5 !== void 0 ? _field$alias5 : field.name;
710
+ var applicationName = (_field$alias6 = field.alias) !== null && _field$alias6 !== void 0 ? _field$alias6 : field.name;
623
711
  var storageKey = getStorageKey(field, this._variables);
624
712
  var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
625
713
 
@@ -627,7 +715,7 @@ var RelayReader = /*#__PURE__*/function () {
627
715
  data[applicationName] = linkedIDs;
628
716
 
629
717
  if (linkedIDs === undefined) {
630
- this._isMissingData = true;
718
+ this._markDataAsMissing();
631
719
  }
632
720
 
633
721
  return linkedIDs;
@@ -639,7 +727,7 @@ var RelayReader = /*#__PURE__*/function () {
639
727
  linkedIDs.forEach(function (linkedID, nextIndex) {
640
728
  if (linkedID == null) {
641
729
  if (linkedID === undefined) {
642
- _this2._isMissingData = true;
730
+ _this2._markDataAsMissing();
643
731
  } // $FlowFixMe[cannot-write]
644
732
 
645
733
 
@@ -670,7 +758,7 @@ var RelayReader = /*#__PURE__*/function () {
670
758
 
671
759
  if (component == null) {
672
760
  if (component === undefined) {
673
- this._isMissingData = true;
761
+ this._markDataAsMissing();
674
762
  }
675
763
 
676
764
  return;
@@ -708,6 +796,12 @@ var RelayReader = /*#__PURE__*/function () {
708
796
  fragmentPointers[fragmentSpread.name] = fragmentSpread.args ? getArgumentValues(fragmentSpread.args, this._variables) : {};
709
797
  data[FRAGMENT_OWNER_KEY] = this._owner;
710
798
  data[IS_WITHIN_UNMATCHED_TYPE_REFINEMENT] = this._isWithinUnmatchedTypeRefinement;
799
+
800
+ if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
801
+ if (this._clientEdgeTraversalPath.length > 0 && this._clientEdgeTraversalPath[this._clientEdgeTraversalPath.length - 1] !== null) {
802
+ data[CLIENT_EDGE_TRAVERSAL_PATH] = (0, _toConsumableArray2["default"])(this._clientEdgeTraversalPath);
803
+ }
804
+ }
711
805
  };
712
806
 
713
807
  _proto._createInlineDataOrResolverFragmentPointer = function _createInlineDataOrResolverFragmentPointer(fragmentSpreadOrFragment, record, data) {
@@ -93,6 +93,7 @@ var RelayStoreSubscriptions = /*#__PURE__*/function () {
93
93
  subscription.snapshot = {
94
94
  data: subscription.snapshot.data,
95
95
  isMissingData: backup.isMissingData,
96
+ missingClientEdges: backup.missingClientEdges,
96
97
  seenRecords: backup.seenRecords,
97
98
  selector: backup.selector,
98
99
  missingRequiredFields: backup.missingRequiredFields
@@ -142,6 +143,7 @@ var RelayStoreSubscriptions = /*#__PURE__*/function () {
142
143
  nextSnapshot = {
143
144
  data: nextData,
144
145
  isMissingData: nextSnapshot.isMissingData,
146
+ missingClientEdges: nextSnapshot.missingClientEdges,
145
147
  seenRecords: nextSnapshot.seenRecords,
146
148
  selector: nextSnapshot.selector,
147
149
  missingRequiredFields: nextSnapshot.missingRequiredFields
@@ -193,6 +193,7 @@ function getModuleOperationKey(documentName) {
193
193
 
194
194
  var RelayStoreUtils = {
195
195
  ACTOR_IDENTIFIER_KEY: '__actorIdentifier',
196
+ CLIENT_EDGE_TRAVERSAL_PATH: '__clientEdgeTraversalPath',
196
197
  FRAGMENTS_KEY: '__fragments',
197
198
  FRAGMENT_OWNER_KEY: '__fragmentOwner',
198
199
  FRAGMENT_PROP_NAME_KEY: '__fragmentPropName',
@@ -27,6 +27,7 @@ var RelayConcreteNode = {
27
27
  ACTOR_CHANGE: 'ActorChange',
28
28
  CONDITION: 'Condition',
29
29
  CLIENT_COMPONENT: 'ClientComponent',
30
+ CLIENT_EDGE: 'ClientEdge',
30
31
  CLIENT_EXTENSION: 'ClientExtension',
31
32
  DEFER: 'Defer',
32
33
  CONNECTION: 'Connection',
@@ -12,6 +12,7 @@
12
12
 
13
13
  var RelayFeatureFlags = {
14
14
  DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES: false,
15
+ ENABLE_CLIENT_EDGES: false,
15
16
  ENABLE_VARIABLE_CONNECTION_KEY: false,
16
17
  ENABLE_PARTIAL_RENDERING_DEFAULT: true,
17
18
  ENABLE_REACT_FLIGHT_COMPONENT_FIELD: false,
@@ -26,6 +27,7 @@ var RelayFeatureFlags = {
26
27
  ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT: false,
27
28
  ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT: false,
28
29
  MAX_DATA_ID_LENGTH: null,
30
+ REFACTOR_SUSPENSE_RESOURCE: true,
29
31
  STRING_INTERN_LEVEL: 0,
30
32
  USE_REACT_CACHE: false
31
33
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "relay-runtime",
3
3
  "description": "A core runtime for building GraphQL-driven applications.",
4
- "version": "0.0.0-main-c3ad9027",
4
+ "version": "0.0.0-main-74926b6f",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"