relay-runtime 10.0.0 → 10.1.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/handlers/RelayDefaultHandlerProvider.js.flow +6 -0
- package/handlers/connection/MutationHandlers.js.flow +121 -3
- package/index.js +1 -1
- package/index.js.flow +16 -1
- package/lib/handlers/RelayDefaultHandlerProvider.js +9 -0
- package/lib/handlers/connection/MutationHandlers.js +147 -14
- package/lib/index.js +7 -0
- package/lib/mutations/RelayDeclarativeMutationConfig.js +5 -7
- package/lib/mutations/commitMutation.js +1 -4
- package/lib/mutations/validateMutation.js +28 -12
- package/lib/network/RelayQueryResponseCache.js +3 -7
- package/lib/query/GraphQLTag.js +2 -1
- package/lib/query/fetchQuery.js +2 -3
- package/lib/query/fetchQueryInternal.js +2 -3
- package/lib/store/DataChecker.js +85 -10
- package/lib/store/RelayConcreteVariables.js +2 -6
- package/lib/store/RelayModernEnvironment.js +81 -72
- package/lib/store/RelayModernFragmentSpecResolver.js +14 -7
- package/lib/store/RelayModernOperationDescriptor.js +6 -5
- package/lib/store/RelayModernQueryExecutor.js +46 -33
- package/lib/store/RelayModernRecord.js +3 -7
- package/lib/store/RelayModernStore.js +45 -143
- package/lib/store/RelayOperationTracker.js +7 -9
- package/lib/store/RelayOptimisticRecordSource.js +2 -6
- package/lib/store/RelayPublishQueue.js +1 -1
- package/lib/store/RelayReader.js +200 -49
- package/lib/store/RelayRecordSourceMapImpl.js +3 -5
- package/lib/store/RelayReferenceMarker.js +87 -5
- package/lib/store/RelayResponseNormalizer.js +123 -54
- package/lib/store/RelayStoreReactFlightUtils.js +47 -0
- package/lib/store/RelayStoreSubscriptions.js +162 -0
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +258 -0
- package/lib/store/StoreInspector.js +3 -9
- package/lib/store/createRelayContext.js +5 -0
- package/lib/store/defaultRequiredFieldLogger.js +18 -0
- package/lib/store/normalizeRelayPayload.js +2 -6
- package/lib/subscription/requestSubscription.js +2 -3
- package/lib/util/NormalizationNode.js +1 -5
- package/lib/util/RelayConcreteNode.js +2 -0
- package/lib/util/RelayFeatureFlags.js +6 -2
- package/lib/util/createPayloadFor3DField.js +2 -7
- package/lib/util/getFragmentIdentifier.js +12 -3
- package/lib/util/getOperation.js +33 -0
- package/lib/util/isEmptyObject.js +25 -0
- package/lib/util/recycleNodesInto.js +6 -9
- package/lib/util/reportMissingRequiredFields.js +48 -0
- package/mutations/commitMutation.js.flow +1 -2
- package/mutations/validateMutation.js.flow +34 -5
- package/network/RelayNetworkTypes.js.flow +22 -0
- package/package.json +2 -2
- package/query/GraphQLTag.js.flow +3 -1
- package/query/fetchQuery.js.flow +2 -2
- package/query/fetchQueryInternal.js.flow +0 -5
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/DataChecker.js.flow +68 -2
- package/store/RelayModernEnvironment.js.flow +107 -87
- package/store/RelayModernFragmentSpecResolver.js.flow +13 -1
- package/store/RelayModernOperationDescriptor.js.flow +5 -1
- package/store/RelayModernQueryExecutor.js.flow +47 -23
- package/store/RelayModernStore.js.flow +40 -114
- package/store/RelayPublishQueue.js.flow +1 -1
- package/store/RelayReader.js.flow +184 -27
- package/store/RelayReferenceMarker.js.flow +72 -5
- package/store/RelayResponseNormalizer.js.flow +140 -50
- package/store/RelayStoreReactFlightUtils.js.flow +64 -0
- package/store/RelayStoreSubscriptions.js.flow +168 -0
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +259 -0
- package/store/RelayStoreTypes.js.flow +130 -37
- package/store/StoreInspector.js.flow +1 -3
- package/store/createRelayContext.js.flow +3 -0
- package/store/defaultRequiredFieldLogger.js.flow +23 -0
- package/subscription/requestSubscription.js.flow +5 -2
- package/util/NormalizationNode.js.flow +17 -2
- package/util/ReaderNode.js.flow +20 -1
- package/util/RelayConcreteNode.js.flow +6 -0
- package/util/RelayFeatureFlags.js.flow +10 -1
- package/util/getFragmentIdentifier.js.flow +33 -9
- package/util/getOperation.js.flow +40 -0
- package/util/isEmptyObject.js.flow +25 -0
- package/util/recycleNodesInto.js.flow +13 -8
- package/util/reportMissingRequiredFields.js.flow +51 -0
|
@@ -19,16 +19,19 @@ import type {
|
|
|
19
19
|
import type {ConcreteRequest} from '../util/RelayConcreteNode';
|
|
20
20
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
21
21
|
|
|
22
|
-
type ValidationContext = {
|
|
22
|
+
type ValidationContext = {|
|
|
23
23
|
visitedPaths: Set<string>,
|
|
24
24
|
path: string,
|
|
25
25
|
variables: Variables,
|
|
26
26
|
missingDiff: Object,
|
|
27
27
|
extraDiff: Object,
|
|
28
|
-
|
|
29
|
-
};
|
|
28
|
+
moduleImportPaths: Set<string>,
|
|
29
|
+
|};
|
|
30
|
+
|
|
30
31
|
const warning = require('warning');
|
|
31
32
|
|
|
33
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
34
|
+
|
|
32
35
|
let validateMutation = () => {};
|
|
33
36
|
if (__DEV__) {
|
|
34
37
|
const addFieldToDiff = (path: string, diff: Object, isScalar) => {
|
|
@@ -55,6 +58,7 @@ if (__DEV__) {
|
|
|
55
58
|
variables: variables || {},
|
|
56
59
|
missingDiff: {},
|
|
57
60
|
extraDiff: {},
|
|
61
|
+
moduleImportPaths: new Set(),
|
|
58
62
|
};
|
|
59
63
|
validateSelections(
|
|
60
64
|
optimisticResponse,
|
|
@@ -97,6 +101,7 @@ if (__DEV__) {
|
|
|
97
101
|
return;
|
|
98
102
|
case 'ScalarField':
|
|
99
103
|
case 'LinkedField':
|
|
104
|
+
case 'FlightField':
|
|
100
105
|
return validateField(optimisticResponse, selection, context);
|
|
101
106
|
case 'InlineFragment':
|
|
102
107
|
const type = selection.type;
|
|
@@ -114,6 +119,7 @@ if (__DEV__) {
|
|
|
114
119
|
});
|
|
115
120
|
return;
|
|
116
121
|
case 'ModuleImport':
|
|
122
|
+
return validateModuleImport(context);
|
|
117
123
|
case 'LinkedHandle':
|
|
118
124
|
case 'ScalarHandle':
|
|
119
125
|
case 'Defer':
|
|
@@ -128,6 +134,10 @@ if (__DEV__) {
|
|
|
128
134
|
}
|
|
129
135
|
};
|
|
130
136
|
|
|
137
|
+
const validateModuleImport = (context: ValidationContext) => {
|
|
138
|
+
context.moduleImportPaths.add(context.path);
|
|
139
|
+
};
|
|
140
|
+
|
|
131
141
|
const validateField = (
|
|
132
142
|
optimisticResponse: Object,
|
|
133
143
|
field: NormalizationField,
|
|
@@ -138,7 +148,7 @@ if (__DEV__) {
|
|
|
138
148
|
context.visitedPaths.add(path);
|
|
139
149
|
switch (field.kind) {
|
|
140
150
|
case 'ScalarField':
|
|
141
|
-
if (
|
|
151
|
+
if (hasOwnProperty.call(optimisticResponse, fieldName) === false) {
|
|
142
152
|
addFieldToDiff(path, context.missingDiff, true);
|
|
143
153
|
}
|
|
144
154
|
return;
|
|
@@ -146,7 +156,7 @@ if (__DEV__) {
|
|
|
146
156
|
const selections = field.selections;
|
|
147
157
|
if (
|
|
148
158
|
optimisticResponse[fieldName] === null ||
|
|
149
|
-
(
|
|
159
|
+
(hasOwnProperty.call(optimisticResponse, fieldName) &&
|
|
150
160
|
optimisticResponse[fieldName] === undefined)
|
|
151
161
|
) {
|
|
152
162
|
return;
|
|
@@ -178,6 +188,21 @@ if (__DEV__) {
|
|
|
178
188
|
return;
|
|
179
189
|
}
|
|
180
190
|
}
|
|
191
|
+
case 'FlightField':
|
|
192
|
+
if (
|
|
193
|
+
optimisticResponse[fieldName] === null ||
|
|
194
|
+
(hasOwnProperty.call(optimisticResponse, fieldName) &&
|
|
195
|
+
optimisticResponse[fieldName] === undefined)
|
|
196
|
+
) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
throw new Error(
|
|
200
|
+
'validateMutation: Flight fields are not compatible with ' +
|
|
201
|
+
'optimistic updates, as React does not have the component code ' +
|
|
202
|
+
'necessary to process new data on the client. Instead, you ' +
|
|
203
|
+
'should update your code to require a full refetch of the Flight ' +
|
|
204
|
+
'field so your UI can be updated.',
|
|
205
|
+
);
|
|
181
206
|
}
|
|
182
207
|
};
|
|
183
208
|
|
|
@@ -196,6 +221,10 @@ if (__DEV__) {
|
|
|
196
221
|
Object.keys(optimisticResponse).forEach((key: string) => {
|
|
197
222
|
const value = optimisticResponse[key];
|
|
198
223
|
const path = `${context.path}.${key}`;
|
|
224
|
+
// if it's a module import path we don't have an ast so we cannot validate it
|
|
225
|
+
if (context.moduleImportPaths.has(path)) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
199
228
|
if (!context.visitedPaths.has(path)) {
|
|
200
229
|
addFieldToDiff(path, context.extraDiff);
|
|
201
230
|
return;
|
|
@@ -121,3 +121,25 @@ export type SubscribeFunction = (
|
|
|
121
121
|
|
|
122
122
|
export type Uploadable = File | Blob;
|
|
123
123
|
export type UploadableMap = {[key: string]: Uploadable, ...};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* React Flight tree created on the server.
|
|
127
|
+
*/
|
|
128
|
+
export type ReactFlightServerTree = mixed;
|
|
129
|
+
export type ReactFlightPayloadQuery = {|
|
|
130
|
+
+id: mixed,
|
|
131
|
+
+module: mixed,
|
|
132
|
+
+response: GraphQLSingularResponse,
|
|
133
|
+
+variables: Variables,
|
|
134
|
+
|};
|
|
135
|
+
/**
|
|
136
|
+
* Data that is returned by a Flight compliant GraphQL server.
|
|
137
|
+
*
|
|
138
|
+
* - tree: an array of values that will be iterated and fed into
|
|
139
|
+
* ReactFlightDOMRelayClient.
|
|
140
|
+
* - queries: an array of queries that the server preloaded for the client.
|
|
141
|
+
*/
|
|
142
|
+
export type ReactFlightPayloadData = {|
|
|
143
|
+
+tree: Array<ReactFlightServerTree>,
|
|
144
|
+
+queries: Array<ReactFlightPayloadQuery>,
|
|
145
|
+
|};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "relay-runtime",
|
|
3
3
|
"description": "A core runtime for building GraphQL-driven applications.",
|
|
4
|
-
"version": "10.
|
|
4
|
+
"version": "10.1.2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"relay"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"repository": "facebook/relay",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@babel/runtime": "^7.0.0",
|
|
15
|
-
"fbjs": "^
|
|
15
|
+
"fbjs": "^3.0.0"
|
|
16
16
|
},
|
|
17
17
|
"directories": {
|
|
18
18
|
"": "./"
|
package/query/GraphQLTag.js.flow
CHANGED
|
@@ -44,7 +44,8 @@ function graphql(strings: Array<string>): GraphQLTaggedNode {
|
|
|
44
44
|
false,
|
|
45
45
|
'graphql: Unexpected invocation at runtime. Either the Babel transform ' +
|
|
46
46
|
'was not set up, or it failed to identify this call site. Make sure it ' +
|
|
47
|
-
'is being used verbatim as `graphql`.'
|
|
47
|
+
'is being used verbatim as `graphql`. Note also that there cannot be ' +
|
|
48
|
+
'a space between graphql and the backtick that follows.',
|
|
48
49
|
);
|
|
49
50
|
}
|
|
50
51
|
|
|
@@ -155,6 +156,7 @@ function getInlineDataFragment(
|
|
|
155
156
|
|
|
156
157
|
module.exports = {
|
|
157
158
|
getFragment,
|
|
159
|
+
getNode,
|
|
158
160
|
getPaginationFragment,
|
|
159
161
|
getRefetchableFragment,
|
|
160
162
|
getRequest,
|
package/query/fetchQuery.js.flow
CHANGED
|
@@ -37,9 +37,9 @@ function fetchQuery<T: OperationType>(
|
|
|
37
37
|
if (query.params.operationKind !== 'query') {
|
|
38
38
|
throw new Error('fetchQuery: Expected query operation');
|
|
39
39
|
}
|
|
40
|
-
const operation = createOperationDescriptor(query, variables);
|
|
40
|
+
const operation = createOperationDescriptor(query, variables, cacheConfig);
|
|
41
41
|
return environment
|
|
42
|
-
.execute({operation
|
|
42
|
+
.execute({operation})
|
|
43
43
|
.map(() => environment.lookup(operation.fragment).data)
|
|
44
44
|
.toPromise();
|
|
45
45
|
}
|
|
@@ -24,7 +24,6 @@ import type {
|
|
|
24
24
|
OperationDescriptor,
|
|
25
25
|
RequestDescriptor,
|
|
26
26
|
} from '../store/RelayStoreTypes';
|
|
27
|
-
import type {CacheConfig} from '../util/RelayRuntimeTypes';
|
|
28
27
|
import type {RequestIdentifier} from '../util/getRequestIdentifier';
|
|
29
28
|
|
|
30
29
|
type RequestCacheEntry = {|
|
|
@@ -106,14 +105,10 @@ const requestCachesByEnvironment = WEAKMAP_SUPPORTED
|
|
|
106
105
|
function fetchQuery(
|
|
107
106
|
environment: IEnvironment,
|
|
108
107
|
operation: OperationDescriptor,
|
|
109
|
-
options?: {|
|
|
110
|
-
networkCacheConfig?: CacheConfig,
|
|
111
|
-
|},
|
|
112
108
|
): Observable<GraphQLResponse> {
|
|
113
109
|
return fetchQueryDeduped(environment, operation.request.identifier, () =>
|
|
114
110
|
environment.execute({
|
|
115
111
|
operation,
|
|
116
|
-
cacheConfig: options?.networkCacheConfig,
|
|
117
112
|
}),
|
|
118
113
|
);
|
|
119
114
|
}
|