relay-runtime 13.0.3 → 13.2.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/index.js +1 -1
- package/index.js.flow +4 -2
- package/lib/index.js +3 -3
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +3 -4
- package/lib/query/GraphQLTag.js +13 -0
- package/lib/query/fetchQuery.js +2 -5
- package/lib/store/RelayModernEnvironment.js +3 -3
- package/lib/store/RelayModernFragmentSpecResolver.js +6 -6
- package/lib/store/RelayModernSelector.js +16 -2
- package/lib/store/RelayReader.js +71 -6
- package/lib/store/RelayStoreSubscriptions.js +4 -2
- package/lib/store/RelayStoreUtils.js +1 -0
- package/lib/store/ResolverCache.js +25 -13
- package/lib/store/experimental-live-resolvers/LiveResolverCache.js +316 -0
- package/lib/store/experimental-live-resolvers/LiveResolverStore.js +787 -0
- package/lib/store/hasOverlappingIDs.js +1 -1
- package/lib/util/RelayConcreteNode.js +2 -0
- package/lib/util/RelayFeatureFlags.js +0 -3
- package/lib/util/handlePotentialSnapshotErrors.js +73 -0
- package/mutations/RelayRecordSourceProxy.js.flow +7 -3
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -3
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +14 -12
- package/network/RelayNetworkTypes.js.flow +1 -1
- package/package.json +1 -1
- package/query/GraphQLTag.js.flow +38 -3
- package/query/fetchQuery.js.flow +6 -4
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/RelayModernEnvironment.js.flow +3 -3
- package/store/RelayModernFragmentSpecResolver.js.flow +11 -7
- package/store/RelayModernSelector.js.flow +32 -8
- package/store/RelayReader.js.flow +65 -23
- package/store/RelayResponseNormalizer.js.flow +1 -1
- package/store/RelayStoreSubscriptions.js.flow +2 -0
- package/store/RelayStoreTypes.js.flow +22 -8
- package/store/RelayStoreUtils.js.flow +2 -1
- package/store/ResolverCache.js.flow +45 -10
- package/store/defaultGetDataID.js.flow +1 -1
- package/store/experimental-live-resolvers/LiveResolverCache.js.flow +410 -0
- package/store/experimental-live-resolvers/LiveResolverStore.js.flow +822 -0
- package/store/hasOverlappingIDs.js.flow +1 -1
- package/util/ReaderNode.js.flow +17 -1
- package/util/RelayConcreteNode.js.flow +9 -1
- package/util/RelayFeatureFlags.js.flow +0 -6
- package/util/RelayRuntimeTypes.js.flow +20 -1
- package/util/deepFreeze.js.flow +1 -1
- package/util/handlePotentialSnapshotErrors.js.flow +63 -0
- package/util/isEmptyObject.js.flow +1 -1
- package/lib/util/reportMissingRequiredFields.js +0 -48
- package/util/reportMissingRequiredFields.js.flow +0 -51
|
@@ -20,7 +20,7 @@ function hasOverlappingIDs(
|
|
|
20
20
|
seenRecords: DataIDSet,
|
|
21
21
|
updatedRecordIDs: DataIDSet,
|
|
22
22
|
): boolean {
|
|
23
|
-
// $FlowFixMe: Set is an iterable type, accessing its iterator is allowed.
|
|
23
|
+
// $FlowFixMe[incompatible-use]: Set is an iterable type, accessing its iterator is allowed.
|
|
24
24
|
const iterator = seenRecords[ITERATOR_KEY]();
|
|
25
25
|
let next = iterator.next();
|
|
26
26
|
while (!next.done) {
|
package/util/ReaderNode.js.flow
CHANGED
|
@@ -111,7 +111,8 @@ export type ReaderClientExtension = {|
|
|
|
111
111
|
export type ReaderField =
|
|
112
112
|
| ReaderScalarField
|
|
113
113
|
| ReaderLinkedField
|
|
114
|
-
| ReaderRelayResolver
|
|
114
|
+
| ReaderRelayResolver
|
|
115
|
+
| ReaderRelayLiveResolver;
|
|
115
116
|
|
|
116
117
|
export type ReaderRootArgument = {|
|
|
117
118
|
+kind: 'RootArgument',
|
|
@@ -224,6 +225,21 @@ export type ReaderRelayResolver = {|
|
|
|
224
225
|
+alias: ?string,
|
|
225
226
|
+name: string,
|
|
226
227
|
+fragment: ReaderFragmentSpread,
|
|
228
|
+
+path: string,
|
|
229
|
+
+resolverModule: (rootKey: {
|
|
230
|
+
+$data?: any, // flowlint-line unclear-type:off
|
|
231
|
+
+$fragmentSpreads: any, // flowlint-line unclear-type:off
|
|
232
|
+
+$fragmentRefs: any, // flowlint-line unclear-type:off
|
|
233
|
+
...
|
|
234
|
+
}) => mixed,
|
|
235
|
+
|};
|
|
236
|
+
|
|
237
|
+
export type ReaderRelayLiveResolver = {|
|
|
238
|
+
+kind: 'RelayLiveResolver',
|
|
239
|
+
+alias: ?string,
|
|
240
|
+
+name: string,
|
|
241
|
+
+fragment: ReaderFragmentSpread,
|
|
242
|
+
+path: string,
|
|
227
243
|
+resolverModule: (rootKey: {
|
|
228
244
|
+$data?: any, // flowlint-line unclear-type:off
|
|
229
245
|
+$fragmentSpreads: any, // flowlint-line unclear-type:off
|
|
@@ -31,6 +31,11 @@ export type ConcreteRequest = {|
|
|
|
31
31
|
+params: RequestParameters,
|
|
32
32
|
|};
|
|
33
33
|
|
|
34
|
+
export type ConcreteUpdatableQuery = {|
|
|
35
|
+
+kind: 'UpdatableQuery',
|
|
36
|
+
+fragment: ReaderFragment,
|
|
37
|
+
|};
|
|
38
|
+
|
|
34
39
|
export type NormalizationRootNode =
|
|
35
40
|
| ConcreteRequest
|
|
36
41
|
| NormalizationSplitOperation;
|
|
@@ -68,7 +73,8 @@ export type GeneratedNode =
|
|
|
68
73
|
| ConcreteRequest
|
|
69
74
|
| ReaderFragment
|
|
70
75
|
| ReaderInlineDataFragment
|
|
71
|
-
| NormalizationSplitOperation
|
|
76
|
+
| NormalizationSplitOperation
|
|
77
|
+
| ConcreteUpdatableQuery;
|
|
72
78
|
|
|
73
79
|
const RelayConcreteNode = {
|
|
74
80
|
ACTOR_CHANGE: 'ActorChange',
|
|
@@ -91,6 +97,7 @@ const RelayConcreteNode = {
|
|
|
91
97
|
LOCAL_ARGUMENT: 'LocalArgument',
|
|
92
98
|
MODULE_IMPORT: 'ModuleImport',
|
|
93
99
|
RELAY_RESOLVER: 'RelayResolver',
|
|
100
|
+
RELAY_LIVE_RESOLVER: 'RelayLiveResolver',
|
|
94
101
|
REQUIRED_FIELD: 'RequiredField',
|
|
95
102
|
OBJECT_VALUE: 'ObjectValue',
|
|
96
103
|
OPERATION: 'Operation',
|
|
@@ -101,6 +108,7 @@ const RelayConcreteNode = {
|
|
|
101
108
|
SPLIT_OPERATION: 'SplitOperation',
|
|
102
109
|
STREAM: 'Stream',
|
|
103
110
|
TYPE_DISCRIMINATOR: 'TypeDiscriminator',
|
|
111
|
+
UPDATABLE_QUERY: 'UpdatableQuery',
|
|
104
112
|
VARIABLE: 'Variable',
|
|
105
113
|
};
|
|
106
114
|
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
import type {Disposable} from '../util/RelayRuntimeTypes';
|
|
16
16
|
|
|
17
17
|
export type FeatureFlags = {|
|
|
18
|
-
DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES: boolean,
|
|
19
18
|
ENABLE_CLIENT_EDGES: boolean,
|
|
20
19
|
ENABLE_VARIABLE_CONNECTION_KEY: boolean,
|
|
21
20
|
ENABLE_PARTIAL_RENDERING_DEFAULT: boolean,
|
|
@@ -28,15 +27,12 @@ export type FeatureFlags = {|
|
|
|
28
27
|
ENABLE_NOTIFY_SUBSCRIPTION: boolean,
|
|
29
28
|
BATCH_ASYNC_MODULE_UPDATES_FN: ?(() => void) => Disposable,
|
|
30
29
|
ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT: boolean,
|
|
31
|
-
ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT: boolean,
|
|
32
30
|
MAX_DATA_ID_LENGTH: ?number,
|
|
33
|
-
REFACTOR_SUSPENSE_RESOURCE: boolean,
|
|
34
31
|
STRING_INTERN_LEVEL: number,
|
|
35
32
|
USE_REACT_CACHE: boolean,
|
|
36
33
|
|};
|
|
37
34
|
|
|
38
35
|
const RelayFeatureFlags: FeatureFlags = {
|
|
39
|
-
DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES: false,
|
|
40
36
|
ENABLE_CLIENT_EDGES: false,
|
|
41
37
|
ENABLE_VARIABLE_CONNECTION_KEY: false,
|
|
42
38
|
ENABLE_PARTIAL_RENDERING_DEFAULT: true,
|
|
@@ -49,9 +45,7 @@ const RelayFeatureFlags: FeatureFlags = {
|
|
|
49
45
|
ENABLE_NOTIFY_SUBSCRIPTION: false,
|
|
50
46
|
BATCH_ASYNC_MODULE_UPDATES_FN: null,
|
|
51
47
|
ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT: false,
|
|
52
|
-
ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT: false,
|
|
53
48
|
MAX_DATA_ID_LENGTH: null,
|
|
54
|
-
REFACTOR_SUSPENSE_RESOURCE: true,
|
|
55
49
|
STRING_INTERN_LEVEL: 0,
|
|
56
50
|
USE_REACT_CACHE: false,
|
|
57
51
|
};
|
|
@@ -17,7 +17,10 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import type {ReaderFragment, ReaderInlineDataFragment} from './ReaderNode';
|
|
20
|
-
import type {
|
|
20
|
+
import type {
|
|
21
|
+
ConcreteRequest,
|
|
22
|
+
ConcreteUpdatableQuery,
|
|
23
|
+
} from './RelayConcreteNode';
|
|
21
24
|
|
|
22
25
|
/**
|
|
23
26
|
* Represents any resource that must be explicitly disposed of. The most common
|
|
@@ -41,6 +44,14 @@ export type OperationType = {|
|
|
|
41
44
|
+rawResponse?: {...},
|
|
42
45
|
|};
|
|
43
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Generated updatable query flow types are subtypes of this.
|
|
49
|
+
*/
|
|
50
|
+
export type UpdatableQueryType = {|
|
|
51
|
+
+variables: Variables,
|
|
52
|
+
+response: mixed,
|
|
53
|
+
|};
|
|
54
|
+
|
|
44
55
|
export type VariablesOf<T: OperationType> = T['variables'];
|
|
45
56
|
|
|
46
57
|
/**
|
|
@@ -84,6 +95,14 @@ declare export opaque type Operation<
|
|
|
84
95
|
TRawResponse,
|
|
85
96
|
>: ConcreteRequest;
|
|
86
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Return type of graphql tag literals for updatable queries.
|
|
100
|
+
*/
|
|
101
|
+
declare export opaque type UpdatableQuery<
|
|
102
|
+
-TVariables: Variables,
|
|
103
|
+
+TData,
|
|
104
|
+
>: ConcreteUpdatableQuery;
|
|
105
|
+
|
|
87
106
|
/**
|
|
88
107
|
* Return type of graphql tag literals for queries.
|
|
89
108
|
*/
|
package/util/deepFreeze.js.flow
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* For convenience, and for consistency with the behavior of `Object.freeze`,
|
|
19
19
|
* returns the now-frozen original object.
|
|
20
20
|
*/
|
|
21
|
-
function deepFreeze<T:
|
|
21
|
+
function deepFreeze<T: {...}>(object: T): T {
|
|
22
22
|
Object.freeze(object);
|
|
23
23
|
Object.getOwnPropertyNames(object).forEach(name => {
|
|
24
24
|
// $FlowFixMe[prop-missing]
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
|
8
|
+
* @emails oncall+relay
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
import type {
|
|
15
|
+
IEnvironment,
|
|
16
|
+
MissingRequiredFields,
|
|
17
|
+
RelayResolverErrors,
|
|
18
|
+
} from '../store/RelayStoreTypes';
|
|
19
|
+
|
|
20
|
+
function handlePotentialSnapshotErrors(
|
|
21
|
+
environment: IEnvironment,
|
|
22
|
+
missingRequiredFields: ?MissingRequiredFields,
|
|
23
|
+
relayResolverErrors: RelayResolverErrors,
|
|
24
|
+
) {
|
|
25
|
+
for (const resolverError of relayResolverErrors) {
|
|
26
|
+
environment.requiredFieldLogger({
|
|
27
|
+
kind: 'relay_resolver.error',
|
|
28
|
+
owner: resolverError.field.owner,
|
|
29
|
+
fieldPath: resolverError.field.path,
|
|
30
|
+
error: resolverError.error,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (missingRequiredFields != null) {
|
|
34
|
+
switch (missingRequiredFields.action) {
|
|
35
|
+
case 'THROW': {
|
|
36
|
+
const {path, owner} = missingRequiredFields.field;
|
|
37
|
+
// This gives the consumer the chance to throw their own error if they so wish.
|
|
38
|
+
environment.requiredFieldLogger({
|
|
39
|
+
kind: 'missing_field.throw',
|
|
40
|
+
owner,
|
|
41
|
+
fieldPath: path,
|
|
42
|
+
});
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Relay: Missing @required value at path '${path}' in '${owner}'.`,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
case 'LOG':
|
|
48
|
+
missingRequiredFields.fields.forEach(({path, owner}) => {
|
|
49
|
+
environment.requiredFieldLogger({
|
|
50
|
+
kind: 'missing_field.log',
|
|
51
|
+
owner,
|
|
52
|
+
fieldPath: path,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
break;
|
|
56
|
+
default: {
|
|
57
|
+
(missingRequiredFields.action: empty);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = handlePotentialSnapshotErrors;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
15
15
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
16
16
|
|
|
17
|
-
function isEmptyObject(obj:
|
|
17
|
+
function isEmptyObject(obj: {+[key: string]: mixed}): boolean {
|
|
18
18
|
for (const key in obj) {
|
|
19
19
|
if (hasOwnProperty.call(obj, key)) {
|
|
20
20
|
return false;
|
|
@@ -1,48 +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
|
-
* @emails oncall+relay
|
|
9
|
-
* @format
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
function reportMissingRequiredFields(environment, missingRequiredFields) {
|
|
14
|
-
switch (missingRequiredFields.action) {
|
|
15
|
-
case 'THROW':
|
|
16
|
-
{
|
|
17
|
-
var _missingRequiredField = missingRequiredFields.field,
|
|
18
|
-
path = _missingRequiredField.path,
|
|
19
|
-
owner = _missingRequiredField.owner; // This gives the consumer the chance to throw their own error if they so wish.
|
|
20
|
-
|
|
21
|
-
environment.requiredFieldLogger({
|
|
22
|
-
kind: 'missing_field.throw',
|
|
23
|
-
owner: owner,
|
|
24
|
-
fieldPath: path
|
|
25
|
-
});
|
|
26
|
-
throw new Error("Relay: Missing @required value at path '".concat(path, "' in '").concat(owner, "'."));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
case 'LOG':
|
|
30
|
-
missingRequiredFields.fields.forEach(function (_ref) {
|
|
31
|
-
var path = _ref.path,
|
|
32
|
-
owner = _ref.owner;
|
|
33
|
-
environment.requiredFieldLogger({
|
|
34
|
-
kind: 'missing_field.log',
|
|
35
|
-
owner: owner,
|
|
36
|
-
fieldPath: path
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
break;
|
|
40
|
-
|
|
41
|
-
default:
|
|
42
|
-
{
|
|
43
|
-
missingRequiredFields.action;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
module.exports = reportMissingRequiredFields;
|
|
@@ -1,51 +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
|
|
8
|
-
* @emails oncall+relay
|
|
9
|
-
* @format
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
import type {
|
|
15
|
-
IEnvironment,
|
|
16
|
-
MissingRequiredFields,
|
|
17
|
-
} from '../store/RelayStoreTypes';
|
|
18
|
-
|
|
19
|
-
function reportMissingRequiredFields(
|
|
20
|
-
environment: IEnvironment,
|
|
21
|
-
missingRequiredFields: MissingRequiredFields,
|
|
22
|
-
) {
|
|
23
|
-
switch (missingRequiredFields.action) {
|
|
24
|
-
case 'THROW': {
|
|
25
|
-
const {path, owner} = missingRequiredFields.field;
|
|
26
|
-
// This gives the consumer the chance to throw their own error if they so wish.
|
|
27
|
-
environment.requiredFieldLogger({
|
|
28
|
-
kind: 'missing_field.throw',
|
|
29
|
-
owner,
|
|
30
|
-
fieldPath: path,
|
|
31
|
-
});
|
|
32
|
-
throw new Error(
|
|
33
|
-
`Relay: Missing @required value at path '${path}' in '${owner}'.`,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
case 'LOG':
|
|
37
|
-
missingRequiredFields.fields.forEach(({path, owner}) => {
|
|
38
|
-
environment.requiredFieldLogger({
|
|
39
|
-
kind: 'missing_field.log',
|
|
40
|
-
owner,
|
|
41
|
-
fieldPath: path,
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
break;
|
|
45
|
-
default: {
|
|
46
|
-
(missingRequiredFields.action: empty);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = reportMissingRequiredFields;
|