relay-runtime 0.0.0-main-857a579c → 0.0.0-main-e01b8404

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-857a579c
2
+ * Relay v0.0.0-main-e01b8404
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
@@ -11,6 +11,13 @@
11
11
  // flowlint ambiguous-object-type:error
12
12
  'use strict';
13
13
 
14
+ var areEqual = require("fbjs/lib/areEqual");
15
+
16
+ var warning = require("fbjs/lib/warning");
17
+
18
+ var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
19
+ var debugCache = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
20
+
14
21
  function withProvidedVariables(userSuppliedVariables, parameters) {
15
22
  var providedVariables = parameters.providedVariables;
16
23
 
@@ -18,7 +25,22 @@ function withProvidedVariables(userSuppliedVariables, parameters) {
18
25
  var operationVariables = {};
19
26
  Object.assign(operationVariables, userSuppliedVariables);
20
27
  Object.keys(providedVariables).forEach(function (varName) {
21
- operationVariables[varName] = providedVariables[varName].get();
28
+ var providerFunction = providedVariables[varName].get;
29
+ var providerResult = providerFunction(); // people like to ignore these warnings, so use the cache to
30
+ // enforce that we only compute the value the first time
31
+
32
+ if (!debugCache.has(providerFunction)) {
33
+ debugCache.set(providerFunction, providerResult);
34
+ operationVariables[varName] = providerResult;
35
+ } else {
36
+ var cachedResult = debugCache.get(providerFunction);
37
+
38
+ if (process.env.NODE_ENV !== "production") {
39
+ process.env.NODE_ENV !== "production" ? warning(areEqual(providerResult, cachedResult), 'Relay: Expected function `%s` for provider `%s` to be a pure function, ' + 'but got conflicting return values `%s` and `%s`', providerFunction.name, varName, providerResult, cachedResult) : void 0;
40
+ }
41
+
42
+ operationVariables[varName] = cachedResult;
43
+ }
22
44
  });
23
45
  return operationVariables;
24
46
  } else {
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-857a579c",
4
+ "version": "0.0.0-main-e01b8404",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"