relay-runtime 13.0.0 → 13.1.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/README.md +1 -4
- package/index.js +1 -1
- package/index.js.flow +2 -0
- package/lib/index.js +4 -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/util/withProvidedVariables.js +49 -0
- 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 +2 -2
- package/store/RelayConcreteVariables.js.flow +12 -2
- package/store/RelayExperimentalGraphResponseTransform.js.flow +35 -1
- package/store/RelayModernOperationDescriptor.js.flow +5 -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/subscription/requestSubscription.js.flow +7 -12
- 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
|
@@ -37,32 +37,15 @@ const validateMutation = require('./validateMutation');
|
|
|
37
37
|
const invariant = require('invariant');
|
|
38
38
|
const warning = require('warning');
|
|
39
39
|
|
|
40
|
-
export type DEPRECATED_MutationConfig<TMutationResponse> = {|
|
|
41
|
-
configs?: Array<DeclarativeMutationConfig>,
|
|
42
|
-
cacheConfig?: CacheConfig,
|
|
43
|
-
mutation: GraphQLTaggedNode,
|
|
44
|
-
variables: Variables,
|
|
45
|
-
uploadables?: UploadableMap,
|
|
46
|
-
onCompleted?: ?(
|
|
47
|
-
response: TMutationResponse,
|
|
48
|
-
errors: ?Array<PayloadError>,
|
|
49
|
-
) => void,
|
|
50
|
-
onError?: ?(error: Error) => void,
|
|
51
|
-
onUnsubscribe?: ?() => void,
|
|
52
|
-
optimisticUpdater?: ?SelectorStoreUpdater<TMutationResponse>,
|
|
53
|
-
optimisticResponse?: Object,
|
|
54
|
-
updater?: ?SelectorStoreUpdater<TMutationResponse>,
|
|
55
|
-
|};
|
|
56
|
-
|
|
57
40
|
export type MutationConfig<TMutation: MutationParameters> = {|
|
|
58
|
-
configs?: Array<DeclarativeMutationConfig>,
|
|
59
41
|
cacheConfig?: CacheConfig,
|
|
42
|
+
configs?: Array<DeclarativeMutationConfig>,
|
|
60
43
|
mutation: GraphQLTaggedNode,
|
|
61
|
-
onError?: ?(error: Error) => void,
|
|
62
44
|
onCompleted?: ?(
|
|
63
45
|
response: TMutation['response'],
|
|
64
46
|
errors: ?Array<PayloadError>,
|
|
65
47
|
) => void,
|
|
48
|
+
onError?: ?(error: Error) => void,
|
|
66
49
|
onNext?: ?() => void,
|
|
67
50
|
onUnsubscribe?: ?() => void,
|
|
68
51
|
optimisticResponse?: {
|
|
@@ -76,6 +59,12 @@ export type MutationConfig<TMutation: MutationParameters> = {|
|
|
|
76
59
|
variables: TMutation['variables'],
|
|
77
60
|
|};
|
|
78
61
|
|
|
62
|
+
export type DEPRECATED_MutationConfig<TMutationResponse> = MutationConfig<{|
|
|
63
|
+
response: TMutationResponse,
|
|
64
|
+
rawResponse: any,
|
|
65
|
+
variables: Variables,
|
|
66
|
+
|}>;
|
|
67
|
+
|
|
79
68
|
/**
|
|
80
69
|
* Higher-level helper function to execute a mutation against a specific
|
|
81
70
|
* environment.
|
|
@@ -21,7 +21,7 @@ import type {OperationType} from '../util/RelayRuntimeTypes';
|
|
|
21
21
|
const {getRequest} = require('../query/GraphQLTag');
|
|
22
22
|
const {getArgumentValues} = require('../store/RelayStoreUtils');
|
|
23
23
|
|
|
24
|
-
const nonUpdatableKeys = ['id', '__id', '__typename'];
|
|
24
|
+
const nonUpdatableKeys = ['id', '__id', '__typename', 'js'];
|
|
25
25
|
|
|
26
26
|
function readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
|
|
27
27
|
query: GraphQLTaggedNode,
|
|
@@ -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'],
|
|
@@ -216,7 +214,7 @@ function createSetterForSingularLinkedField<TQuery: OperationType>(
|
|
|
216
214
|
const variables = getArgumentValues(selection.args ?? [], queryVariables);
|
|
217
215
|
if (newValue == null) {
|
|
218
216
|
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
219
|
-
recordProxy.setValue(
|
|
217
|
+
recordProxy.setValue(newValue, selection.name, (variables: any));
|
|
220
218
|
} else {
|
|
221
219
|
const {__id} = newValue;
|
|
222
220
|
if (__id == null) {
|
|
@@ -141,6 +141,7 @@ if (__DEV__) {
|
|
|
141
141
|
case INLINE_FRAGMENT:
|
|
142
142
|
const type = selection.type;
|
|
143
143
|
const isConcreteType = selection.abstractKey == null;
|
|
144
|
+
validateAbstractKey(context, selection.abstractKey);
|
|
144
145
|
selection.selections.forEach(subselection => {
|
|
145
146
|
if (isConcreteType && optimisticResponse.__typename !== type) {
|
|
146
147
|
return;
|
|
@@ -155,11 +156,12 @@ if (__DEV__) {
|
|
|
155
156
|
return;
|
|
156
157
|
case MODULE_IMPORT:
|
|
157
158
|
return validateModuleImport(context);
|
|
159
|
+
case TYPE_DISCRIMINATOR:
|
|
160
|
+
return validateAbstractKey(context, selection.abstractKey);
|
|
158
161
|
case LINKED_HANDLE:
|
|
159
162
|
case SCALAR_HANDLE:
|
|
160
163
|
case DEFER:
|
|
161
|
-
case STREAM:
|
|
162
|
-
case TYPE_DISCRIMINATOR: {
|
|
164
|
+
case STREAM: {
|
|
163
165
|
// TODO(T35864292) - Add missing validations for these types
|
|
164
166
|
return;
|
|
165
167
|
}
|
|
@@ -173,6 +175,16 @@ if (__DEV__) {
|
|
|
173
175
|
context.moduleImportPaths.add(context.path);
|
|
174
176
|
};
|
|
175
177
|
|
|
178
|
+
const validateAbstractKey = (
|
|
179
|
+
context: ValidationContext,
|
|
180
|
+
abstractKey: ?string,
|
|
181
|
+
) => {
|
|
182
|
+
if (abstractKey != null) {
|
|
183
|
+
const path = `${context.path}.${abstractKey}`;
|
|
184
|
+
context.visitedPaths.add(path);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
176
188
|
const validateField = (
|
|
177
189
|
optimisticResponse: Object,
|
|
178
190
|
field: NormalizationField,
|
|
@@ -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,10 @@ function create(
|
|
|
45
46
|
uploadables?: ?UploadableMap,
|
|
46
47
|
logRequestInfo: ?LogRequestInfoFunction,
|
|
47
48
|
): RelayObservable<GraphQLResponse> {
|
|
49
|
+
const operationVariables = withProvidedVariables(
|
|
50
|
+
variables,
|
|
51
|
+
request.providedVariables,
|
|
52
|
+
);
|
|
48
53
|
if (request.operationKind === 'subscription') {
|
|
49
54
|
invariant(
|
|
50
55
|
subscribe,
|
|
@@ -56,7 +61,7 @@ function create(
|
|
|
56
61
|
!uploadables,
|
|
57
62
|
'RelayNetwork: Cannot provide uploadables while subscribing.',
|
|
58
63
|
);
|
|
59
|
-
return subscribe(request,
|
|
64
|
+
return subscribe(request, operationVariables, cacheConfig);
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
const pollInterval = cacheConfig.poll;
|
|
@@ -65,12 +70,14 @@ function create(
|
|
|
65
70
|
!uploadables,
|
|
66
71
|
'RelayNetwork: Cannot provide uploadables while polling.',
|
|
67
72
|
);
|
|
68
|
-
return observeFetch(request,
|
|
73
|
+
return observeFetch(request, operationVariables, {force: true}).poll(
|
|
74
|
+
pollInterval,
|
|
75
|
+
);
|
|
69
76
|
}
|
|
70
77
|
|
|
71
78
|
return observeFetch(
|
|
72
79
|
request,
|
|
73
|
-
|
|
80
|
+
operationVariables,
|
|
74
81
|
cacheConfig,
|
|
75
82
|
uploadables,
|
|
76
83
|
logRequestInfo,
|
|
@@ -26,7 +26,7 @@ export interface INetwork {
|
|
|
26
26
|
|
|
27
27
|
export type LogRequestInfoFunction = mixed => void;
|
|
28
28
|
|
|
29
|
-
export type PayloadData =
|
|
29
|
+
export type PayloadData = {[key: string]: mixed};
|
|
30
30
|
|
|
31
31
|
export type PayloadError = interface {
|
|
32
32
|
message: string,
|
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": "13.
|
|
4
|
+
"version": "13.1.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"relay"
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"homepage": "https://relay.dev",
|
|
11
11
|
"bugs": "https://github.com/facebook/relay/issues",
|
|
12
|
-
"repository":
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/facebook/relay.git",
|
|
15
|
+
"directory": "packages/relay-runtime"
|
|
16
|
+
},
|
|
13
17
|
"dependencies": {
|
|
14
18
|
"@babel/runtime": "^7.0.0",
|
|
15
19
|
"fbjs": "^3.0.2",
|
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
|
|