relay-runtime 13.0.0 → 13.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/index.js.flow +2 -0
- package/lib/index.js +4 -1
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +20 -15
- package/lib/network/RelayNetwork.js +7 -3
- package/lib/query/fetchQuery.js +3 -0
- package/lib/store/RelayConcreteVariables.js +13 -3
- package/lib/store/RelayModernOperationDescriptor.js +1 -1
- package/lib/util/{getAllRootVariables.js → withProvidedVariables.js} +6 -6
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +45 -47
- package/network/RelayNetwork.js.flow +7 -3
- package/package.json +1 -1
- package/query/fetchQuery.js.flow +9 -7
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/RelayConcreteVariables.js.flow +13 -2
- package/store/RelayModernOperationDescriptor.js.flow +5 -1
- package/util/{getAllRootVariables.js.flow → withProvidedVariables.js.flow} +6 -6
package/index.js
CHANGED
package/index.js.flow
CHANGED
|
@@ -70,6 +70,7 @@ const RelayProfiler = require('./util/RelayProfiler');
|
|
|
70
70
|
const RelayReplaySubject = require('./util/RelayReplaySubject');
|
|
71
71
|
const reportMissingRequiredFields = require('./util/reportMissingRequiredFields');
|
|
72
72
|
const stableCopy = require('./util/stableCopy');
|
|
73
|
+
const withProvidedVariables = require('./util/withProvidedVariables');
|
|
73
74
|
|
|
74
75
|
export type {ConnectionMetadata} from './handlers/connection/ConnectionHandler';
|
|
75
76
|
export type {
|
|
@@ -362,5 +363,6 @@ module.exports = {
|
|
|
362
363
|
getPromiseForActiveRequest: fetchQueryInternal.getPromiseForActiveRequest,
|
|
363
364
|
getObservableForActiveRequest:
|
|
364
365
|
fetchQueryInternal.getObservableForActiveRequest,
|
|
366
|
+
withProvidedVariables: withProvidedVariables,
|
|
365
367
|
},
|
|
366
368
|
};
|
package/lib/index.js
CHANGED
|
@@ -121,6 +121,8 @@ var reportMissingRequiredFields = require('./util/reportMissingRequiredFields');
|
|
|
121
121
|
|
|
122
122
|
var stableCopy = require('./util/stableCopy');
|
|
123
123
|
|
|
124
|
+
var withProvidedVariables = require('./util/withProvidedVariables');
|
|
125
|
+
|
|
124
126
|
// As early as possible, check for the existence of the JavaScript globals which
|
|
125
127
|
// Relay Runtime relies upon, and produce a clear message if they do not exist.
|
|
126
128
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -239,6 +241,7 @@ module.exports = {
|
|
|
239
241
|
fetchQuery: fetchQueryInternal.fetchQuery,
|
|
240
242
|
fetchQueryDeduped: fetchQueryInternal.fetchQueryDeduped,
|
|
241
243
|
getPromiseForActiveRequest: fetchQueryInternal.getPromiseForActiveRequest,
|
|
242
|
-
getObservableForActiveRequest: fetchQueryInternal.getObservableForActiveRequest
|
|
244
|
+
getObservableForActiveRequest: fetchQueryInternal.getObservableForActiveRequest,
|
|
245
|
+
withProvidedVariables: withProvidedVariables
|
|
243
246
|
}
|
|
244
247
|
};
|
|
@@ -37,7 +37,7 @@ function readUpdatableQuery_EXPERIMENTAL(query, variables, proxy) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVariables, selections, root) {
|
|
40
|
-
var _selection$
|
|
40
|
+
var _selection$alias3;
|
|
41
41
|
|
|
42
42
|
var _iterator = (0, _createForOfIteratorHelper2["default"])(selections),
|
|
43
43
|
_step;
|
|
@@ -48,21 +48,23 @@ function updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVari
|
|
|
48
48
|
|
|
49
49
|
switch (selection.kind) {
|
|
50
50
|
case 'LinkedField':
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
if (selection.plural) {
|
|
52
|
+
Object.defineProperty(mutableUpdatableProxy, (_selection$alias = selection.alias) !== null && _selection$alias !== void 0 ? _selection$alias : selection.name, {
|
|
53
|
+
// $FlowFixMe[incompatible-call] these getters and setters have different types on purpose
|
|
54
|
+
get: createGetterForPluralLinkedField(selection, queryVariables, recordProxy, root),
|
|
55
|
+
set: createSetterForPluralLinkedField(selection, queryVariables, recordProxy, root)
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
Object.defineProperty(mutableUpdatableProxy, (_selection$alias2 = selection.alias) !== null && _selection$alias2 !== void 0 ? _selection$alias2 : selection.name, {
|
|
59
|
+
get: createGetterForSingularLinkedField(selection, queryVariables, recordProxy, root),
|
|
60
|
+
set: createSetterForSingularLinkedField(selection, queryVariables, recordProxy, root)
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
62
64
|
break;
|
|
63
65
|
|
|
64
66
|
case 'ScalarField':
|
|
65
|
-
var scalarFieldName = (_selection$
|
|
67
|
+
var scalarFieldName = (_selection$alias3 = selection.alias) !== null && _selection$alias3 !== void 0 ? _selection$alias3 : selection.name;
|
|
66
68
|
Object.defineProperty(mutableUpdatableProxy, scalarFieldName, {
|
|
67
69
|
get: function get() {
|
|
68
70
|
var _selection$args;
|
|
@@ -106,6 +108,10 @@ function updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVari
|
|
|
106
108
|
};
|
|
107
109
|
|
|
108
110
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
111
|
+
var _selection$alias;
|
|
112
|
+
|
|
113
|
+
var _selection$alias2;
|
|
114
|
+
|
|
109
115
|
_loop();
|
|
110
116
|
}
|
|
111
117
|
} catch (err) {
|
|
@@ -122,8 +128,7 @@ function createSetterForPluralLinkedField(selection, queryVariables, recordProxy
|
|
|
122
128
|
var variables = getArgumentValues((_selection$args3 = selection.args) !== null && _selection$args3 !== void 0 ? _selection$args3 : [], queryVariables);
|
|
123
129
|
|
|
124
130
|
if (newValue == null) {
|
|
125
|
-
|
|
126
|
-
recordProxy.setValue(null, selection.name, variables);
|
|
131
|
+
throw new Error('Do not assign null to plural linked fields; assign an empty array instead.');
|
|
127
132
|
} else {
|
|
128
133
|
var recordProxies = newValue.map(function (item) {
|
|
129
134
|
if (item == null) {
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
var withProvidedVariables = require('../util/withProvidedVariables');
|
|
14
|
+
|
|
13
15
|
var _require = require('./ConvertToExecuteFunction'),
|
|
14
16
|
convertFetch = _require.convertFetch;
|
|
15
17
|
|
|
@@ -25,22 +27,24 @@ function create(fetchFn, subscribe) {
|
|
|
25
27
|
var observeFetch = convertFetch(fetchFn);
|
|
26
28
|
|
|
27
29
|
function execute(request, variables, cacheConfig, uploadables, logRequestInfo) {
|
|
30
|
+
var operationVariables = withProvidedVariables(variables, request);
|
|
31
|
+
|
|
28
32
|
if (request.operationKind === 'subscription') {
|
|
29
33
|
!subscribe ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayNetwork: This network layer does not support Subscriptions. ' + 'To use Subscriptions, provide a custom network layer.') : invariant(false) : void 0;
|
|
30
34
|
!!uploadables ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayNetwork: Cannot provide uploadables while subscribing.') : invariant(false) : void 0;
|
|
31
|
-
return subscribe(request,
|
|
35
|
+
return subscribe(request, operationVariables, cacheConfig);
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
var pollInterval = cacheConfig.poll;
|
|
35
39
|
|
|
36
40
|
if (pollInterval != null) {
|
|
37
41
|
!!uploadables ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayNetwork: Cannot provide uploadables while polling.') : invariant(false) : void 0;
|
|
38
|
-
return observeFetch(request,
|
|
42
|
+
return observeFetch(request, operationVariables, {
|
|
39
43
|
force: true
|
|
40
44
|
}).poll(pollInterval);
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
return observeFetch(request,
|
|
47
|
+
return observeFetch(request, operationVariables, cacheConfig, uploadables, logRequestInfo);
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
return {
|
package/lib/query/fetchQuery.js
CHANGED
|
@@ -122,6 +122,9 @@ function fetchQuery(environment, query, variables, options) {
|
|
|
122
122
|
if (snapshot.missingRequiredFields != null) {
|
|
123
123
|
reportMissingRequiredFields(environment, snapshot.missingRequiredFields);
|
|
124
124
|
}
|
|
125
|
+
/* $FlowFixMe[incompatible-return] we assume readData returns the right
|
|
126
|
+
* data just having written it from network or checked availability. */
|
|
127
|
+
|
|
125
128
|
|
|
126
129
|
return snapshot.data;
|
|
127
130
|
}
|
|
@@ -68,13 +68,15 @@ function getFragmentVariables(fragment, rootVariables, argumentVariables) {
|
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* Determines the variables that are in scope for a given operation given values
|
|
71
|
-
* for some/all of its arguments.
|
|
72
|
-
*
|
|
71
|
+
* for some/all of its arguments.
|
|
72
|
+
* - extraneous input variables are filtered from the output
|
|
73
|
+
* - missing variables are set to default values (if given in the
|
|
73
74
|
* operation's definition).
|
|
75
|
+
* - variables with provider modules are added
|
|
74
76
|
*/
|
|
75
77
|
|
|
76
78
|
|
|
77
|
-
function getOperationVariables(operation, variables) {
|
|
79
|
+
function getOperationVariables(operation, parameters, variables) {
|
|
78
80
|
var operationVariables = {};
|
|
79
81
|
operation.argumentDefinitions.forEach(function (def) {
|
|
80
82
|
var value = def.defaultValue;
|
|
@@ -85,6 +87,14 @@ function getOperationVariables(operation, variables) {
|
|
|
85
87
|
|
|
86
88
|
operationVariables[def.name] = value;
|
|
87
89
|
});
|
|
90
|
+
var providedVariables = parameters.providedVariables;
|
|
91
|
+
|
|
92
|
+
if (providedVariables != null) {
|
|
93
|
+
Object.keys(providedVariables).forEach(function (varName) {
|
|
94
|
+
operationVariables[varName] = providedVariables[varName].get();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
88
98
|
return operationVariables;
|
|
89
99
|
}
|
|
90
100
|
|
|
@@ -34,7 +34,7 @@ var _require3 = require('./RelayStoreUtils'),
|
|
|
34
34
|
function createOperationDescriptor(request, variables, cacheConfig) {
|
|
35
35
|
var dataID = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ROOT_ID;
|
|
36
36
|
var operation = request.operation;
|
|
37
|
-
var operationVariables = getOperationVariables(operation, variables);
|
|
37
|
+
var operationVariables = getOperationVariables(operation, request.params, variables);
|
|
38
38
|
var requestDescriptor = createRequestDescriptor(request, operationVariables, cacheConfig);
|
|
39
39
|
var operationDescriptor = {
|
|
40
40
|
fragment: createReaderSelector(request.fragment, dataID, operationVariables, requestDescriptor),
|
|
@@ -11,19 +11,19 @@
|
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
function
|
|
14
|
+
function withProvidedVariables(userSuppliedVariables, parameters) {
|
|
15
15
|
var providedVariables = parameters.providedVariables;
|
|
16
16
|
|
|
17
17
|
if (providedVariables != null) {
|
|
18
|
-
var
|
|
19
|
-
Object.assign(
|
|
18
|
+
var operationVariables = {};
|
|
19
|
+
Object.assign(operationVariables, userSuppliedVariables);
|
|
20
20
|
Object.keys(providedVariables).forEach(function (varName) {
|
|
21
|
-
|
|
21
|
+
operationVariables[varName] = providedVariables[varName].get();
|
|
22
22
|
});
|
|
23
|
-
return
|
|
23
|
+
return operationVariables;
|
|
24
24
|
} else {
|
|
25
25
|
return userSuppliedVariables;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
module.exports =
|
|
29
|
+
module.exports = withProvidedVariables;
|
|
@@ -55,50 +55,46 @@ function updateProxyFromSelections<TQuery: OperationType>(
|
|
|
55
55
|
for (const selection of selections) {
|
|
56
56
|
switch (selection.kind) {
|
|
57
57
|
case 'LinkedField':
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
get,
|
|
99
|
-
set,
|
|
100
|
-
},
|
|
101
|
-
);
|
|
58
|
+
if (selection.plural) {
|
|
59
|
+
Object.defineProperty(
|
|
60
|
+
mutableUpdatableProxy,
|
|
61
|
+
selection.alias ?? selection.name,
|
|
62
|
+
{
|
|
63
|
+
// $FlowFixMe[incompatible-call] these getters and setters have different types on purpose
|
|
64
|
+
get: createGetterForPluralLinkedField(
|
|
65
|
+
selection,
|
|
66
|
+
queryVariables,
|
|
67
|
+
recordProxy,
|
|
68
|
+
root,
|
|
69
|
+
),
|
|
70
|
+
set: createSetterForPluralLinkedField(
|
|
71
|
+
selection,
|
|
72
|
+
queryVariables,
|
|
73
|
+
recordProxy,
|
|
74
|
+
root,
|
|
75
|
+
),
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
} else {
|
|
79
|
+
Object.defineProperty(
|
|
80
|
+
mutableUpdatableProxy,
|
|
81
|
+
selection.alias ?? selection.name,
|
|
82
|
+
{
|
|
83
|
+
get: createGetterForSingularLinkedField(
|
|
84
|
+
selection,
|
|
85
|
+
queryVariables,
|
|
86
|
+
recordProxy,
|
|
87
|
+
root,
|
|
88
|
+
),
|
|
89
|
+
set: createSetterForSingularLinkedField(
|
|
90
|
+
selection,
|
|
91
|
+
queryVariables,
|
|
92
|
+
recordProxy,
|
|
93
|
+
root,
|
|
94
|
+
),
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
}
|
|
102
98
|
break;
|
|
103
99
|
case 'ScalarField':
|
|
104
100
|
const scalarFieldName = selection.alias ?? selection.name;
|
|
@@ -171,11 +167,12 @@ function createSetterForPluralLinkedField<TQuery: OperationType>(
|
|
|
171
167
|
recordProxy: RecordProxy,
|
|
172
168
|
root: RecordSourceProxy,
|
|
173
169
|
) {
|
|
174
|
-
return function set(newValue:
|
|
170
|
+
return function set(newValue: $ReadOnlyArray<{__id: string, ...}>) {
|
|
175
171
|
const variables = getArgumentValues(selection.args ?? [], queryVariables);
|
|
176
172
|
if (newValue == null) {
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
throw new Error(
|
|
174
|
+
'Do not assign null to plural linked fields; assign an empty array instead.',
|
|
175
|
+
);
|
|
179
176
|
} else {
|
|
180
177
|
const recordProxies = newValue.map(item => {
|
|
181
178
|
if (item == null) {
|
|
@@ -206,6 +203,7 @@ function createSetterForPluralLinkedField<TQuery: OperationType>(
|
|
|
206
203
|
}
|
|
207
204
|
};
|
|
208
205
|
}
|
|
206
|
+
|
|
209
207
|
function createSetterForSingularLinkedField<TQuery: OperationType>(
|
|
210
208
|
selection: ReaderLinkedField,
|
|
211
209
|
queryVariables: TQuery['variables'],
|
|
@@ -24,6 +24,7 @@ import type {
|
|
|
24
24
|
} from './RelayNetworkTypes';
|
|
25
25
|
import type RelayObservable from './RelayObservable';
|
|
26
26
|
|
|
27
|
+
const withProvidedVariables = require('../util/withProvidedVariables');
|
|
27
28
|
const {convertFetch} = require('./ConvertToExecuteFunction');
|
|
28
29
|
const invariant = require('invariant');
|
|
29
30
|
|
|
@@ -45,6 +46,7 @@ function create(
|
|
|
45
46
|
uploadables?: ?UploadableMap,
|
|
46
47
|
logRequestInfo: ?LogRequestInfoFunction,
|
|
47
48
|
): RelayObservable<GraphQLResponse> {
|
|
49
|
+
const operationVariables = withProvidedVariables(variables, request);
|
|
48
50
|
if (request.operationKind === 'subscription') {
|
|
49
51
|
invariant(
|
|
50
52
|
subscribe,
|
|
@@ -56,7 +58,7 @@ function create(
|
|
|
56
58
|
!uploadables,
|
|
57
59
|
'RelayNetwork: Cannot provide uploadables while subscribing.',
|
|
58
60
|
);
|
|
59
|
-
return subscribe(request,
|
|
61
|
+
return subscribe(request, operationVariables, cacheConfig);
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
const pollInterval = cacheConfig.poll;
|
|
@@ -65,12 +67,14 @@ function create(
|
|
|
65
67
|
!uploadables,
|
|
66
68
|
'RelayNetwork: Cannot provide uploadables while polling.',
|
|
67
69
|
);
|
|
68
|
-
return observeFetch(request,
|
|
70
|
+
return observeFetch(request, operationVariables, {force: true}).poll(
|
|
71
|
+
pollInterval,
|
|
72
|
+
);
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
return observeFetch(
|
|
72
76
|
request,
|
|
73
|
-
|
|
77
|
+
operationVariables,
|
|
74
78
|
cacheConfig,
|
|
75
79
|
uploadables,
|
|
76
80
|
logRequestInfo,
|
package/package.json
CHANGED
package/query/fetchQuery.js.flow
CHANGED
|
@@ -22,9 +22,9 @@ import type {
|
|
|
22
22
|
CacheConfig,
|
|
23
23
|
FetchQueryFetchPolicy,
|
|
24
24
|
OperationType,
|
|
25
|
-
|
|
25
|
+
Query,
|
|
26
|
+
Variables,
|
|
26
27
|
} from '../util/RelayRuntimeTypes';
|
|
27
|
-
import type {GraphQLTaggedNode} from './GraphQLTag';
|
|
28
28
|
|
|
29
29
|
const RelayObservable = require('../network/RelayObservable');
|
|
30
30
|
const {
|
|
@@ -112,15 +112,15 @@ const invariant = require('invariant');
|
|
|
112
112
|
* ```
|
|
113
113
|
* NOTE: When using .toPromise(), the request cannot be cancelled.
|
|
114
114
|
*/
|
|
115
|
-
function fetchQuery<
|
|
115
|
+
function fetchQuery<TVariables: Variables, TData, TRawResponse>(
|
|
116
116
|
environment: IEnvironment,
|
|
117
|
-
query:
|
|
118
|
-
variables:
|
|
117
|
+
query: Query<TVariables, TData, TRawResponse>,
|
|
118
|
+
variables: TVariables,
|
|
119
119
|
options?: $ReadOnly<{|
|
|
120
120
|
fetchPolicy?: FetchQueryFetchPolicy,
|
|
121
121
|
networkCacheConfig?: CacheConfig,
|
|
122
122
|
|}>,
|
|
123
|
-
): RelayObservable<
|
|
123
|
+
): RelayObservable<TData> {
|
|
124
124
|
const queryNode = getRequest(query);
|
|
125
125
|
invariant(
|
|
126
126
|
queryNode.params.operationKind === 'query',
|
|
@@ -137,10 +137,12 @@ function fetchQuery<TQuery: OperationType>(
|
|
|
137
137
|
);
|
|
138
138
|
const fetchPolicy = options?.fetchPolicy ?? 'network-only';
|
|
139
139
|
|
|
140
|
-
function readData(snapshot: Snapshot) {
|
|
140
|
+
function readData(snapshot: Snapshot): TData {
|
|
141
141
|
if (snapshot.missingRequiredFields != null) {
|
|
142
142
|
reportMissingRequiredFields(environment, snapshot.missingRequiredFields);
|
|
143
143
|
}
|
|
144
|
+
/* $FlowFixMe[incompatible-return] we assume readData returns the right
|
|
145
|
+
* data just having written it from network or checked availability. */
|
|
144
146
|
return snapshot.data;
|
|
145
147
|
}
|
|
146
148
|
|