relay-runtime 13.0.0-rc.1 → 13.0.2
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 +64 -0
- package/handlers/RelayDefaultHandlerProvider.js.flow +1 -1
- package/handlers/connection/ConnectionHandler.js.flow +1 -1
- package/handlers/connection/ConnectionInterface.js.flow +1 -1
- package/handlers/connection/MutationHandlers.js.flow +1 -1
- package/index.js +2 -2
- package/index.js.flow +5 -1
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +1 -1
- package/lib/handlers/connection/ConnectionInterface.js +1 -1
- package/lib/handlers/connection/MutationHandlers.js +1 -1
- package/lib/index.js +8 -2
- package/lib/multi-actor-environment/ActorIdentifier.js +1 -1
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +1 -1
- package/lib/multi-actor-environment/ActorUtils.js +1 -1
- package/lib/multi-actor-environment/MultiActorEnvironment.js +1 -1
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +1 -1
- package/lib/multi-actor-environment/index.js +1 -1
- package/lib/mutations/RelayDeclarativeMutationConfig.js +1 -1
- package/lib/mutations/RelayRecordProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceMutator.js +1 -1
- package/lib/mutations/RelayRecordSourceProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -1
- package/lib/mutations/applyOptimisticMutation.js +1 -1
- package/lib/mutations/commitLocalUpdate.js +1 -1
- package/lib/mutations/commitMutation.js +1 -1
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +27 -18
- package/lib/mutations/validateMutation.js +1 -1
- package/lib/network/ConvertToExecuteFunction.js +1 -1
- package/lib/network/RelayNetwork.js +8 -4
- package/lib/network/RelayNetworkTypes.js +1 -1
- package/lib/network/RelayObservable.js +1 -1
- package/lib/network/RelayQueryResponseCache.js +1 -1
- package/lib/network/wrapNetworkWithLogObserver.js +1 -1
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/PreloadableQueryRegistry.js +1 -1
- package/lib/query/fetchQuery.js +4 -1
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/query/fetchQuery_DEPRECATED.js +1 -1
- package/lib/store/ClientID.js +1 -1
- package/lib/store/DataChecker.js +1 -1
- package/lib/store/OperationExecutor.js +1 -1
- package/lib/store/RelayConcreteVariables.js +13 -4
- package/lib/store/RelayExperimentalGraphResponseHandler.js +3 -3
- package/lib/store/RelayExperimentalGraphResponseTransform.js +54 -22
- package/lib/store/RelayModernEnvironment.js +1 -1
- package/lib/store/RelayModernFragmentSpecResolver.js +1 -1
- package/lib/store/RelayModernOperationDescriptor.js +2 -2
- package/lib/store/RelayModernRecord.js +1 -1
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +1 -1
- package/lib/store/RelayOperationTracker.js +1 -1
- package/lib/store/RelayOptimisticRecordSource.js +1 -1
- package/lib/store/RelayPublishQueue.js +5 -3
- package/lib/store/RelayReader.js +56 -16
- package/lib/store/RelayRecordSource.js +1 -1
- package/lib/store/RelayRecordState.js +1 -1
- package/lib/store/RelayReferenceMarker.js +1 -1
- package/lib/store/RelayResponseNormalizer.js +1 -1
- package/lib/store/RelayStoreReactFlightUtils.js +1 -1
- package/lib/store/RelayStoreSubscriptions.js +1 -1
- package/lib/store/RelayStoreTypes.js +1 -1
- package/lib/store/RelayStoreUtils.js +2 -1
- package/lib/store/ResolverCache.js +11 -3
- package/lib/store/ResolverFragments.js +3 -3
- package/lib/store/StoreInspector.js +1 -1
- package/lib/store/TypeID.js +1 -1
- package/lib/store/ViewerPattern.js +1 -1
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createFragmentSpecResolver.js +1 -1
- package/lib/store/createRelayContext.js +1 -1
- package/lib/store/defaultGetDataID.js +1 -1
- package/lib/store/defaultRequiredFieldLogger.js +1 -1
- package/lib/store/hasOverlappingIDs.js +1 -1
- package/lib/store/isRelayModernEnvironment.js +1 -1
- package/lib/store/normalizeRelayPayload.js +1 -1
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +1 -3
- package/lib/util/JSResourceTypes.flow.js +1 -1
- package/lib/util/NormalizationNode.js +1 -1
- package/lib/util/ReaderNode.js +1 -1
- package/lib/util/RelayConcreteNode.js +1 -1
- package/lib/util/RelayDefaultHandleKey.js +1 -1
- package/lib/util/RelayError.js +1 -1
- package/lib/util/RelayFeatureFlags.js +1 -2
- package/lib/util/RelayProfiler.js +1 -1
- package/lib/util/RelayReplaySubject.js +1 -1
- package/lib/util/RelayRuntimeTypes.js +1 -1
- package/lib/util/StringInterner.js +1 -1
- package/lib/util/createPayloadFor3DField.js +1 -1
- package/lib/util/deepFreeze.js +1 -1
- package/lib/util/generateID.js +1 -1
- package/lib/util/getFragmentIdentifier.js +1 -1
- package/lib/util/getOperation.js +1 -1
- package/lib/util/getPaginationMetadata.js +1 -1
- package/lib/util/getPaginationVariables.js +1 -1
- package/lib/util/getPendingOperationsForFragment.js +1 -1
- package/lib/util/getRefetchMetadata.js +1 -1
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- package/lib/util/getValueAtPath.js +1 -1
- package/lib/util/isEmptyObject.js +1 -1
- package/lib/util/isPromise.js +1 -1
- package/lib/util/isScalarAndEqual.js +1 -1
- package/lib/util/recycleNodesInto.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +1 -1
- package/lib/util/reportMissingRequiredFields.js +1 -1
- package/lib/util/resolveImmediate.js +1 -1
- package/lib/util/stableCopy.js +1 -1
- package/lib/util/withDuration.js +1 -1
- package/lib/util/withProvidedVariables.js +49 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +1 -1
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +1 -1
- package/multi-actor-environment/ActorUtils.js.flow +1 -1
- package/multi-actor-environment/MultiActorEnvironment.js.flow +1 -1
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +1 -1
- package/multi-actor-environment/index.js.flow +1 -1
- package/mutations/RelayDeclarativeMutationConfig.js.flow +1 -2
- package/mutations/RelayRecordProxy.js.flow +1 -1
- package/mutations/RelayRecordSourceMutator.js.flow +1 -1
- package/mutations/RelayRecordSourceProxy.js.flow +1 -1
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +1 -1
- package/mutations/applyOptimisticMutation.js.flow +1 -1
- package/mutations/commitLocalUpdate.js.flow +1 -1
- package/mutations/commitMutation.js.flow +9 -20
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +57 -50
- package/mutations/validateMutation.js.flow +1 -1
- package/network/ConvertToExecuteFunction.js.flow +1 -1
- package/network/RelayNetwork.js.flow +11 -4
- package/network/RelayNetworkTypes.js.flow +2 -2
- package/network/RelayObservable.js.flow +1 -1
- package/network/RelayQueryResponseCache.js.flow +1 -1
- package/network/wrapNetworkWithLogObserver.js.flow +2 -3
- package/package.json +2 -2
- package/query/GraphQLTag.js.flow +2 -2
- package/query/PreloadableQueryRegistry.js.flow +3 -2
- package/query/fetchQuery.js.flow +16 -12
- package/query/fetchQueryInternal.js.flow +1 -1
- package/query/fetchQuery_DEPRECATED.js.flow +1 -1
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +3 -3
- package/store/ClientID.js.flow +1 -1
- package/store/DataChecker.js.flow +1 -1
- package/store/OperationExecutor.js.flow +1 -1
- package/store/RelayConcreteVariables.js.flow +13 -3
- package/store/RelayExperimentalGraphResponseHandler.js.flow +3 -6
- package/store/RelayExperimentalGraphResponseTransform.js.flow +51 -22
- package/store/RelayModernEnvironment.js.flow +1 -1
- package/store/RelayModernFragmentSpecResolver.js.flow +1 -1
- package/store/RelayModernOperationDescriptor.js.flow +6 -2
- package/store/RelayModernRecord.js.flow +1 -1
- package/store/RelayModernSelector.js.flow +1 -1
- package/store/RelayModernStore.js.flow +1 -2
- package/store/RelayOperationTracker.js.flow +1 -1
- package/store/RelayOptimisticRecordSource.js.flow +1 -1
- package/store/RelayPublishQueue.js.flow +9 -2
- package/store/RelayReader.js.flow +79 -39
- package/store/RelayRecordSource.js.flow +1 -1
- package/store/RelayRecordState.js.flow +1 -1
- package/store/RelayReferenceMarker.js.flow +1 -1
- package/store/RelayResponseNormalizer.js.flow +1 -1
- package/store/RelayStoreReactFlightUtils.js.flow +1 -1
- package/store/RelayStoreSubscriptions.js.flow +1 -1
- package/store/RelayStoreTypes.js.flow +4 -3
- package/store/RelayStoreUtils.js.flow +2 -1
- package/store/ResolverCache.js.flow +19 -6
- package/store/ResolverFragments.js.flow +3 -3
- package/store/StoreInspector.js.flow +1 -1
- package/store/TypeID.js.flow +1 -1
- package/store/ViewerPattern.js.flow +1 -1
- package/store/cloneRelayHandleSourceField.js.flow +1 -1
- package/store/cloneRelayScalarHandleSourceField.js.flow +1 -1
- package/store/createFragmentSpecResolver.js.flow +1 -1
- package/store/createRelayContext.js.flow +1 -1
- package/store/defaultGetDataID.js.flow +1 -1
- package/store/defaultRequiredFieldLogger.js.flow +1 -1
- package/store/hasOverlappingIDs.js.flow +1 -1
- package/store/isRelayModernEnvironment.js.flow +1 -1
- package/store/normalizeRelayPayload.js.flow +1 -1
- package/store/readInlineData.js.flow +1 -1
- package/subscription/requestSubscription.js.flow +8 -14
- package/util/JSResourceTypes.flow.js.flow +1 -1
- package/util/NormalizationNode.js.flow +1 -1
- package/util/ReaderNode.js.flow +1 -1
- package/util/RelayConcreteNode.js.flow +5 -3
- package/util/RelayDefaultHandleKey.js.flow +1 -1
- package/util/RelayError.js.flow +1 -1
- package/util/RelayFeatureFlags.js.flow +1 -3
- package/util/RelayProfiler.js.flow +1 -1
- package/util/RelayReplaySubject.js.flow +1 -1
- package/util/RelayRuntimeTypes.js.flow +1 -1
- package/util/StringInterner.js.flow +1 -1
- package/util/createPayloadFor3DField.js.flow +1 -1
- package/util/deepFreeze.js.flow +1 -1
- package/util/generateID.js.flow +1 -1
- package/util/getFragmentIdentifier.js.flow +1 -1
- package/util/getOperation.js.flow +1 -1
- package/util/getPaginationMetadata.js.flow +3 -6
- package/util/getPaginationVariables.js.flow +1 -1
- package/util/getPendingOperationsForFragment.js.flow +1 -1
- package/util/getRefetchMetadata.js.flow +3 -6
- package/util/getRelayHandleKey.js.flow +1 -1
- package/util/getRequestIdentifier.js.flow +1 -1
- package/util/getValueAtPath.js.flow +1 -1
- package/util/isEmptyObject.js.flow +1 -1
- package/util/isPromise.js.flow +1 -1
- package/util/isScalarAndEqual.js.flow +1 -1
- package/util/recycleNodesInto.js.flow +1 -1
- package/util/registerEnvironmentWithDevTools.js.flow +1 -1
- package/util/reportMissingRequiredFields.js.flow +1 -1
- package/util/resolveImmediate.js.flow +1 -1
- package/util/stableCopy.js.flow +1 -1
- package/util/withDuration.js.flow +1 -1
- package/util/withProvidedVariables.js.flow +64 -0
package/store/ClientID.js.flow
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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.
|
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
NormalizationOperation,
|
|
19
19
|
} from '../util/NormalizationNode';
|
|
20
20
|
import type {ReaderFragment} from '../util/ReaderNode';
|
|
21
|
+
import type {ProvidedVariablesType} from '../util/RelayConcreteNode';
|
|
21
22
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
22
23
|
|
|
23
24
|
const {getArgumentValues} = require('./RelayStoreUtils');
|
|
@@ -76,12 +77,15 @@ function getFragmentVariables(
|
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
79
|
* Determines the variables that are in scope for a given operation given values
|
|
79
|
-
* for some/all of its arguments.
|
|
80
|
-
*
|
|
80
|
+
* for some/all of its arguments.
|
|
81
|
+
* - extraneous input variables are filtered from the output
|
|
82
|
+
* - missing variables are set to default values (if given in the
|
|
81
83
|
* operation's definition).
|
|
84
|
+
* - variables with provider modules are added
|
|
82
85
|
*/
|
|
83
86
|
function getOperationVariables(
|
|
84
87
|
operation: NormalizationOperation,
|
|
88
|
+
providedVariables: ?ProvidedVariablesType,
|
|
85
89
|
variables: Variables,
|
|
86
90
|
): Variables {
|
|
87
91
|
const operationVariables = {};
|
|
@@ -92,6 +96,12 @@ function getOperationVariables(
|
|
|
92
96
|
}
|
|
93
97
|
operationVariables[def.name] = value;
|
|
94
98
|
});
|
|
99
|
+
|
|
100
|
+
if (providedVariables != null) {
|
|
101
|
+
Object.keys(providedVariables).forEach((varName: string) => {
|
|
102
|
+
operationVariables[varName] = providedVariables[varName].get();
|
|
103
|
+
});
|
|
104
|
+
}
|
|
95
105
|
return operationVariables;
|
|
96
106
|
}
|
|
97
107
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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.
|
|
@@ -14,13 +14,10 @@ import type {
|
|
|
14
14
|
GraphModeResponse,
|
|
15
15
|
RecordChunk,
|
|
16
16
|
} from './RelayExperimentalGraphResponseTransform';
|
|
17
|
-
import type {
|
|
18
|
-
MutableRecordSource,
|
|
19
|
-
Record,
|
|
20
|
-
} from 'relay-runtime/store/RelayStoreTypes';
|
|
17
|
+
import type {MutableRecordSource, Record} from './RelayStoreTypes';
|
|
21
18
|
|
|
19
|
+
const RelayModernRecord = require('./RelayModernRecord');
|
|
22
20
|
const invariant = require('invariant');
|
|
23
|
-
const RelayModernRecord = require('relay-runtime/store/RelayModernRecord');
|
|
24
21
|
|
|
25
22
|
/**
|
|
26
23
|
* Given a stream of GraphMode chunks, populate a MutableRecordSource.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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.
|
|
@@ -10,30 +10,20 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type {ActorIdentifier} from '../multi-actor-environment/ActorIdentifier';
|
|
13
|
-
import type {
|
|
14
|
-
import type {IncrementalDataPlaceholder} from './RelayStoreTypes';
|
|
13
|
+
import type {PayloadData} from '../network/RelayNetworkTypes';
|
|
15
14
|
import type {
|
|
16
|
-
DataID,
|
|
17
15
|
NormalizationField,
|
|
18
|
-
NormalizationSelector,
|
|
19
|
-
PayloadData,
|
|
20
|
-
} from 'relay-runtime';
|
|
21
|
-
import type {GetDataID} from 'relay-runtime/store/RelayResponseNormalizer';
|
|
22
|
-
import type {
|
|
23
16
|
NormalizationLinkedField,
|
|
24
17
|
NormalizationNode,
|
|
25
|
-
} from '
|
|
26
|
-
import type {Variables} from '
|
|
18
|
+
} from '../util/NormalizationNode';
|
|
19
|
+
import type {DataID, Variables} from '../util/RelayRuntimeTypes';
|
|
20
|
+
import type {NormalizationOptions} from './RelayResponseNormalizer';
|
|
21
|
+
import type {GetDataID} from './RelayResponseNormalizer';
|
|
22
|
+
import type {
|
|
23
|
+
IncrementalDataPlaceholder,
|
|
24
|
+
NormalizationSelector,
|
|
25
|
+
} from './RelayStoreTypes';
|
|
27
26
|
|
|
28
|
-
const {getLocalVariables} = require('./RelayConcreteVariables');
|
|
29
|
-
const {createNormalizationSelector} = require('./RelayModernSelector');
|
|
30
|
-
const invariant = require('invariant');
|
|
31
|
-
const {generateClientID} = require('relay-runtime');
|
|
32
|
-
const {
|
|
33
|
-
ROOT_TYPE,
|
|
34
|
-
TYPENAME_KEY,
|
|
35
|
-
getStorageKey,
|
|
36
|
-
} = require('relay-runtime/store/RelayStoreUtils');
|
|
37
27
|
const {
|
|
38
28
|
CLIENT_EXTENSION,
|
|
39
29
|
CONDITION,
|
|
@@ -41,8 +31,15 @@ const {
|
|
|
41
31
|
FRAGMENT_SPREAD,
|
|
42
32
|
INLINE_FRAGMENT,
|
|
43
33
|
LINKED_FIELD,
|
|
34
|
+
LINKED_HANDLE,
|
|
44
35
|
SCALAR_FIELD,
|
|
45
|
-
|
|
36
|
+
SCALAR_HANDLE,
|
|
37
|
+
} = require('../util/RelayConcreteNode');
|
|
38
|
+
const {getLocalVariables} = require('./RelayConcreteVariables');
|
|
39
|
+
const {createNormalizationSelector} = require('./RelayModernSelector');
|
|
40
|
+
const {ROOT_TYPE, TYPENAME_KEY, getStorageKey} = require('./RelayStoreUtils');
|
|
41
|
+
const invariant = require('invariant');
|
|
42
|
+
const {generateClientID} = require('relay-runtime');
|
|
46
43
|
|
|
47
44
|
/**
|
|
48
45
|
* This module is an experiment to explore a proposal normalized response format for GraphQL.
|
|
@@ -96,6 +93,10 @@ export type GraphModeChunk = DataChunk | CompleteChunk;
|
|
|
96
93
|
|
|
97
94
|
export type GraphModeResponse = Iterable<GraphModeChunk>;
|
|
98
95
|
|
|
96
|
+
export type TransformMetadata = {
|
|
97
|
+
duplicateFieldsAvoided: number,
|
|
98
|
+
};
|
|
99
|
+
|
|
99
100
|
/**
|
|
100
101
|
* Converts a JSON response (and Normalization AST) into a stream of GraphMode chunks
|
|
101
102
|
*
|
|
@@ -133,7 +134,20 @@ export function normalizeResponse(
|
|
|
133
134
|
return normalizer.normalizeResponse(node, dataID, response);
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
|
|
137
|
+
export function normalizeResponseWithMetadata(
|
|
138
|
+
response: PayloadData,
|
|
139
|
+
selector: NormalizationSelector,
|
|
140
|
+
options: NormalizationOptions,
|
|
141
|
+
): [Array<GraphModeChunk>, TransformMetadata] {
|
|
142
|
+
const {node, variables, dataID} = selector;
|
|
143
|
+
const normalizer = new GraphModeNormalizer(variables, options);
|
|
144
|
+
const chunks = Array.from(
|
|
145
|
+
normalizer.normalizeResponse(node, dataID, response),
|
|
146
|
+
);
|
|
147
|
+
return [chunks, {duplicateFieldsAvoided: normalizer.duplicateFieldsAvoided}];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export class GraphModeNormalizer {
|
|
137
151
|
_cacheKeyToStreamID: Map<string, number>;
|
|
138
152
|
_sentFields: Map<string, Set<string>>;
|
|
139
153
|
_getDataId: GetDataID;
|
|
@@ -143,6 +157,7 @@ class GraphModeNormalizer {
|
|
|
143
157
|
_path: Array<string>;
|
|
144
158
|
_incrementalPlaceholders: Array<IncrementalDataPlaceholder>;
|
|
145
159
|
_actorIdentifier: ?ActorIdentifier;
|
|
160
|
+
duplicateFieldsAvoided: number;
|
|
146
161
|
constructor(variables: Variables, options: NormalizationOptions) {
|
|
147
162
|
this._actorIdentifier = options.actorIdentifier;
|
|
148
163
|
this._path = options.path ? [...options.path] : [];
|
|
@@ -151,6 +166,7 @@ class GraphModeNormalizer {
|
|
|
151
166
|
this._sentFields = new Map();
|
|
152
167
|
this._nextStreamID = 0;
|
|
153
168
|
this._variables = variables;
|
|
169
|
+
this.duplicateFieldsAvoided = 0;
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
_getStreamID() {
|
|
@@ -271,6 +287,7 @@ class GraphModeNormalizer {
|
|
|
271
287
|
// TODO: We could also opt to confirm that this matches the previously
|
|
272
288
|
// seen value.
|
|
273
289
|
if (sentFields.has(storageKey)) {
|
|
290
|
+
this.duplicateFieldsAvoided++;
|
|
274
291
|
break;
|
|
275
292
|
}
|
|
276
293
|
|
|
@@ -286,6 +303,7 @@ class GraphModeNormalizer {
|
|
|
286
303
|
// TODO: We could also opt to confirm that this matches the previously
|
|
287
304
|
// seen value.
|
|
288
305
|
if (sentFields.has(storageKey)) {
|
|
306
|
+
this.duplicateFieldsAvoided++;
|
|
289
307
|
break;
|
|
290
308
|
}
|
|
291
309
|
const fieldData = ((data[responseKey]: any): ChunkField);
|
|
@@ -379,6 +397,17 @@ class GraphModeNormalizer {
|
|
|
379
397
|
// Since we are only expecting to handle server responses, we can skip
|
|
380
398
|
// over client extensions.
|
|
381
399
|
break;
|
|
400
|
+
case SCALAR_HANDLE:
|
|
401
|
+
case LINKED_HANDLE:
|
|
402
|
+
// Handles allow us to record information that will be needed to
|
|
403
|
+
// perform additional process when we insert data into the store. For
|
|
404
|
+
// example, connection edges need to be prepended/appended to the
|
|
405
|
+
// pre-existing values.
|
|
406
|
+
//
|
|
407
|
+
// GraphMode will eventually need some replacement for this, but it is
|
|
408
|
+
// not nessesary in order to measure things like response size, so we
|
|
409
|
+
// can ignore these for now.
|
|
410
|
+
break;
|
|
382
411
|
default:
|
|
383
412
|
throw new Error(`Unexpected selection type: ${selection.kind}`);
|
|
384
413
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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.
|
|
@@ -44,7 +44,11 @@ function createOperationDescriptor<TQuery: OperationType>(
|
|
|
44
44
|
dataID?: DataID = ROOT_ID,
|
|
45
45
|
): OperationDescriptor {
|
|
46
46
|
const operation = request.operation;
|
|
47
|
-
const operationVariables = getOperationVariables(
|
|
47
|
+
const operationVariables = getOperationVariables(
|
|
48
|
+
operation,
|
|
49
|
+
request.params.providedVariables,
|
|
50
|
+
variables,
|
|
51
|
+
);
|
|
48
52
|
const requestDescriptor = createRequestDescriptor(
|
|
49
53
|
request,
|
|
50
54
|
operationVariables,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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.
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
import type {ActorIdentifier} from '../multi-actor-environment/ActorIdentifier';
|
|
16
15
|
import type {DataID, Disposable} from '../util/RelayRuntimeTypes';
|
|
17
16
|
import type {Availability} from './DataChecker';
|
|
18
17
|
import type {GetDataID} from './RelayResponseNormalizer';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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.
|
|
@@ -57,8 +57,15 @@ type PendingUpdater = {|
|
|
|
57
57
|
+updater: StoreUpdater,
|
|
58
58
|
|};
|
|
59
59
|
|
|
60
|
+
const _global: typeof global | $FlowFixMe =
|
|
61
|
+
typeof global !== 'undefined'
|
|
62
|
+
? global
|
|
63
|
+
: typeof window !== 'undefined'
|
|
64
|
+
? window
|
|
65
|
+
: undefined;
|
|
66
|
+
|
|
60
67
|
const applyWithGuard =
|
|
61
|
-
|
|
68
|
+
_global?.ErrorUtils?.applyWithGuard ??
|
|
62
69
|
((callback, context, args, onError, name) => callback.apply(context, args));
|
|
63
70
|
|
|
64
71
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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.
|
|
@@ -109,6 +109,7 @@ class RelayReader {
|
|
|
109
109
|
_selector: SingularReaderSelector;
|
|
110
110
|
_variables: Variables;
|
|
111
111
|
_resolverCache: ResolverCache;
|
|
112
|
+
_fragmentName: string;
|
|
112
113
|
|
|
113
114
|
constructor(
|
|
114
115
|
recordSource: RecordSource,
|
|
@@ -130,6 +131,7 @@ class RelayReader {
|
|
|
130
131
|
this._selector = selector;
|
|
131
132
|
this._variables = selector.variables;
|
|
132
133
|
this._resolverCache = resolverCache;
|
|
134
|
+
this._fragmentName = selector.node.name;
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
read(): Snapshot {
|
|
@@ -267,7 +269,7 @@ class RelayReader {
|
|
|
267
269
|
// encounter is likely to be the root cause of the error.
|
|
268
270
|
return;
|
|
269
271
|
}
|
|
270
|
-
const owner = this.
|
|
272
|
+
const owner = this._fragmentName;
|
|
271
273
|
|
|
272
274
|
switch (action) {
|
|
273
275
|
case 'THROW':
|
|
@@ -275,9 +277,19 @@ class RelayReader {
|
|
|
275
277
|
return;
|
|
276
278
|
case 'LOG':
|
|
277
279
|
if (this._missingRequiredFields == null) {
|
|
278
|
-
this._missingRequiredFields = {
|
|
280
|
+
this._missingRequiredFields = {
|
|
281
|
+
action,
|
|
282
|
+
fields: [{path: fieldPath, owner}],
|
|
283
|
+
};
|
|
284
|
+
} else {
|
|
285
|
+
this._missingRequiredFields = {
|
|
286
|
+
action,
|
|
287
|
+
fields: [
|
|
288
|
+
...this._missingRequiredFields.fields,
|
|
289
|
+
{path: fieldPath, owner},
|
|
290
|
+
],
|
|
291
|
+
};
|
|
279
292
|
}
|
|
280
|
-
this._missingRequiredFields.fields.push({path: fieldPath, owner});
|
|
281
293
|
return;
|
|
282
294
|
default:
|
|
283
295
|
(action: empty);
|
|
@@ -293,13 +305,6 @@ class RelayReader {
|
|
|
293
305
|
const selection = selections[i];
|
|
294
306
|
switch (selection.kind) {
|
|
295
307
|
case REQUIRED_FIELD:
|
|
296
|
-
invariant(
|
|
297
|
-
RelayFeatureFlags.ENABLE_REQUIRED_DIRECTIVES,
|
|
298
|
-
'RelayReader(): Encountered a `@required` directive at path "%s" in `%s` without the `ENABLE_REQUIRED_DIRECTIVES` feature flag enabled.',
|
|
299
|
-
selection.path,
|
|
300
|
-
this._selector.node.name,
|
|
301
|
-
);
|
|
302
|
-
|
|
303
308
|
const fieldValue = this._readRequiredField(selection, record, data);
|
|
304
309
|
if (fieldValue == null) {
|
|
305
310
|
const {action} = selection;
|
|
@@ -490,8 +495,7 @@ class RelayReader {
|
|
|
490
495
|
if (!RelayFeatureFlags.ENABLE_RELAY_RESOLVERS) {
|
|
491
496
|
throw new Error('Relay Resolver fields are not yet supported.');
|
|
492
497
|
}
|
|
493
|
-
this._readResolverField(selection.field, record, data);
|
|
494
|
-
break;
|
|
498
|
+
return this._readResolverField(selection.field, record, data);
|
|
495
499
|
default:
|
|
496
500
|
(selection.field.kind: empty);
|
|
497
501
|
invariant(
|
|
@@ -506,7 +510,7 @@ class RelayReader {
|
|
|
506
510
|
field: ReaderRelayResolver,
|
|
507
511
|
record: Record,
|
|
508
512
|
data: SelectorData,
|
|
509
|
-
):
|
|
513
|
+
): mixed {
|
|
510
514
|
const {resolverModule, fragment} = field;
|
|
511
515
|
const storageKey = getStorageKey(field, this._variables);
|
|
512
516
|
const resolverID = ClientID.generateClientID(
|
|
@@ -519,6 +523,8 @@ class RelayReader {
|
|
|
519
523
|
// inputs have changed since a previous evaluation:
|
|
520
524
|
let fragmentValue;
|
|
521
525
|
let fragmentReaderSelector;
|
|
526
|
+
let fragmentMissingRequiredFields: ?MissingRequiredFields;
|
|
527
|
+
let previousMissingRequriedFields: ?MissingRequiredFields;
|
|
522
528
|
const fragmentSeenRecordIDs = new Set();
|
|
523
529
|
|
|
524
530
|
const getDataForResolverFragment = singularReaderSelector => {
|
|
@@ -533,11 +539,14 @@ class RelayReader {
|
|
|
533
539
|
try {
|
|
534
540
|
this._seenRecords = fragmentSeenRecordIDs;
|
|
535
541
|
const resolverFragmentData = {};
|
|
542
|
+
previousMissingRequriedFields = this._missingRequiredFields;
|
|
543
|
+
this._missingRequiredFields = null;
|
|
536
544
|
this._createInlineDataOrResolverFragmentPointer(
|
|
537
545
|
singularReaderSelector.node,
|
|
538
546
|
record,
|
|
539
547
|
resolverFragmentData,
|
|
540
548
|
);
|
|
549
|
+
fragmentMissingRequiredFields = this._missingRequiredFields;
|
|
541
550
|
fragmentValue = resolverFragmentData[FRAGMENTS_KEY]?.[fragment.name];
|
|
542
551
|
invariant(
|
|
543
552
|
typeof fragmentValue === 'object' && fragmentValue !== null,
|
|
@@ -546,42 +555,50 @@ class RelayReader {
|
|
|
546
555
|
return fragmentValue;
|
|
547
556
|
} finally {
|
|
548
557
|
this._seenRecords = existingSeenRecords;
|
|
558
|
+
this._missingRequiredFields = previousMissingRequriedFields;
|
|
549
559
|
}
|
|
550
560
|
};
|
|
551
561
|
const resolverContext = {getDataForResolverFragment};
|
|
552
562
|
|
|
553
|
-
const [result, seenRecord] =
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
return withResolverContext(resolverContext, () => {
|
|
566
|
-
// $FlowFixMe[prop-missing] - resolver module's type signature is a lie
|
|
567
|
-
const resolverResult = resolverModule(key);
|
|
568
|
-
return {
|
|
569
|
-
resolverResult,
|
|
570
|
-
fragmentValue,
|
|
571
|
-
resolverID,
|
|
572
|
-
seenRecordIDs: fragmentSeenRecordIDs,
|
|
573
|
-
readerSelector: fragmentReaderSelector,
|
|
563
|
+
const [result, seenRecord, missingRequiredFields] =
|
|
564
|
+
this._resolverCache.readFromCacheOrEvaluate(
|
|
565
|
+
record,
|
|
566
|
+
field,
|
|
567
|
+
this._variables,
|
|
568
|
+
() => {
|
|
569
|
+
const key = {
|
|
570
|
+
__id: RelayModernRecord.getDataID(record),
|
|
571
|
+
__fragmentOwner: this._owner,
|
|
572
|
+
__fragments: {
|
|
573
|
+
[fragment.name]: {}, // Arguments to this fragment; not yet supported.
|
|
574
|
+
},
|
|
574
575
|
};
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
576
|
+
return withResolverContext(resolverContext, () => {
|
|
577
|
+
// $FlowFixMe[prop-missing] - resolver module's type signature is a lie
|
|
578
|
+
const resolverResult = resolverModule(key);
|
|
579
|
+
return {
|
|
580
|
+
resolverResult,
|
|
581
|
+
fragmentValue,
|
|
582
|
+
resolverID,
|
|
583
|
+
seenRecordIDs: fragmentSeenRecordIDs,
|
|
584
|
+
readerSelector: fragmentReaderSelector,
|
|
585
|
+
missingRequiredFields: fragmentMissingRequiredFields,
|
|
586
|
+
};
|
|
587
|
+
});
|
|
588
|
+
},
|
|
589
|
+
getDataForResolverFragment,
|
|
590
|
+
);
|
|
591
|
+
|
|
592
|
+
if (missingRequiredFields != null) {
|
|
593
|
+
this._addMissingRequiredFields(missingRequiredFields);
|
|
594
|
+
}
|
|
579
595
|
if (seenRecord != null) {
|
|
580
596
|
this._seenRecords.add(seenRecord);
|
|
581
597
|
}
|
|
582
598
|
|
|
583
599
|
const applicationName = field.alias ?? field.name;
|
|
584
600
|
data[applicationName] = result;
|
|
601
|
+
return result;
|
|
585
602
|
}
|
|
586
603
|
|
|
587
604
|
_readClientEdge(
|
|
@@ -903,14 +920,37 @@ class RelayReader {
|
|
|
903
920
|
data[ID_KEY] = RelayModernRecord.getDataID(record);
|
|
904
921
|
}
|
|
905
922
|
const inlineData = {};
|
|
923
|
+
const parentFragmentName = this._fragmentName;
|
|
924
|
+
this._fragmentName = fragmentSpreadOrFragment.name;
|
|
906
925
|
this._traverseSelections(
|
|
907
926
|
fragmentSpreadOrFragment.selections,
|
|
908
927
|
record,
|
|
909
928
|
inlineData,
|
|
910
929
|
);
|
|
930
|
+
this._fragmentName = parentFragmentName;
|
|
911
931
|
// $FlowFixMe[cannot-write] - writing into read-only field
|
|
912
932
|
fragmentPointers[fragmentSpreadOrFragment.name] = inlineData;
|
|
913
933
|
}
|
|
934
|
+
|
|
935
|
+
_addMissingRequiredFields(additional: MissingRequiredFields) {
|
|
936
|
+
if (this._missingRequiredFields == null) {
|
|
937
|
+
this._missingRequiredFields = additional;
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
if (this._missingRequiredFields.action === 'THROW') {
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
if (additional.action === 'THROW') {
|
|
945
|
+
this._missingRequiredFields = additional;
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
this._missingRequiredFields = {
|
|
950
|
+
action: 'LOG',
|
|
951
|
+
fields: [...this._missingRequiredFields.fields, ...additional.fields],
|
|
952
|
+
};
|
|
953
|
+
}
|
|
914
954
|
}
|
|
915
955
|
|
|
916
956
|
module.exports = {read};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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.
|
|
@@ -117,9 +117,10 @@ type MissingRequiredField = {|
|
|
|
117
117
|
owner: string,
|
|
118
118
|
|};
|
|
119
119
|
|
|
120
|
-
export type MissingRequiredFields =
|
|
120
|
+
export type MissingRequiredFields = $ReadOnly<
|
|
121
121
|
| {|action: 'THROW', field: MissingRequiredField|}
|
|
122
|
-
| {|action: 'LOG', fields: Array<MissingRequiredField>|}
|
|
122
|
+
| {|action: 'LOG', fields: Array<MissingRequiredField>|},
|
|
123
|
+
>;
|
|
123
124
|
|
|
124
125
|
export type ClientEdgeTraversalInfo = {|
|
|
125
126
|
+readerClientEdge: ReaderClientEdge,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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.
|
|
@@ -219,6 +219,7 @@ const RelayStoreUtils = {
|
|
|
219
219
|
RELAY_RESOLVER_INVALIDATION_KEY: '__resolverValueMayBeInvalid',
|
|
220
220
|
RELAY_RESOLVER_INPUTS_KEY: '__resolverInputValues',
|
|
221
221
|
RELAY_RESOLVER_READER_SELECTOR_KEY: '__resolverReaderSelector',
|
|
222
|
+
RELAY_RESOLVER_MISSING_REQUIRED_FIELDS_KEY: '__resolverMissingRequiredFields',
|
|
222
223
|
|
|
223
224
|
formatStorageKey,
|
|
224
225
|
getArgumentValue,
|