relay-runtime 1.3.0 → 1.5.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 +16 -26
- package/index.js +3 -6
- package/lib/ConvertToExecuteFunction.js +73 -0
- package/lib/RelayConcreteNode.js +31 -14
- package/lib/RelayConcreteVariables.js +11 -6
- package/lib/RelayConnectionHandler.js +2 -4
- package/lib/RelayConnectionInterface.js +3 -5
- package/lib/RelayCore.js +4 -6
- package/lib/RelayDataLoader.js +2 -4
- package/lib/RelayDeclarativeMutationConfig.js +316 -0
- package/lib/RelayDefaultHandleKey.js +2 -4
- package/lib/RelayDefaultHandlerProvider.js +2 -4
- package/lib/RelayError.js +2 -6
- package/lib/RelayInMemoryRecordSource.js +2 -4
- package/lib/RelayInternalTypes.js +2 -5
- package/lib/RelayInternals.js +2 -5
- package/lib/RelayMarkSweepStore.js +22 -5
- package/lib/RelayMetricsRecorder.js +9 -9
- package/lib/RelayMockRenderer.js +3 -8
- package/lib/RelayModernEnvironment.js +120 -135
- package/lib/RelayModernFragmentSpecResolver.js +81 -55
- package/lib/RelayModernGraphQLTag.js +8 -17
- package/lib/RelayModernOperationSelector.js +8 -8
- package/lib/RelayModernRecord.js +8 -8
- package/lib/RelayModernSelector.js +54 -43
- package/lib/RelayNetwork.js +9 -11
- package/lib/RelayNetworkDebug.js +4 -7
- package/lib/RelayNetworkLogger.js +2 -4
- package/lib/RelayNetworkLoggerTransaction.js +18 -20
- package/lib/RelayNetworkTypes.js +2 -4
- package/lib/RelayObservable.js +193 -120
- package/lib/RelayProfiler.js +7 -7
- package/lib/RelayPublishQueue.js +17 -9
- package/lib/RelayQueryCaching.js +2 -5
- package/lib/RelayQueryResponseCache.js +3 -5
- package/lib/RelayReader.js +18 -8
- package/lib/RelayRecordProxy.js +12 -11
- package/lib/RelayRecordSourceMutator.js +9 -9
- package/lib/RelayRecordSourceProxy.js +15 -13
- package/lib/RelayRecordSourceSelectorProxy.js +2 -4
- package/lib/RelayRecordState.js +2 -4
- package/lib/RelayReferenceMarker.js +2 -4
- package/lib/RelayResponseNormalizer.js +34 -25
- package/lib/RelayRuntime.js +25 -14
- package/lib/RelayRuntimeTypes.js +22 -0
- package/lib/RelayShallowMock.js +4 -7
- package/lib/RelayStoreTypes.js +2 -4
- package/lib/RelayStoreUtils.js +66 -26
- package/lib/RelayTaskQueue.js +2 -5
- package/lib/RelayTypes.js +2 -5
- package/lib/RelayViewerHandler.js +4 -5
- package/lib/applyRelayModernOptimisticMutation.js +9 -8
- package/lib/cloneRelayHandleSourceField.js +4 -11
- package/lib/commitLocalUpdate.js +2 -4
- package/lib/commitRelayModernMutation.js +24 -22
- package/lib/createRelayNetworkLogger.js +25 -27
- package/lib/dedent.js +2 -5
- package/lib/deepFreeze.js +3 -5
- package/lib/deferrableFragmentKey.js +21 -0
- package/lib/fetchRelayModernQuery.js +13 -21
- package/lib/generateRelayClientID.js +2 -4
- package/lib/getRelayHandleKey.js +2 -4
- package/lib/hasOverlappingIDs.js +2 -4
- package/lib/isCompatibleRelayFragmentType.js +2 -5
- package/lib/isPromise.js +2 -5
- package/lib/isRelayModernEnvironment.js +2 -4
- package/lib/isScalarAndEqual.js +3 -5
- package/lib/normalizePayload.js +10 -13
- package/lib/normalizeRelayPayload.js +8 -5
- package/lib/recycleNodesInto.js +2 -4
- package/lib/relayUnstableBatchedUpdates.js +2 -5
- package/lib/relayUnstableBatchedUpdates.native.js +2 -5
- package/lib/requestRelaySubscription.js +20 -34
- package/lib/simpleClone.js +2 -4
- package/lib/stableCopy.js +35 -0
- package/lib/testEditDistance.js +2 -5
- package/lib/throwFailedPromise.js +2 -5
- package/package.json +4 -5
- package/relay-runtime.js +2307 -2665
- package/relay-runtime.min.js +6 -9
- package/ARCHITECTURE.md +0 -232
- package/PATENTS +0 -33
- package/lib/ConvertToObserveFunction.js +0 -39
- package/lib/RelayDebugger.js +0 -199
- package/lib/RelayRecordSourceInspector.js +0 -289
- package/lib/RelayStoreProxyDebugger.js +0 -44
- package/lib/formatStorageKey.js +0 -37
- package/lib/prettyStringify.js +0 -35
- package/lib/setRelayModernMutationConfigs.js +0 -302
- package/lib/stableJSONStringify.js +0 -45
package/lib/RelayStoreUtils.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayStoreUtils
|
|
10
8
|
*
|
|
@@ -17,7 +15,7 @@ var VARIABLE = require('./RelayConcreteNode').VARIABLE;
|
|
|
17
15
|
|
|
18
16
|
/**
|
|
19
17
|
* Returns the values of field/fragment arguments as an object keyed by argument
|
|
20
|
-
* names.
|
|
18
|
+
* names. Guaranteed to return a result with stable ordered nested values.
|
|
21
19
|
*/
|
|
22
20
|
|
|
23
21
|
|
|
@@ -25,19 +23,40 @@ function getArgumentValues(args, variables) {
|
|
|
25
23
|
var values = {};
|
|
26
24
|
args.forEach(function (arg) {
|
|
27
25
|
if (arg.kind === VARIABLE) {
|
|
28
|
-
|
|
26
|
+
// Variables are provided at runtime and are not guaranteed to be stable.
|
|
27
|
+
values[arg.name] = getStableVariableValue(arg.variableName, variables);
|
|
29
28
|
} else {
|
|
29
|
+
// The Relay compiler generates stable ConcreteArgument values.
|
|
30
30
|
values[arg.name] = arg.value;
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
return values;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Given a handle field and variable values, returns a key that can be used to
|
|
38
|
+
* uniquely identify the combination of the handle name and argument values.
|
|
39
|
+
*
|
|
40
|
+
* Note: the word "storage" here refers to the fact this key is primarily used
|
|
41
|
+
* when writing the results of a key in a normalized graph or "store". This
|
|
42
|
+
* name was used in previous implementations of Relay internals and is also
|
|
43
|
+
* used here for consistency.
|
|
44
|
+
*/
|
|
45
|
+
function getHandleStorageKey(handleField, variables) {
|
|
46
|
+
var handle = handleField.handle,
|
|
47
|
+
key = handleField.key,
|
|
48
|
+
name = handleField.name,
|
|
49
|
+
args = handleField.args,
|
|
50
|
+
filters = handleField.filters;
|
|
51
|
+
|
|
52
|
+
var handleName = require('./getRelayHandleKey')(handle, key, name);
|
|
53
|
+
if (!args || !filters || args.length === 0 || filters.length === 0) {
|
|
54
|
+
return handleName;
|
|
55
|
+
}
|
|
37
56
|
var filterArgs = args.filter(function (arg) {
|
|
38
57
|
return filters.indexOf(arg.name) > -1;
|
|
39
58
|
});
|
|
40
|
-
return getArgumentValues(filterArgs, variables);
|
|
59
|
+
return formatStorageKey(handleName, getArgumentValues(filterArgs, variables));
|
|
41
60
|
}
|
|
42
61
|
|
|
43
62
|
/**
|
|
@@ -51,36 +70,56 @@ function getHandleFilterValues(args, filters, variables) {
|
|
|
51
70
|
*/
|
|
52
71
|
function getStorageKey(field, variables) {
|
|
53
72
|
if (field.storageKey) {
|
|
73
|
+
// TODO T23663664: Handle nodes do not yet define a static storageKey.
|
|
54
74
|
return field.storageKey;
|
|
55
75
|
}
|
|
56
76
|
var args = field.args,
|
|
57
77
|
name = field.name;
|
|
58
78
|
|
|
59
|
-
|
|
79
|
+
return args && args.length !== 0 ? formatStorageKey(name, getArgumentValues(args, variables)) : name;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Given a `name` (eg. "foo") and an object representing argument values
|
|
84
|
+
* (eg. `{orberBy: "name", first: 10}`) returns a unique storage key
|
|
85
|
+
* (ie. `foo{"first":10,"orderBy":"name"}`).
|
|
86
|
+
*
|
|
87
|
+
* This differs from getStorageKey which requires a ConcreteNode where arguments
|
|
88
|
+
* are assumed to already be sorted into a stable order.
|
|
89
|
+
*/
|
|
90
|
+
function getStableStorageKey(name, args) {
|
|
91
|
+
return formatStorageKey(name, require('./stableCopy')(args));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Given a name and argument values, format a storage key.
|
|
96
|
+
*
|
|
97
|
+
* Arguments and the values within them are expected to be ordered in a stable
|
|
98
|
+
* alphabetical ordering.
|
|
99
|
+
*/
|
|
100
|
+
function formatStorageKey(name, argValues) {
|
|
101
|
+
if (!argValues) {
|
|
60
102
|
return name;
|
|
61
103
|
}
|
|
62
104
|
var values = [];
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
value
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
if (value != null) {
|
|
71
|
-
values.push('"' + arg.name + '":' + require('./stableJSONStringify')(value));
|
|
105
|
+
for (var _argName in argValues) {
|
|
106
|
+
if (argValues.hasOwnProperty(_argName)) {
|
|
107
|
+
var value = argValues[_argName];
|
|
108
|
+
if (value != null) {
|
|
109
|
+
values.push(_argName + ':' + JSON.stringify(value));
|
|
110
|
+
}
|
|
72
111
|
}
|
|
73
|
-
});
|
|
74
|
-
if (values.length) {
|
|
75
|
-
return field.name + ('{' + values.join(',') + '}');
|
|
76
|
-
} else {
|
|
77
|
-
return field.name;
|
|
78
112
|
}
|
|
113
|
+
return values.length === 0 ? name : name + ('(' + values.join(',') + ')');
|
|
79
114
|
}
|
|
80
115
|
|
|
81
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Given Variables and a variable name, return a variable value with
|
|
118
|
+
* all values in a stable order.
|
|
119
|
+
*/
|
|
120
|
+
function getStableVariableValue(name, variables) {
|
|
82
121
|
require('fbjs/lib/invariant')(variables.hasOwnProperty(name), 'getVariableValue(): Undefined variable `%s`.', name);
|
|
83
|
-
return variables[name];
|
|
122
|
+
return require('./stableCopy')(variables[name]);
|
|
84
123
|
}
|
|
85
124
|
|
|
86
125
|
/**
|
|
@@ -98,8 +137,9 @@ var RelayStoreUtils = {
|
|
|
98
137
|
UNPUBLISH_FIELD_SENTINEL: Object.freeze({ __UNPUBLISH_FIELD_SENTINEL: true }),
|
|
99
138
|
|
|
100
139
|
getArgumentValues: getArgumentValues,
|
|
140
|
+
getHandleStorageKey: getHandleStorageKey,
|
|
101
141
|
getStorageKey: getStorageKey,
|
|
102
|
-
|
|
142
|
+
getStableStorageKey: getStableStorageKey
|
|
103
143
|
};
|
|
104
144
|
|
|
105
145
|
module.exports = RelayStoreUtils;
|
package/lib/RelayTaskQueue.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
|
-
* @providesModule RelayTaskQueue
|
|
10
7
|
*
|
|
11
8
|
* @format
|
|
12
9
|
*/
|
package/lib/RelayTypes.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
|
-
* @providesModule RelayTypes
|
|
10
7
|
*
|
|
11
8
|
* @format
|
|
12
9
|
*/
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayViewerHandler
|
|
10
8
|
*
|
|
@@ -37,7 +35,8 @@ function update(store, payload) {
|
|
|
37
35
|
}
|
|
38
36
|
var serverViewer = record.getLinkedRecord(payload.fieldKey);
|
|
39
37
|
if (!serverViewer) {
|
|
40
|
-
|
|
38
|
+
// If `serverViewer` is null, `viewer` key for `client:root` should already
|
|
39
|
+
// be null, so no need to `setValue` again.
|
|
41
40
|
return;
|
|
42
41
|
}
|
|
43
42
|
// Server data already has viewer data at `client:root:viewer`, so link the
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule applyRelayModernOptimisticMutation
|
|
10
8
|
*
|
|
@@ -21,9 +19,12 @@ function applyRelayModernOptimisticMutation(environment, config) {
|
|
|
21
19
|
require('fbjs/lib/invariant')(require('./isRelayModernEnvironment')(environment), 'commitRelayModernMutation: expect `environment` to be an instance of ' + '`RelayModernEnvironment`.');
|
|
22
20
|
var _environment$unstable = environment.unstable_internal,
|
|
23
21
|
createOperationSelector = _environment$unstable.createOperationSelector,
|
|
24
|
-
|
|
22
|
+
getRequest = _environment$unstable.getRequest;
|
|
25
23
|
|
|
26
|
-
var mutation =
|
|
24
|
+
var mutation = getRequest(config.mutation);
|
|
25
|
+
if (mutation.operationKind !== 'mutation') {
|
|
26
|
+
throw new Error('commitRelayModernMutation: Expected mutation operation');
|
|
27
|
+
}
|
|
27
28
|
var optimisticUpdater = config.optimisticUpdater;
|
|
28
29
|
var configs = config.configs,
|
|
29
30
|
optimisticResponse = config.optimisticResponse,
|
|
@@ -31,9 +32,9 @@ function applyRelayModernOptimisticMutation(environment, config) {
|
|
|
31
32
|
|
|
32
33
|
var operation = createOperationSelector(mutation, variables);
|
|
33
34
|
if (configs) {
|
|
34
|
-
var
|
|
35
|
+
var _RelayDeclarativeMuta = require('./RelayDeclarativeMutationConfig').convert(configs, mutation, optimisticUpdater);
|
|
35
36
|
|
|
36
|
-
optimisticUpdater =
|
|
37
|
+
optimisticUpdater = _RelayDeclarativeMuta.optimisticUpdater;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
return environment.applyUpdate({
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule cloneRelayHandleSourceField
|
|
10
8
|
*
|
|
@@ -18,7 +16,7 @@ var _extends3 = _interopRequireDefault(require('babel-runtime/helpers/extends'))
|
|
|
18
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
19
17
|
|
|
20
18
|
var _require = require('./RelayStoreUtils'),
|
|
21
|
-
|
|
19
|
+
getHandleStorageKey = _require.getHandleStorageKey;
|
|
22
20
|
|
|
23
21
|
var LINKED_FIELD = require('./RelayConcreteNode').LINKED_FIELD;
|
|
24
22
|
|
|
@@ -36,12 +34,7 @@ function cloneRelayHandleSourceField(handleField, selections, variables) {
|
|
|
36
34
|
return source.kind === LINKED_FIELD && source.name === handleField.name && source.alias === handleField.alias && require('fbjs/lib/areEqual')(source.args, handleField.args);
|
|
37
35
|
});
|
|
38
36
|
require('fbjs/lib/invariant')(sourceField && sourceField.kind === LINKED_FIELD, 'cloneRelayHandleSourceField: Expected a corresponding source field for ' + 'handle `%s`.', handleField.handle);
|
|
39
|
-
var handleKey =
|
|
40
|
-
if (handleField.filters && handleField.filters.length > 0) {
|
|
41
|
-
var filterValues = getHandleFilterValues(handleField.args || [], handleField.filters, variables);
|
|
42
|
-
handleKey = require('./formatStorageKey')(handleKey, filterValues);
|
|
43
|
-
}
|
|
44
|
-
|
|
37
|
+
var handleKey = getHandleStorageKey(handleField, variables);
|
|
45
38
|
var clonedField = (0, _extends3['default'])({}, sourceField, {
|
|
46
39
|
args: null,
|
|
47
40
|
name: handleKey,
|
package/lib/commitLocalUpdate.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule commitLocalUpdate
|
|
10
8
|
*
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule commitRelayModernMutation
|
|
10
8
|
*
|
|
@@ -17,13 +15,20 @@
|
|
|
17
15
|
* Higher-level helper function to execute a mutation against a specific
|
|
18
16
|
* environment.
|
|
19
17
|
*/
|
|
20
|
-
function commitRelayModernMutation(
|
|
18
|
+
function commitRelayModernMutation(
|
|
19
|
+
/* $FlowFixMe(>=0.55.0 site=www) This comment suppresses an error found when
|
|
20
|
+
* Flow v0.55 was deployed. To see the error delete this comment and run
|
|
21
|
+
* Flow. */
|
|
22
|
+
environment, config) {
|
|
21
23
|
require('fbjs/lib/invariant')(require('./isRelayModernEnvironment')(environment), 'commitRelayModernMutation: expect `environment` to be an instance of ' + '`RelayModernEnvironment`.');
|
|
22
24
|
var _environment$unstable = environment.unstable_internal,
|
|
23
25
|
createOperationSelector = _environment$unstable.createOperationSelector,
|
|
24
|
-
|
|
26
|
+
getRequest = _environment$unstable.getRequest;
|
|
25
27
|
|
|
26
|
-
var mutation =
|
|
28
|
+
var mutation = getRequest(config.mutation);
|
|
29
|
+
if (mutation.operationKind !== 'mutation') {
|
|
30
|
+
throw new Error('commitRelayModernMutation: Expected mutation operation');
|
|
31
|
+
}
|
|
27
32
|
var optimisticResponse = config.optimisticResponse,
|
|
28
33
|
optimisticUpdater = config.optimisticUpdater,
|
|
29
34
|
updater = config.updater;
|
|
@@ -38,18 +43,17 @@ function commitRelayModernMutation(environment, config) {
|
|
|
38
43
|
optimisticResponse = optimisticResponse();
|
|
39
44
|
require('fbjs/lib/warning')(false, 'commitRelayModernMutation: Expected `optimisticResponse` to be an object, ' + 'received a function.');
|
|
40
45
|
}
|
|
41
|
-
if (optimisticResponse && mutation.
|
|
42
|
-
var mutationRoot = mutation.
|
|
46
|
+
if (optimisticResponse && mutation.fragment.selections && mutation.fragment.selections.length === 1 && mutation.fragment.selections[0].kind === 'LinkedField') {
|
|
47
|
+
var mutationRoot = mutation.fragment.selections[0].name;
|
|
43
48
|
require('fbjs/lib/warning')(optimisticResponse[mutationRoot], 'commitRelayModernMutation: Expected `optimisticResponse` to be wrapped ' + 'in mutation name `%s`', mutationRoot);
|
|
44
49
|
}
|
|
45
50
|
if (configs) {
|
|
46
|
-
var
|
|
51
|
+
var _RelayDeclarativeMuta = require('./RelayDeclarativeMutationConfig').convert(configs, mutation, optimisticUpdater, updater);
|
|
47
52
|
|
|
48
|
-
optimisticUpdater =
|
|
49
|
-
updater =
|
|
53
|
+
optimisticUpdater = _RelayDeclarativeMuta.optimisticUpdater;
|
|
54
|
+
updater = _RelayDeclarativeMuta.updater;
|
|
50
55
|
}
|
|
51
|
-
|
|
52
|
-
return environment.observeMutation({
|
|
56
|
+
return environment.executeMutation({
|
|
53
57
|
operation: operation,
|
|
54
58
|
optimisticResponse: optimisticResponse,
|
|
55
59
|
optimisticUpdater: optimisticUpdater,
|
|
@@ -57,19 +61,17 @@ function commitRelayModernMutation(environment, config) {
|
|
|
57
61
|
uploadables: uploadables
|
|
58
62
|
}).subscribeLegacy({
|
|
59
63
|
onNext: function onNext(payload) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
onCompleted: function onCompleted() {
|
|
64
|
-
// NOTE: MutationConfig has a non-standard use of onCompleted() by passing
|
|
65
|
-
// it a value and errors.
|
|
64
|
+
// NOTE: commitRelayModernMutation has a non-standard use of
|
|
65
|
+
// onCompleted() by calling it on every next value. It may be called
|
|
66
|
+
// multiple times if a network request produces multiple responses.
|
|
66
67
|
var onCompleted = config.onCompleted;
|
|
67
68
|
|
|
68
69
|
if (onCompleted) {
|
|
69
70
|
var snapshot = environment.lookup(operation.fragment);
|
|
70
|
-
onCompleted(snapshot.data, errors);
|
|
71
|
+
onCompleted(snapshot.data, payload.response.errors);
|
|
71
72
|
}
|
|
72
|
-
}
|
|
73
|
+
},
|
|
74
|
+
onError: onError
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
77
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule createRelayNetworkLogger
|
|
10
8
|
*
|
|
@@ -13,44 +11,38 @@
|
|
|
13
11
|
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _require = require('./ConvertToObserveFunction'),
|
|
14
|
+
var _require = require('./ConvertToExecuteFunction'),
|
|
19
15
|
convertFetch = _require.convertFetch,
|
|
20
16
|
convertSubscribe = _require.convertSubscribe;
|
|
21
17
|
|
|
22
18
|
function createRelayNetworkLogger(LoggerTransaction) {
|
|
23
19
|
return {
|
|
24
20
|
wrapFetch: function wrapFetch(fetch, graphiQLPrinter) {
|
|
25
|
-
return function (
|
|
26
|
-
var wrapped =
|
|
27
|
-
return wrapped(
|
|
21
|
+
return function (request, variables, cacheConfig, uploadables) {
|
|
22
|
+
var wrapped = wrapExecute(convertFetch(fetch), LoggerTransaction, graphiQLPrinter);
|
|
23
|
+
return wrapped(request, variables, cacheConfig, uploadables);
|
|
28
24
|
};
|
|
29
25
|
},
|
|
30
26
|
wrapSubscribe: function wrapSubscribe(subscribe, graphiQLPrinter) {
|
|
31
|
-
return function (
|
|
32
|
-
var wrapped =
|
|
33
|
-
return wrapped(
|
|
27
|
+
return function (request, variables, cacheConfig) {
|
|
28
|
+
var wrapped = wrapExecute(convertSubscribe(subscribe), LoggerTransaction, graphiQLPrinter);
|
|
29
|
+
return wrapped(request, variables, cacheConfig);
|
|
34
30
|
};
|
|
35
31
|
}
|
|
36
32
|
};
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
function
|
|
40
|
-
return function (
|
|
41
|
-
var transaction =
|
|
42
|
-
operation: operation,
|
|
43
|
-
variables: variables,
|
|
44
|
-
cacheConfig: cacheConfig,
|
|
45
|
-
uploadables: uploadables
|
|
46
|
-
});
|
|
35
|
+
function wrapExecute(execute, LoggerTransaction, graphiQLPrinter) {
|
|
36
|
+
return function (request, variables, cacheConfig, uploadables) {
|
|
37
|
+
var transaction = void 0;
|
|
47
38
|
|
|
48
39
|
function addLogs(error, response, status) {
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
// Only print GraphiQL links for non-batch requests.
|
|
41
|
+
if (graphiQLPrinter && request.kind === require('./RelayConcreteNode').REQUEST) {
|
|
42
|
+
transaction.addLog('GraphiQL', graphiQLPrinter(request, variables));
|
|
51
43
|
}
|
|
52
44
|
transaction.addLog('Cache Config', cacheConfig);
|
|
53
|
-
transaction.addLog('Variables',
|
|
45
|
+
transaction.addLog('Variables', JSON.stringify(variables, null, 2));
|
|
54
46
|
if (status) {
|
|
55
47
|
transaction.addLog('Status', status);
|
|
56
48
|
}
|
|
@@ -72,12 +64,18 @@ function wrapObserve(observe, LoggerTransaction, graphiQLPrinter) {
|
|
|
72
64
|
transaction.commitLogs(error, response, status);
|
|
73
65
|
}
|
|
74
66
|
|
|
75
|
-
var observable =
|
|
67
|
+
var observable = execute(request, variables, cacheConfig, uploadables);
|
|
76
68
|
|
|
77
|
-
var isSubscription =
|
|
69
|
+
var isSubscription = request.operationKind === 'subscription';
|
|
78
70
|
|
|
79
71
|
return observable['do']({
|
|
80
72
|
start: function start() {
|
|
73
|
+
transaction = new LoggerTransaction({
|
|
74
|
+
request: request,
|
|
75
|
+
variables: variables,
|
|
76
|
+
cacheConfig: cacheConfig,
|
|
77
|
+
uploadables: uploadables
|
|
78
|
+
});
|
|
81
79
|
console.time && console.time(transaction.getIdentifier());
|
|
82
80
|
if (isSubscription) {
|
|
83
81
|
flushLogs(null, null, 'subscription is sent.');
|
|
@@ -100,7 +98,7 @@ function wrapObserve(observe, LoggerTransaction, graphiQLPrinter) {
|
|
|
100
98
|
}
|
|
101
99
|
},
|
|
102
100
|
unsubscribe: function unsubscribe() {
|
|
103
|
-
return commitLogs(null, null, isSubscription ? 'subscription is unsubscribed.' : '
|
|
101
|
+
return commitLogs(null, null, isSubscription ? 'subscription is unsubscribed.' : 'execution is unsubscribed.');
|
|
104
102
|
}
|
|
105
103
|
});
|
|
106
104
|
};
|
package/lib/dedent.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
|
-
* @providesModule dedent
|
|
10
7
|
*
|
|
11
8
|
* @format
|
|
12
9
|
*/
|
package/lib/deepFreeze.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
7
|
* @providesModule deepFreeze
|
|
8
|
+
*
|
|
11
9
|
* @format
|
|
12
10
|
*/
|
|
13
11
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @providesModule deferrableFragmentKey
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
function deferrableFragmentKey(dataID, fragmentName, variables) {
|
|
15
|
+
var variablesString = Object.keys(variables).reduce(function (acc, key) {
|
|
16
|
+
return '' + acc + (acc ? ',' : '') + key + ':' + variables[key];
|
|
17
|
+
}, '');
|
|
18
|
+
return 'dataID:' + dataID + ',fragment:' + fragmentName + ',variables:' + variablesString;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = deferrableFragmentKey;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule fetchRelayModernQuery
|
|
10
8
|
*
|
|
@@ -30,26 +28,20 @@ function fetchRelayModernQuery(environment, taggedNode, variables, cacheConfig)
|
|
|
30
28
|
require('fbjs/lib/invariant')(environment.unstable_internal, 'fetchRelayModernQuery: Expected a valid Relay environment, got `%s`.', environment);
|
|
31
29
|
var _environment$unstable = environment.unstable_internal,
|
|
32
30
|
createOperationSelector = _environment$unstable.createOperationSelector,
|
|
33
|
-
|
|
31
|
+
getRequest = _environment$unstable.getRequest;
|
|
34
32
|
|
|
35
|
-
var query =
|
|
33
|
+
var query = getRequest(taggedNode);
|
|
34
|
+
if (query.kind === require('./RelayConcreteNode').BATCH_REQUEST) {
|
|
35
|
+
throw new Error('fetchRelayModernQuery: Batch request not supported in this API.');
|
|
36
|
+
}
|
|
37
|
+
if (query.operationKind !== 'query') {
|
|
38
|
+
throw new Error('fetchRelayModernQuery: Expected query operation');
|
|
39
|
+
}
|
|
36
40
|
var operation = createOperationSelector(query, variables);
|
|
37
|
-
return new Promise(function (resolve, reject) {
|
|
38
|
-
environment.sendQuery({
|
|
39
|
-
cacheConfig: cacheConfig,
|
|
40
|
-
onError: reject,
|
|
41
|
-
onCompleted: function onCompleted() {
|
|
42
|
-
try {
|
|
43
|
-
var snapshot = environment.lookup(operation.fragment);
|
|
44
|
-
resolve(snapshot.data);
|
|
45
|
-
} catch (e) {
|
|
46
|
-
reject(e);
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
41
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
42
|
+
return environment.execute({ operation: operation, cacheConfig: cacheConfig }).map(function () {
|
|
43
|
+
return environment.lookup(operation.fragment).data;
|
|
44
|
+
}).toPromise();
|
|
53
45
|
}
|
|
54
46
|
|
|
55
47
|
module.exports = fetchRelayModernQuery;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule generateRelayClientID
|
|
10
8
|
*
|
package/lib/getRelayHandleKey.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
*
|
|
10
8
|
* @providesModule getRelayHandleKey
|
package/lib/hasOverlappingIDs.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule hasOverlappingIDs
|
|
10
8
|
*
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
|
-
* @providesModule isCompatibleRelayFragmentType
|
|
10
7
|
*
|
|
11
8
|
* @format
|
|
12
9
|
*/
|