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.
- package/LICENSE +1 -1
- package/index.js +1 -1
- package/lib/ConvertToExecuteFunction.js +12 -75
- package/lib/DataChecker.js +400 -0
- package/lib/NormalizationNode.js +14 -0
- package/lib/ReaderNode.js +10 -0
- package/lib/RelayCombinedEnvironmentTypes.js +10 -0
- package/lib/RelayConcreteNode.js +12 -29
- package/lib/RelayConcreteVariables.js +17 -11
- package/lib/RelayConnectionHandler.js +98 -42
- package/lib/RelayConnectionInterface.js +5 -13
- package/lib/RelayCore.js +17 -14
- package/lib/RelayDeclarativeMutationConfig.js +69 -34
- package/lib/RelayDefaultHandleKey.js +1 -2
- package/lib/RelayDefaultHandlerProvider.js +6 -5
- package/lib/RelayError.js +6 -9
- package/lib/RelayInMemoryRecordSource.js +20 -22
- package/lib/RelayModernEnvironment.js +140 -229
- package/lib/RelayModernFragmentSpecResolver.js +110 -102
- package/lib/RelayModernGraphQLTag.js +53 -15
- package/lib/{RelayModernOperationSelector.js → RelayModernOperationDescriptor.js} +9 -8
- package/lib/RelayModernQueryExecutor.js +172 -0
- package/lib/RelayModernRecord.js +97 -38
- package/lib/RelayModernSelector.js +89 -33
- package/lib/RelayModernStore.js +301 -0
- package/lib/RelayNetwork.js +16 -28
- package/lib/RelayNetworkLogger.js +2 -3
- package/lib/RelayNetworkLoggerTransaction.js +32 -30
- package/lib/RelayNetworkTypes.js +1 -2
- package/lib/RelayObservable.js +127 -155
- package/lib/RelayProfiler.js +35 -22
- package/lib/RelayPublishQueue.js +144 -96
- package/lib/RelayQueryResponseCache.js +37 -21
- package/lib/RelayReader.js +194 -61
- package/lib/RelayRecordProxy.js +50 -31
- package/lib/RelayRecordSourceMutator.js +92 -51
- package/lib/RelayRecordSourceProxy.js +43 -35
- package/lib/RelayRecordSourceSelectorProxy.js +22 -21
- package/lib/RelayRecordState.js +1 -3
- package/lib/RelayReferenceMarker.js +110 -37
- package/lib/RelayResponseNormalizer.js +248 -82
- package/lib/RelayRuntimeTypes.js +1 -3
- package/lib/RelayStoreTypes.js +1 -2
- package/lib/RelayStoreUtils.js +37 -19
- package/lib/RelayViewerHandler.js +14 -10
- package/lib/applyRelayModernOptimisticMutation.js +8 -8
- package/lib/cloneRelayHandleSourceField.js +8 -9
- package/lib/commitLocalUpdate.js +1 -2
- package/lib/commitRelayModernMutation.js +21 -14
- package/lib/createRelayNetworkLogger.js +11 -9
- package/lib/deepFreeze.js +2 -3
- package/lib/fetchRelayModernQuery.js +10 -12
- package/lib/generateRelayClientID.js +4 -2
- package/lib/getRelayHandleKey.js +5 -6
- package/lib/hasOverlappingIDs.js +3 -2
- package/lib/index.js +59 -62
- package/lib/isPromise.js +1 -2
- package/lib/isRelayModernEnvironment.js +1 -3
- package/lib/isScalarAndEqual.js +1 -3
- package/lib/normalizePayload.js +17 -15
- package/lib/normalizeRelayPayload.js +9 -9
- package/lib/recycleNodesInto.js +25 -9
- package/lib/requestRelaySubscription.js +25 -58
- package/lib/simpleClone.js +2 -3
- package/lib/stableCopy.js +5 -3
- package/lib/validateMutation.js +146 -0
- package/package.json +3 -3
- package/relay-runtime.js +4 -0
- package/relay-runtime.min.js +9 -0
- package/lib/RelayDataLoader.js +0 -302
- package/lib/RelayMarkSweepStore.js +0 -242
- package/lib/deferrableFragmentKey.js +0 -20
package/lib/RelayStoreUtils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
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(
|
|
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(
|
|
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(
|
|
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 !==
|
|
117
|
-
return require(
|
|
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({
|
|
132
|
-
|
|
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)
|
|
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(
|
|
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)
|
|
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(
|
|
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
|
-
|
|
19
|
+
createOperationDescriptor = _environment$unstable.createOperationDescriptor,
|
|
21
20
|
getRequest = _environment$unstable.getRequest;
|
|
22
|
-
|
|
23
21
|
var mutation = getRequest(config.mutation);
|
|
24
|
-
|
|
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(
|
|
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)
|
|
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
|
|
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(
|
|
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(
|
|
29
|
-
|
|
30
|
-
var
|
|
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
|
package/lib/commitLocalUpdate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
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)
|
|
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(
|
|
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
|
-
|
|
19
|
+
createOperationDescriptor = _environment$unstable.createOperationDescriptor,
|
|
21
20
|
getRequest = _environment$unstable.getRequest;
|
|
22
|
-
|
|
23
21
|
var mutation = getRequest(config.mutation);
|
|
24
|
-
|
|
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 !==
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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(
|
|
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.
|
|
73
|
+
onCompleted(snapshot.data, payload.errors);
|
|
67
74
|
}
|
|
68
75
|
},
|
|
69
76
|
onError: onError
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
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(
|
|
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(
|
|
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
|
|
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
|
|
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)
|
|
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)
|
|
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 !==
|
|
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
|
-
|
|
20
|
+
createOperationDescriptor = _environment$unstable.createOperationDescriptor,
|
|
23
21
|
getRequest = _environment$unstable.getRequest;
|
|
24
|
-
|
|
25
22
|
var query = getRequest(taggedNode);
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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)
|
|
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
|
|
package/lib/getRelayHandleKey.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
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(
|
|
21
|
-
return
|
|
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 !==
|
|
25
|
-
return
|
|
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;
|
package/lib/hasOverlappingIDs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
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
|
|