relay-runtime 0.0.0-main-d4ab8a1c → 0.0.0-main-ee374c8e

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.
@@ -31,7 +31,9 @@ const {
31
31
  FRAGMENT_SPREAD,
32
32
  INLINE_FRAGMENT,
33
33
  LINKED_FIELD,
34
+ LINKED_HANDLE,
34
35
  SCALAR_FIELD,
36
+ SCALAR_HANDLE,
35
37
  } = require('../util/RelayConcreteNode');
36
38
  const {getLocalVariables} = require('./RelayConcreteVariables');
37
39
  const {createNormalizationSelector} = require('./RelayModernSelector');
@@ -91,6 +93,10 @@ export type GraphModeChunk = DataChunk | CompleteChunk;
91
93
 
92
94
  export type GraphModeResponse = Iterable<GraphModeChunk>;
93
95
 
96
+ export type TransformMetadata = {
97
+ duplicateFieldsAvoided: number,
98
+ };
99
+
94
100
  /**
95
101
  * Converts a JSON response (and Normalization AST) into a stream of GraphMode chunks
96
102
  *
@@ -128,7 +134,20 @@ export function normalizeResponse(
128
134
  return normalizer.normalizeResponse(node, dataID, response);
129
135
  }
130
136
 
131
- class GraphModeNormalizer {
137
+ export function normalizeResponseWithMetadata(
138
+ response: PayloadData,
139
+ selector: NormalizationSelector,
140
+ options: NormalizationOptions,
141
+ ): [Array<GraphModeChunk>, TransformMetadata] {
142
+ const {node, variables, dataID} = selector;
143
+ const normalizer = new GraphModeNormalizer(variables, options);
144
+ const chunks = Array.from(
145
+ normalizer.normalizeResponse(node, dataID, response),
146
+ );
147
+ return [chunks, {duplicateFieldsAvoided: normalizer.duplicateFieldsAvoided}];
148
+ }
149
+
150
+ export class GraphModeNormalizer {
132
151
  _cacheKeyToStreamID: Map<string, number>;
133
152
  _sentFields: Map<string, Set<string>>;
134
153
  _getDataId: GetDataID;
@@ -138,6 +157,7 @@ class GraphModeNormalizer {
138
157
  _path: Array<string>;
139
158
  _incrementalPlaceholders: Array<IncrementalDataPlaceholder>;
140
159
  _actorIdentifier: ?ActorIdentifier;
160
+ duplicateFieldsAvoided: number;
141
161
  constructor(variables: Variables, options: NormalizationOptions) {
142
162
  this._actorIdentifier = options.actorIdentifier;
143
163
  this._path = options.path ? [...options.path] : [];
@@ -146,6 +166,7 @@ class GraphModeNormalizer {
146
166
  this._sentFields = new Map();
147
167
  this._nextStreamID = 0;
148
168
  this._variables = variables;
169
+ this.duplicateFieldsAvoided = 0;
149
170
  }
150
171
 
151
172
  _getStreamID() {
@@ -266,6 +287,7 @@ class GraphModeNormalizer {
266
287
  // TODO: We could also opt to confirm that this matches the previously
267
288
  // seen value.
268
289
  if (sentFields.has(storageKey)) {
290
+ this.duplicateFieldsAvoided++;
269
291
  break;
270
292
  }
271
293
 
@@ -281,6 +303,7 @@ class GraphModeNormalizer {
281
303
  // TODO: We could also opt to confirm that this matches the previously
282
304
  // seen value.
283
305
  if (sentFields.has(storageKey)) {
306
+ this.duplicateFieldsAvoided++;
284
307
  break;
285
308
  }
286
309
  const fieldData = ((data[responseKey]: any): ChunkField);
@@ -374,6 +397,17 @@ class GraphModeNormalizer {
374
397
  // Since we are only expecting to handle server responses, we can skip
375
398
  // over client extensions.
376
399
  break;
400
+ case SCALAR_HANDLE:
401
+ case LINKED_HANDLE:
402
+ // Handles allow us to record information that will be needed to
403
+ // perform additional process when we insert data into the store. For
404
+ // example, connection edges need to be prepended/appended to the
405
+ // pre-existing values.
406
+ //
407
+ // GraphMode will eventually need some replacement for this, but it is
408
+ // not nessesary in order to measure things like response size, so we
409
+ // can ignore these for now.
410
+ break;
377
411
  default:
378
412
  throw new Error(`Unexpected selection type: ${selection.kind}`);
379
413
  }