relay-runtime 1.7.0-rc.1 → 2.0.0

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.
Files changed (72) hide show
  1. package/LICENSE +1 -1
  2. package/index.js +1 -1
  3. package/lib/ConvertToExecuteFunction.js +12 -75
  4. package/lib/DataChecker.js +400 -0
  5. package/lib/NormalizationNode.js +14 -0
  6. package/lib/ReaderNode.js +10 -0
  7. package/lib/RelayCombinedEnvironmentTypes.js +10 -0
  8. package/lib/RelayConcreteNode.js +12 -29
  9. package/lib/RelayConcreteVariables.js +17 -11
  10. package/lib/RelayConnectionHandler.js +98 -42
  11. package/lib/RelayConnectionInterface.js +5 -13
  12. package/lib/RelayCore.js +17 -14
  13. package/lib/RelayDeclarativeMutationConfig.js +69 -34
  14. package/lib/RelayDefaultHandleKey.js +1 -2
  15. package/lib/RelayDefaultHandlerProvider.js +6 -5
  16. package/lib/RelayError.js +6 -9
  17. package/lib/RelayInMemoryRecordSource.js +20 -22
  18. package/lib/RelayModernEnvironment.js +140 -229
  19. package/lib/RelayModernFragmentSpecResolver.js +110 -102
  20. package/lib/RelayModernGraphQLTag.js +53 -15
  21. package/lib/{RelayModernOperationSelector.js → RelayModernOperationDescriptor.js} +9 -8
  22. package/lib/RelayModernQueryExecutor.js +172 -0
  23. package/lib/RelayModernRecord.js +97 -38
  24. package/lib/RelayModernSelector.js +89 -33
  25. package/lib/RelayModernStore.js +301 -0
  26. package/lib/RelayNetwork.js +16 -28
  27. package/lib/RelayNetworkLogger.js +2 -3
  28. package/lib/RelayNetworkLoggerTransaction.js +32 -30
  29. package/lib/RelayNetworkTypes.js +1 -2
  30. package/lib/RelayObservable.js +127 -155
  31. package/lib/RelayProfiler.js +35 -22
  32. package/lib/RelayPublishQueue.js +144 -96
  33. package/lib/RelayQueryResponseCache.js +37 -21
  34. package/lib/RelayReader.js +194 -61
  35. package/lib/RelayRecordProxy.js +50 -31
  36. package/lib/RelayRecordSourceMutator.js +92 -51
  37. package/lib/RelayRecordSourceProxy.js +43 -35
  38. package/lib/RelayRecordSourceSelectorProxy.js +22 -21
  39. package/lib/RelayRecordState.js +1 -3
  40. package/lib/RelayReferenceMarker.js +110 -37
  41. package/lib/RelayResponseNormalizer.js +248 -82
  42. package/lib/RelayRuntimeTypes.js +1 -3
  43. package/lib/RelayStoreTypes.js +1 -2
  44. package/lib/RelayStoreUtils.js +37 -19
  45. package/lib/RelayViewerHandler.js +14 -10
  46. package/lib/applyRelayModernOptimisticMutation.js +8 -8
  47. package/lib/cloneRelayHandleSourceField.js +8 -9
  48. package/lib/commitLocalUpdate.js +1 -2
  49. package/lib/commitRelayModernMutation.js +21 -14
  50. package/lib/createRelayNetworkLogger.js +11 -9
  51. package/lib/deepFreeze.js +2 -3
  52. package/lib/fetchRelayModernQuery.js +10 -12
  53. package/lib/generateRelayClientID.js +4 -2
  54. package/lib/getRelayHandleKey.js +5 -6
  55. package/lib/hasOverlappingIDs.js +3 -2
  56. package/lib/index.js +59 -62
  57. package/lib/isPromise.js +1 -2
  58. package/lib/isRelayModernEnvironment.js +1 -3
  59. package/lib/isScalarAndEqual.js +1 -3
  60. package/lib/normalizePayload.js +17 -15
  61. package/lib/normalizeRelayPayload.js +9 -9
  62. package/lib/recycleNodesInto.js +25 -9
  63. package/lib/requestRelaySubscription.js +25 -58
  64. package/lib/simpleClone.js +2 -3
  65. package/lib/stableCopy.js +5 -3
  66. package/lib/validateMutation.js +146 -0
  67. package/package.json +3 -3
  68. package/relay-runtime.js +4 -0
  69. package/relay-runtime.min.js +9 -0
  70. package/lib/RelayDataLoader.js +0 -302
  71. package/lib/RelayMarkSweepStore.js +0 -242
  72. package/lib/deferrableFragmentKey.js +0 -20
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
7
7
  *
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  /**
@@ -17,7 +16,7 @@
17
16
  function getArgumentValues(args, variables) {
18
17
  var values = {};
19
18
  args.forEach(function (arg) {
20
- if (arg.kind === require('./RelayConcreteNode').VARIABLE) {
19
+ if (arg.kind === require("./RelayConcreteNode").VARIABLE) {
21
20
  // Variables are provided at runtime and are not guaranteed to be stable.
22
21
  values[arg.name] = getStableVariableValue(arg.variableName, variables);
23
22
  } else {
@@ -27,7 +26,6 @@ function getArgumentValues(args, variables) {
27
26
  });
28
27
  return values;
29
28
  }
30
-
31
29
  /**
32
30
  * Given a handle field and variable values, returns a key that can be used to
33
31
  * uniquely identify the combination of the handle name and argument values.
@@ -37,6 +35,8 @@ function getArgumentValues(args, variables) {
37
35
  * name was used in previous implementations of Relay internals and is also
38
36
  * used here for consistency.
39
37
  */
38
+
39
+
40
40
  function getHandleStorageKey(handleField, variables) {
41
41
  var handle = handleField.handle,
42
42
  key = handleField.key,
@@ -44,16 +44,17 @@ function getHandleStorageKey(handleField, variables) {
44
44
  args = handleField.args,
45
45
  filters = handleField.filters;
46
46
 
47
- var handleName = require('./getRelayHandleKey')(handle, key, name);
47
+ var handleName = require("./getRelayHandleKey")(handle, key, name);
48
+
48
49
  if (!args || !filters || args.length === 0 || filters.length === 0) {
49
50
  return handleName;
50
51
  }
52
+
51
53
  var filterArgs = args.filter(function (arg) {
52
54
  return filters.indexOf(arg.name) > -1;
53
55
  });
54
56
  return formatStorageKey(handleName, getArgumentValues(filterArgs, variables));
55
57
  }
56
-
57
58
  /**
58
59
  * Given a field and variable values, returns a key that can be used to
59
60
  * uniquely identify the combination of the field name and argument values.
@@ -63,17 +64,18 @@ function getHandleStorageKey(handleField, variables) {
63
64
  * name was used in previous implementations of Relay internals and is also
64
65
  * used here for consistency.
65
66
  */
67
+
68
+
66
69
  function getStorageKey(field, variables) {
67
70
  if (field.storageKey) {
68
71
  // TODO T23663664: Handle nodes do not yet define a static storageKey.
69
72
  return field.storageKey;
70
73
  }
74
+
71
75
  var args = field.args,
72
76
  name = field.name;
73
-
74
77
  return args && args.length !== 0 ? formatStorageKey(name, getArgumentValues(args, variables)) : name;
75
78
  }
76
-
77
79
  /**
78
80
  * Given a `name` (eg. "foo") and an object representing argument values
79
81
  * (eg. `{orberBy: "name", first: 10}`) returns a unique storage key
@@ -82,59 +84,75 @@ function getStorageKey(field, variables) {
82
84
  * This differs from getStorageKey which requires a ConcreteNode where arguments
83
85
  * are assumed to already be sorted into a stable order.
84
86
  */
87
+
88
+
85
89
  function getStableStorageKey(name, args) {
86
- return formatStorageKey(name, require('./stableCopy')(args));
90
+ return formatStorageKey(name, require("./stableCopy")(args));
87
91
  }
88
-
89
92
  /**
90
93
  * Given a name and argument values, format a storage key.
91
94
  *
92
95
  * Arguments and the values within them are expected to be ordered in a stable
93
96
  * alphabetical ordering.
94
97
  */
98
+
99
+
95
100
  function formatStorageKey(name, argValues) {
96
101
  if (!argValues) {
97
102
  return name;
98
103
  }
104
+
99
105
  var values = [];
106
+
100
107
  for (var _argName in argValues) {
101
108
  if (argValues.hasOwnProperty(_argName)) {
102
109
  var value = argValues[_argName];
110
+
103
111
  if (value != null) {
104
112
  values.push(_argName + ':' + JSON.stringify(value));
105
113
  }
106
114
  }
107
115
  }
108
- return values.length === 0 ? name : name + ('(' + values.join(',') + ')');
109
- }
110
116
 
117
+ return values.length === 0 ? name : name + "(".concat(values.join(','), ")");
118
+ }
111
119
  /**
112
120
  * Given Variables and a variable name, return a variable value with
113
121
  * all values in a stable order.
114
122
  */
123
+
124
+
115
125
  function getStableVariableValue(name, variables) {
116
- !variables.hasOwnProperty(name) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'getVariableValue(): Undefined variable `%s`.', name) : require('fbjs/lib/invariant')(false) : void 0;
117
- return require('./stableCopy')(variables[name]);
126
+ !variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'getVariableValue(): Undefined variable `%s`.', name) : require("fbjs/lib/invariant")(false) : void 0;
127
+ return require("./stableCopy")(variables[name]);
118
128
  }
119
-
120
129
  /**
121
130
  * Constants shared by all implementations of RecordSource/MutableRecordSource/etc.
122
131
  */
132
+
133
+
123
134
  var RelayStoreUtils = {
124
135
  FRAGMENTS_KEY: '__fragments',
136
+ FRAGMENT_OWNER_KEY: '__fragmentOwner',
137
+ FRAGMENT_PROP_NAME_KEY: '__fragmentPropName',
138
+ MATCH_COMPONENT_KEY: '__match_component',
139
+ MATCH_FRAGMENT_KEY: '__match_fragment',
125
140
  ID_KEY: '__id',
141
+ MODULE_KEY: '__module',
126
142
  REF_KEY: '__ref',
127
143
  REFS_KEY: '__refs',
128
144
  ROOT_ID: 'client:root',
129
145
  ROOT_TYPE: '__Root',
130
146
  TYPENAME_KEY: '__typename',
131
- UNPUBLISH_RECORD_SENTINEL: Object.freeze({ __UNPUBLISH_RECORD_SENTINEL: true }),
132
- UNPUBLISH_FIELD_SENTINEL: Object.freeze({ __UNPUBLISH_FIELD_SENTINEL: true }),
133
-
147
+ UNPUBLISH_RECORD_SENTINEL: Object.freeze({
148
+ __UNPUBLISH_RECORD_SENTINEL: true
149
+ }),
150
+ UNPUBLISH_FIELD_SENTINEL: Object.freeze({
151
+ __UNPUBLISH_FIELD_SENTINEL: true
152
+ }),
134
153
  getArgumentValues: getArgumentValues,
135
154
  getHandleStorageKey: getHandleStorageKey,
136
155
  getStorageKey: getStorageKey,
137
156
  getStableStorageKey: getStableStorageKey
138
157
  };
139
-
140
158
  module.exports = RelayStoreUtils;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,12 +7,11 @@
7
7
  * strict-local
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
- var VIEWER_ID = require('./generateRelayClientID')(require('./RelayStoreUtils').ROOT_ID, 'viewer');
14
- var VIEWER_TYPE = 'Viewer';
12
+ var VIEWER_ID = require("./generateRelayClientID")(require("./RelayStoreUtils").ROOT_ID, 'viewer');
15
13
 
14
+ var VIEWER_TYPE = 'Viewer';
16
15
  /**
17
16
  * A runtime handler for the `viewer` field. The actual viewer record will
18
17
  * *never* be accessed at runtime because all fragments that reference it will
@@ -24,33 +23,38 @@ var VIEWER_TYPE = 'Viewer';
24
23
  * NOTE: This means other handles may not be added on viewer, since they may
25
24
  * execute after this handle when the server record is already deleted.
26
25
  */
26
+
27
27
  function update(store, payload) {
28
28
  var record = store.get(payload.dataID);
29
+
29
30
  if (!record) {
30
31
  return;
31
32
  }
33
+
32
34
  var serverViewer = record.getLinkedRecord(payload.fieldKey);
35
+
33
36
  if (!serverViewer) {
34
37
  // If `serverViewer` is null, `viewer` key for `client:root` should already
35
38
  // be null, so no need to `setValue` again.
36
39
  return;
37
- }
38
- // Server data already has viewer data at `client:root:viewer`, so link the
40
+ } // Server data already has viewer data at `client:root:viewer`, so link the
39
41
  // handle field to the server viewer record.
42
+
43
+
40
44
  if (serverViewer.getDataID() === VIEWER_ID) {
41
45
  record.setValue(null, payload.fieldKey);
42
46
  record.setLinkedRecord(serverViewer, payload.handleKey);
43
47
  return;
44
- }
45
- // Other ways to access viewer such as mutations may have a different id for
48
+ } // Other ways to access viewer such as mutations may have a different id for
46
49
  // viewer: synthesize a record at the canonical viewer id, copy its fields
47
50
  // from the server record, and delete the server record link to speed up GC.
51
+
52
+
48
53
  var clientViewer = store.get(VIEWER_ID) || store.create(VIEWER_ID, VIEWER_TYPE);
49
54
  clientViewer.copyFieldsFrom(serverViewer);
50
55
  record.setValue(null, payload.fieldKey);
51
- record.setLinkedRecord(clientViewer, payload.handleKey);
56
+ record.setLinkedRecord(clientViewer, payload.handleKey); // Make sure the root object points to the viewer object as well
52
57
 
53
- // Make sure the root object points to the viewer object as well
54
58
  var root = store.getRoot();
55
59
  root.setLinkedRecord(clientViewer, payload.handleKey);
56
60
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
7
7
  *
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  /**
@@ -15,23 +14,24 @@
15
14
  * environment.
16
15
  */
17
16
  function applyRelayModernOptimisticMutation(environment, config) {
18
- !require('./isRelayModernEnvironment')(environment) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'commitRelayModernMutation: expect `environment` to be an instance of ' + '`RelayModernEnvironment`.') : require('fbjs/lib/invariant')(false) : void 0;
17
+ !require("./isRelayModernEnvironment")(environment) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'commitRelayModernMutation: expected `environment` to be an instance of ' + '`RelayModernEnvironment`.\n' + 'When using Relay Modern and Relay Classic in the same ' + 'application, ensure mutations use Relay Compat to work in ' + 'both environments.\n' + 'See: http://facebook.github.io/relay/docs/relay-compat.html') : require("fbjs/lib/invariant")(false) : void 0;
19
18
  var _environment$unstable = environment.unstable_internal,
20
- createOperationSelector = _environment$unstable.createOperationSelector,
19
+ createOperationDescriptor = _environment$unstable.createOperationDescriptor,
21
20
  getRequest = _environment$unstable.getRequest;
22
-
23
21
  var mutation = getRequest(config.mutation);
24
- if (mutation.operationKind !== 'mutation') {
22
+
23
+ if (mutation.params.operationKind !== 'mutation') {
25
24
  throw new Error('commitRelayModernMutation: Expected mutation operation');
26
25
  }
26
+
27
27
  var optimisticUpdater = config.optimisticUpdater;
28
28
  var configs = config.configs,
29
29
  optimisticResponse = config.optimisticResponse,
30
30
  variables = config.variables;
31
+ var operation = createOperationDescriptor(mutation, variables);
31
32
 
32
- var operation = createOperationSelector(mutation, variables);
33
33
  if (configs) {
34
- var _RelayDeclarativeMuta = require('./RelayDeclarativeMutationConfig').convert(configs, mutation, optimisticUpdater);
34
+ var _RelayDeclarativeMuta = require("./RelayDeclarativeMutationConfig").convert(configs, mutation, optimisticUpdater);
35
35
 
36
36
  optimisticUpdater = _RelayDeclarativeMuta.optimisticUpdater;
37
37
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,12 +7,9 @@
7
7
  * strict-local
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
- var _extends3 = _interopRequireDefault(require('babel-runtime/helpers/extends'));
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
12
+ var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
16
13
 
17
14
  /**
18
15
  * @private
@@ -23,11 +20,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
23
20
  */
24
21
  function cloneRelayHandleSourceField(handleField, selections, variables) {
25
22
  var sourceField = selections.find(function (source) {
26
- return source.kind === require('./RelayConcreteNode').LINKED_FIELD && source.name === handleField.name && source.alias === handleField.alias && require('fbjs/lib/areEqual')(source.args, handleField.args);
23
+ return source.kind === require("./RelayConcreteNode").LINKED_FIELD && source.name === handleField.name && source.alias === handleField.alias && require("fbjs/lib/areEqual")(source.args, handleField.args);
27
24
  });
28
- !(sourceField && sourceField.kind === require('./RelayConcreteNode').LINKED_FIELD) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'cloneRelayHandleSourceField: Expected a corresponding source field for ' + 'handle `%s`.', handleField.handle) : require('fbjs/lib/invariant')(false) : void 0;
29
- var handleKey = require('./RelayStoreUtils').getHandleStorageKey(handleField, variables);
30
- var clonedField = (0, _extends3['default'])({}, sourceField, {
25
+ !(sourceField && sourceField.kind === require("./RelayConcreteNode").LINKED_FIELD) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'cloneRelayHandleSourceField: Expected a corresponding source field for ' + 'handle `%s`.', handleField.handle) : require("fbjs/lib/invariant")(false) : void 0;
26
+
27
+ var handleKey = require("./RelayStoreUtils").getHandleStorageKey(handleField, variables);
28
+
29
+ var clonedField = (0, _objectSpread2["default"])({}, sourceField, {
31
30
  args: null,
32
31
  name: handleKey,
33
32
  storageKey: handleKey
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
7
7
  * strict-local
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  function commitLocalUpdate(environment, updater) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
7
7
  *
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  /**
@@ -15,15 +14,20 @@
15
14
  * environment.
16
15
  */
17
16
  function commitRelayModernMutation(environment, config) {
18
- !require('./isRelayModernEnvironment')(environment) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'commitRelayModernMutation: expect `environment` to be an instance of ' + '`RelayModernEnvironment`.') : require('fbjs/lib/invariant')(false) : void 0;
17
+ !require("./isRelayModernEnvironment")(environment) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'commitRelayModernMutation: expected `environment` to be an instance of ' + '`RelayModernEnvironment`.\n' + 'When using Relay Modern and Relay Classic in the same ' + 'application, ensure mutations use Relay Compat to work in ' + 'both environments.\n' + 'See: http://facebook.github.io/relay/docs/relay-compat.html') : require("fbjs/lib/invariant")(false) : void 0;
19
18
  var _environment$unstable = environment.unstable_internal,
20
- createOperationSelector = _environment$unstable.createOperationSelector,
19
+ createOperationDescriptor = _environment$unstable.createOperationDescriptor,
21
20
  getRequest = _environment$unstable.getRequest;
22
-
23
21
  var mutation = getRequest(config.mutation);
24
- if (mutation.operationKind !== 'mutation') {
22
+
23
+ if (mutation.params.operationKind !== 'mutation') {
25
24
  throw new Error('commitRelayModernMutation: Expected mutation operation');
26
25
  }
26
+
27
+ if (mutation.kind !== 'Request') {
28
+ throw new Error('commitRelayModernMutation: Expected mutation to be of type request');
29
+ }
30
+
27
31
  var optimisticResponse = config.optimisticResponse,
28
32
  optimisticUpdater = config.optimisticUpdater,
29
33
  updater = config.updater;
@@ -31,23 +35,26 @@ function commitRelayModernMutation(environment, config) {
31
35
  onError = config.onError,
32
36
  variables = config.variables,
33
37
  uploadables = config.uploadables;
38
+ var operation = createOperationDescriptor(mutation, variables); // TODO: remove this check after we fix flow.
34
39
 
35
- var operation = createOperationSelector(mutation, variables);
36
- // TODO: remove this check after we fix flow.
37
40
  if (typeof optimisticResponse === 'function') {
38
41
  optimisticResponse = optimisticResponse();
39
- process.env.NODE_ENV !== 'production' ? require('fbjs/lib/warning')(false, 'commitRelayModernMutation: Expected `optimisticResponse` to be an object, ' + 'received a function.') : void 0;
42
+ process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'commitRelayModernMutation: Expected `optimisticResponse` to be an object, ' + 'received a function.') : void 0;
40
43
  }
41
- if (optimisticResponse && mutation.fragment.selections && mutation.fragment.selections.length === 1 && mutation.fragment.selections[0].kind === 'LinkedField') {
42
- var mutationRoot = mutation.fragment.selections[0].name;
43
- process.env.NODE_ENV !== 'production' ? require('fbjs/lib/warning')(optimisticResponse[mutationRoot], 'commitRelayModernMutation: Expected `optimisticResponse` to be wrapped ' + 'in mutation name `%s`', mutationRoot) : void 0;
44
+
45
+ if (process.env.NODE_ENV !== "production") {
46
+ if (optimisticResponse instanceof Object) {
47
+ require("./validateMutation")(optimisticResponse, mutation, config.variables);
48
+ }
44
49
  }
50
+
45
51
  if (configs) {
46
- var _RelayDeclarativeMuta = require('./RelayDeclarativeMutationConfig').convert(configs, mutation, optimisticUpdater, updater);
52
+ var _RelayDeclarativeMuta = require("./RelayDeclarativeMutationConfig").convert(configs, mutation, optimisticUpdater, updater);
47
53
 
48
54
  optimisticUpdater = _RelayDeclarativeMuta.optimisticUpdater;
49
55
  updater = _RelayDeclarativeMuta.updater;
50
56
  }
57
+
51
58
  return environment.executeMutation({
52
59
  operation: operation,
53
60
  optimisticResponse: optimisticResponse,
@@ -63,7 +70,7 @@ function commitRelayModernMutation(environment, config) {
63
70
 
64
71
  if (onCompleted) {
65
72
  var snapshot = environment.lookup(operation.fragment);
66
- onCompleted(snapshot.data, payload.response.errors);
73
+ onCompleted(snapshot.data, payload.errors);
67
74
  }
68
75
  },
69
76
  onError: onError
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,20 +7,19 @@
7
7
  *
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  function createRelayNetworkLogger(LoggerTransaction) {
14
13
  return {
15
14
  wrapFetch: function wrapFetch(fetch, graphiQLPrinter) {
16
15
  return function (request, variables, cacheConfig, uploadables) {
17
- var wrapped = wrapExecute(require('./ConvertToExecuteFunction').convertFetch(fetch), LoggerTransaction, graphiQLPrinter);
16
+ var wrapped = wrapExecute(require("./ConvertToExecuteFunction").convertFetch(fetch), LoggerTransaction, graphiQLPrinter);
18
17
  return wrapped(request, variables, cacheConfig, uploadables);
19
18
  };
20
19
  },
21
20
  wrapSubscribe: function wrapSubscribe(subscribe, graphiQLPrinter) {
22
21
  return function (request, variables, cacheConfig) {
23
- var wrapped = wrapExecute(require('./ConvertToExecuteFunction').convertSubscribe(subscribe), LoggerTransaction, graphiQLPrinter);
22
+ var wrapped = wrapExecute(require("./ConvertToExecuteFunction").convertSubscribe(subscribe), LoggerTransaction, graphiQLPrinter);
24
23
  return wrapped(request, variables, cacheConfig);
25
24
  };
26
25
  }
@@ -29,21 +28,25 @@ function createRelayNetworkLogger(LoggerTransaction) {
29
28
 
30
29
  function wrapExecute(execute, LoggerTransaction, graphiQLPrinter) {
31
30
  return function (request, variables, cacheConfig, uploadables) {
32
- var transaction = void 0;
31
+ var transaction;
33
32
 
34
33
  function addLogs(error, response, status) {
35
34
  // Only print GraphiQL links for non-batch requests.
36
- if (graphiQLPrinter && request.kind === require('./RelayConcreteNode').REQUEST) {
35
+ if (graphiQLPrinter) {
37
36
  transaction.addLog('GraphiQL', graphiQLPrinter(request, variables));
38
37
  }
38
+
39
39
  transaction.addLog('Cache Config', cacheConfig);
40
40
  transaction.addLog('Variables', JSON.stringify(variables, null, 2));
41
+
41
42
  if (status) {
42
43
  transaction.addLog('Status', status);
43
44
  }
45
+
44
46
  if (error) {
45
47
  transaction.addLog('Error', error);
46
48
  }
49
+
47
50
  if (response) {
48
51
  transaction.addLog('Response', response);
49
52
  }
@@ -60,10 +63,8 @@ function wrapExecute(execute, LoggerTransaction, graphiQLPrinter) {
60
63
  }
61
64
 
62
65
  var observable = execute(request, variables, cacheConfig, uploadables);
63
-
64
66
  var isSubscription = request.operationKind === 'subscription';
65
-
66
- return observable['do']({
67
+ return observable["do"]({
67
68
  start: function start() {
68
69
  transaction = new LoggerTransaction({
69
70
  request: request,
@@ -72,6 +73,7 @@ function wrapExecute(execute, LoggerTransaction, graphiQLPrinter) {
72
73
  uploadables: uploadables
73
74
  });
74
75
  console.time && console.time(transaction.getIdentifier());
76
+
75
77
  if (isSubscription) {
76
78
  flushLogs(null, null, 'subscription is sent.');
77
79
  }
package/lib/deepFreeze.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,9 +7,7 @@
7
7
  * strict
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
-
13
11
  /**
14
12
  * Recursively "deep" freezes the supplied object.
15
13
  *
@@ -21,6 +19,7 @@ function deepFreeze(object) {
21
19
  Object.freeze(object);
22
20
  Object.getOwnPropertyNames(object).forEach(function (name) {
23
21
  var property = object[name];
22
+
24
23
  if (property && typeof property === 'object' && !Object.isFrozen(property)) {
25
24
  deepFreeze(property);
26
25
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
7
7
  * strict-local
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  /**
@@ -15,23 +14,22 @@
15
14
  * fragment spreads are masked: fields must be explicitly listed in the query in
16
15
  * order to be accessible in the result object.
17
16
  */
18
-
19
17
  function fetchRelayModernQuery(environment, taggedNode, variables, cacheConfig) {
20
- !environment.unstable_internal ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'fetchRelayModernQuery: Expected a valid Relay environment, got `%s`.', environment) : require('fbjs/lib/invariant')(false) : void 0;
18
+ !environment.unstable_internal ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'fetchRelayModernQuery: Expected a valid Relay environment, got `%s`.', environment) : require("fbjs/lib/invariant")(false) : void 0;
21
19
  var _environment$unstable = environment.unstable_internal,
22
- createOperationSelector = _environment$unstable.createOperationSelector,
20
+ createOperationDescriptor = _environment$unstable.createOperationDescriptor,
23
21
  getRequest = _environment$unstable.getRequest;
24
-
25
22
  var query = getRequest(taggedNode);
26
- if (query.kind === require('./RelayConcreteNode').BATCH_REQUEST) {
27
- throw new Error('fetchRelayModernQuery: Batch request not supported in this API.');
28
- }
29
- if (query.operationKind !== 'query') {
23
+
24
+ if (query.params.operationKind !== 'query') {
30
25
  throw new Error('fetchRelayModernQuery: Expected query operation');
31
26
  }
32
- var operation = createOperationSelector(query, variables);
33
27
 
34
- return environment.execute({ operation: operation, cacheConfig: cacheConfig }).map(function () {
28
+ var operation = createOperationDescriptor(query, variables);
29
+ return environment.execute({
30
+ operation: operation,
31
+ cacheConfig: cacheConfig
32
+ }).map(function () {
35
33
  return environment.lookup(operation.fragment).data;
36
34
  }).toPromise();
37
35
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,19 +7,21 @@
7
7
  * strict
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  var PREFIX = 'client:';
14
13
 
15
14
  function generateRelayClientID(id, storageKey, index) {
16
15
  var key = id + ':' + storageKey;
16
+
17
17
  if (index != null) {
18
18
  key += ':' + index;
19
19
  }
20
+
20
21
  if (key.indexOf(PREFIX) !== 0) {
21
22
  key = PREFIX + key;
22
23
  }
24
+
23
25
  return key;
24
26
  }
25
27
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
7
7
  *
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  /**
@@ -17,12 +16,12 @@
17
16
  * source field.
18
17
  */
19
18
  function getRelayHandleKey(handleName, key, fieldName) {
20
- if (key && key !== require('./RelayDefaultHandleKey').DEFAULT_HANDLE_KEY) {
21
- return '__' + key + '_' + handleName;
19
+ if (key && key !== require("./RelayDefaultHandleKey").DEFAULT_HANDLE_KEY) {
20
+ return "__".concat(key, "_").concat(handleName);
22
21
  }
23
22
 
24
- !(fieldName != null) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'getRelayHandleKey: Expected either `fieldName` or `key` in `handle` to be provided') : require('fbjs/lib/invariant')(false) : void 0;
25
- return '__' + fieldName + '_' + handleName;
23
+ !(fieldName != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'getRelayHandleKey: Expected either `fieldName` or `key` in `handle` to be provided') : require("fbjs/lib/invariant")(false) : void 0;
24
+ return "__".concat(fieldName, "_").concat(handleName);
26
25
  }
27
26
 
28
27
  module.exports = getRelayHandleKey;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,16 +7,17 @@
7
7
  * strict-local
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  function hasOverlappingIDs(snapshot, updatedRecordIDs) {
14
13
  var keys = Object.keys(snapshot.seenRecords);
14
+
15
15
  for (var ii = 0; ii < keys.length; ii++) {
16
16
  if (updatedRecordIDs.hasOwnProperty(keys[ii])) {
17
17
  return true;
18
18
  }
19
19
  }
20
+
20
21
  return false;
21
22
  }
22
23