relay-runtime 13.0.0-rc.2 → 13.0.3
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/README.md +1 -4
- package/index.js +2 -2
- package/index.js.flow +4 -0
- package/lib/index.js +7 -1
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +22 -17
- package/lib/mutations/validateMutation.js +11 -1
- package/lib/network/RelayNetwork.js +7 -3
- package/lib/query/fetchQuery.js +3 -0
- package/lib/store/RelayConcreteVariables.js +12 -3
- package/lib/store/RelayExperimentalGraphResponseTransform.js +34 -2
- package/lib/store/RelayModernOperationDescriptor.js +1 -1
- package/lib/store/RelayPublishQueue.js +4 -2
- package/lib/store/RelayReader.js +55 -13
- package/lib/store/RelayStoreUtils.js +1 -0
- package/lib/store/ResolverCache.js +10 -2
- package/lib/store/ResolverFragments.js +2 -2
- package/lib/subscription/requestSubscription.js +0 -2
- package/lib/util/withProvidedVariables.js +49 -0
- package/mutations/RelayDeclarativeMutationConfig.js.flow +0 -1
- package/mutations/commitMutation.js.flow +8 -19
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +47 -49
- package/mutations/validateMutation.js.flow +14 -2
- package/network/RelayNetwork.js.flow +10 -3
- package/network/RelayNetworkTypes.js.flow +1 -1
- package/package.json +6 -2
- package/query/fetchQuery.js.flow +9 -7
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +3 -3
- package/store/RelayConcreteVariables.js.flow +12 -2
- package/store/RelayExperimentalGraphResponseTransform.js.flow +35 -1
- package/store/RelayModernOperationDescriptor.js.flow +5 -1
- package/store/RelayModernStore.js.flow +0 -1
- package/store/RelayPublishQueue.js.flow +8 -1
- package/store/RelayReader.js.flow +78 -31
- package/store/RelayStoreTypes.js.flow +3 -2
- package/store/RelayStoreUtils.js.flow +1 -0
- package/store/ResolverCache.js.flow +18 -5
- package/store/ResolverFragments.js.flow +2 -2
- package/subscription/requestSubscription.js.flow +7 -13
- package/util/NormalizationNode.js.flow +16 -16
- package/util/ReaderNode.js.flow +15 -15
- package/util/RelayConcreteNode.js.flow +4 -2
- package/util/withProvidedVariables.js.flow +64 -0
- package/lib/util/getAllRootVariables.js +0 -29
- package/util/getAllRootVariables.js.flow +0 -36
package/util/ReaderNode.js.flow
CHANGED
|
@@ -18,7 +18,7 @@ import type {ConcreteRequest} from './RelayConcreteNode';
|
|
|
18
18
|
export type ReaderFragmentSpread = {|
|
|
19
19
|
+kind: 'FragmentSpread',
|
|
20
20
|
+name: string,
|
|
21
|
-
+args
|
|
21
|
+
+args?: ?$ReadOnlyArray<ReaderArgument>,
|
|
22
22
|
|};
|
|
23
23
|
|
|
24
24
|
export type ReaderInlineDataFragmentSpread = {|
|
|
@@ -31,8 +31,8 @@ export type ReaderFragment = {|
|
|
|
31
31
|
+kind: 'Fragment',
|
|
32
32
|
+name: string,
|
|
33
33
|
+type: string,
|
|
34
|
-
+abstractKey
|
|
35
|
-
+metadata
|
|
34
|
+
+abstractKey?: ?string,
|
|
35
|
+
+metadata?: ?{|
|
|
36
36
|
+connection?: $ReadOnlyArray<ConnectionMetadata>,
|
|
37
37
|
+mask?: boolean,
|
|
38
38
|
+plural?: boolean,
|
|
@@ -64,7 +64,7 @@ export type ReaderPaginationFragment = {|
|
|
|
64
64
|
|};
|
|
65
65
|
|
|
66
66
|
export type ReaderRefetchMetadata = {|
|
|
67
|
-
+connection
|
|
67
|
+
+connection?: ?ReaderPaginationMetadata,
|
|
68
68
|
+operation: string | ConcreteRequest,
|
|
69
69
|
+fragmentPathInResult: Array<string>,
|
|
70
70
|
+identifierField?: ?string,
|
|
@@ -122,26 +122,26 @@ export type ReaderInlineFragment = {|
|
|
|
122
122
|
+kind: 'InlineFragment',
|
|
123
123
|
+selections: $ReadOnlyArray<ReaderSelection>,
|
|
124
124
|
+type: string,
|
|
125
|
-
+abstractKey
|
|
125
|
+
+abstractKey?: ?string,
|
|
126
126
|
|};
|
|
127
127
|
|
|
128
128
|
export type ReaderLinkedField = {|
|
|
129
129
|
+kind: 'LinkedField',
|
|
130
|
-
+alias
|
|
130
|
+
+alias?: ?string,
|
|
131
131
|
+name: string,
|
|
132
|
-
+storageKey
|
|
133
|
-
+args
|
|
134
|
-
+concreteType
|
|
132
|
+
+storageKey?: ?string,
|
|
133
|
+
+args?: ?$ReadOnlyArray<ReaderArgument>,
|
|
134
|
+
+concreteType?: ?string,
|
|
135
135
|
+plural: boolean,
|
|
136
136
|
+selections: $ReadOnlyArray<ReaderSelection>,
|
|
137
137
|
|};
|
|
138
138
|
|
|
139
139
|
export type ReaderActorChange = {|
|
|
140
140
|
+kind: 'ActorChange',
|
|
141
|
-
+alias
|
|
141
|
+
+alias?: ?string,
|
|
142
142
|
+name: string,
|
|
143
|
-
+storageKey
|
|
144
|
-
+args
|
|
143
|
+
+storageKey?: ?string,
|
|
144
|
+
+args?: ?$ReadOnlyArray<ReaderArgument>,
|
|
145
145
|
+fragmentSpread: ReaderFragmentSpread,
|
|
146
146
|
|};
|
|
147
147
|
|
|
@@ -186,10 +186,10 @@ export type ReaderNode =
|
|
|
186
186
|
|
|
187
187
|
export type ReaderScalarField = {|
|
|
188
188
|
+kind: 'ScalarField',
|
|
189
|
-
+alias
|
|
189
|
+
+alias?: ?string,
|
|
190
190
|
+name: string,
|
|
191
|
-
+args
|
|
192
|
-
+storageKey
|
|
191
|
+
+args?: ?$ReadOnlyArray<ReaderArgument>,
|
|
192
|
+
+storageKey?: ?string,
|
|
193
193
|
|};
|
|
194
194
|
|
|
195
195
|
export type ReaderFlightField = {|
|
|
@@ -35,6 +35,8 @@ export type NormalizationRootNode =
|
|
|
35
35
|
| ConcreteRequest
|
|
36
36
|
| NormalizationSplitOperation;
|
|
37
37
|
|
|
38
|
+
export type ProvidedVariablesType = {+[key: string]: {|get(): mixed|}};
|
|
39
|
+
|
|
38
40
|
/**
|
|
39
41
|
* Contains the parameters required for executing a GraphQL request.
|
|
40
42
|
* The operation can either be provided as a persisted `id` or `text`. If given
|
|
@@ -48,7 +50,7 @@ export type RequestParameters =
|
|
|
48
50
|
// common fields
|
|
49
51
|
+name: string,
|
|
50
52
|
+operationKind: 'mutation' | 'query' | 'subscription',
|
|
51
|
-
+providedVariables?:
|
|
53
|
+
+providedVariables?: ProvidedVariablesType,
|
|
52
54
|
+metadata: {[key: string]: mixed, ...},
|
|
53
55
|
|}
|
|
54
56
|
| {|
|
|
@@ -58,7 +60,7 @@ export type RequestParameters =
|
|
|
58
60
|
// common fields
|
|
59
61
|
+name: string,
|
|
60
62
|
+operationKind: 'mutation' | 'query' | 'subscription',
|
|
61
|
-
+providedVariables?:
|
|
63
|
+
+providedVariables?: ProvidedVariablesType,
|
|
62
64
|
+metadata: {[key: string]: mixed, ...},
|
|
63
65
|
|};
|
|
64
66
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
* @emails oncall+relay
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// flowlint ambiguous-object-type:error
|
|
13
|
+
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
import type {ProvidedVariablesType} from './RelayConcreteNode';
|
|
17
|
+
import type {Variables} from './RelayRuntimeTypes';
|
|
18
|
+
|
|
19
|
+
const areEqual = require('areEqual');
|
|
20
|
+
const warning = require('warning');
|
|
21
|
+
|
|
22
|
+
const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
|
23
|
+
const debugCache = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
|
|
24
|
+
|
|
25
|
+
function withProvidedVariables(
|
|
26
|
+
userSuppliedVariables: Variables,
|
|
27
|
+
providedVariables: ?ProvidedVariablesType,
|
|
28
|
+
): Variables {
|
|
29
|
+
if (providedVariables != null) {
|
|
30
|
+
const operationVariables = {};
|
|
31
|
+
Object.assign(operationVariables, userSuppliedVariables);
|
|
32
|
+
Object.keys(providedVariables).forEach((varName: string) => {
|
|
33
|
+
const providerFunction = providedVariables[varName].get;
|
|
34
|
+
const providerResult = providerFunction();
|
|
35
|
+
|
|
36
|
+
// people like to ignore these warnings, so use the cache to
|
|
37
|
+
// enforce that we only compute the value the first time
|
|
38
|
+
if (!debugCache.has(providerFunction)) {
|
|
39
|
+
debugCache.set(providerFunction, providerResult);
|
|
40
|
+
operationVariables[varName] = providerResult;
|
|
41
|
+
} else {
|
|
42
|
+
const cachedResult = debugCache.get(providerFunction);
|
|
43
|
+
|
|
44
|
+
if (__DEV__) {
|
|
45
|
+
warning(
|
|
46
|
+
areEqual(providerResult, cachedResult),
|
|
47
|
+
'Relay: Expected function `%s` for provider `%s` to be a pure function, ' +
|
|
48
|
+
'but got conflicting return values `%s` and `%s`',
|
|
49
|
+
providerFunction.name,
|
|
50
|
+
varName,
|
|
51
|
+
providerResult,
|
|
52
|
+
cachedResult,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
operationVariables[varName] = cachedResult;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return operationVariables;
|
|
59
|
+
} else {
|
|
60
|
+
return userSuppliedVariables;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = withProvidedVariables;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @emails oncall+relay
|
|
10
|
-
*/
|
|
11
|
-
// flowlint ambiguous-object-type:error
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
function getAllRootVariables(userSuppliedVariables, parameters) {
|
|
15
|
-
var providedVariables = parameters.providedVariables;
|
|
16
|
-
|
|
17
|
-
if (providedVariables != null) {
|
|
18
|
-
var allVariables = {};
|
|
19
|
-
Object.assign(allVariables, userSuppliedVariables);
|
|
20
|
-
Object.keys(providedVariables).forEach(function (varName) {
|
|
21
|
-
allVariables[varName] = providedVariables[varName].get();
|
|
22
|
-
});
|
|
23
|
-
return allVariables;
|
|
24
|
-
} else {
|
|
25
|
-
return userSuppliedVariables;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = getAllRootVariables;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
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
|
-
* @flow strict-local
|
|
8
|
-
* @format
|
|
9
|
-
* @emails oncall+relay
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
import type {RequestParameters} from './RelayConcreteNode';
|
|
17
|
-
import type {Variables} from './RelayRuntimeTypes';
|
|
18
|
-
|
|
19
|
-
function getAllRootVariables(
|
|
20
|
-
userSuppliedVariables: Variables,
|
|
21
|
-
parameters: RequestParameters,
|
|
22
|
-
): Variables {
|
|
23
|
-
const providedVariables = parameters.providedVariables;
|
|
24
|
-
if (providedVariables != null) {
|
|
25
|
-
const allVariables = {};
|
|
26
|
-
Object.assign(allVariables, userSuppliedVariables);
|
|
27
|
-
Object.keys(providedVariables).forEach((varName: string) => {
|
|
28
|
-
allVariables[varName] = providedVariables[varName].get();
|
|
29
|
-
});
|
|
30
|
-
return allVariables;
|
|
31
|
-
} else {
|
|
32
|
-
return userSuppliedVariables;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = getAllRootVariables;
|