relay-runtime 0.0.0-main-81de3a91 → 0.0.0-main-e5f61d46

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v0.0.0-main-81de3a91
2
+ * Relay v0.0.0-main-e5f61d46
3
3
  *
4
4
  * Copyright (c) Facebook, Inc. and its affiliates.
5
5
  *
@@ -201,7 +201,10 @@ function rangeDelete(config, request) {
201
201
  return;
202
202
  }
203
203
 
204
- var deleteIDs = [];
204
+ var deleteIDs = []; // the type of data should come from a type parameter associated with ConcreteRequest,
205
+ // but ConcreteRequest does not contain a type parameter. Hence, we use a FlowFixMe.
206
+ // $FlowFixMe[incompatible-use] see above
207
+
205
208
  var deletedIDField = data[rootField];
206
209
 
207
210
  if (deletedIDField && Array.isArray(deletedIDFieldName)) {
@@ -45,9 +45,15 @@ var RelayPublishQueue = /*#__PURE__*/function () {
45
45
  // True if the next `run()` should apply the backup and rerun all optimistic
46
46
  // updates performing a rebase.
47
47
  // Payloads to apply or Sources to publish to the store with the next `run()`.
48
+ // $FlowFixMe[unclear-type] See explanation below.
48
49
  // Optimistic updaters to add with the next `run()`.
50
+ // $FlowFixMe[unclear-type] See explanation below.
49
51
  // Optimistic updaters that are already added and might be rerun in order to
50
52
  // rebase them.
53
+ // $FlowFixMe[unclear-type] See explanation below.
54
+ // For _pendingOptimisticUpdates, _appliedOptimisticUpdates, and _pendingData,
55
+ // we want to parametrize by "any" since the type is effectively
56
+ // "the union of all T's that PublishQueue's methods were called with".
51
57
  // Garbage collection hold, should rerun gc on dispose
52
58
  function RelayPublishQueue(store, handlerProvider, getDataID) {
53
59
  this._hasStoreSnapshot = false;
@@ -301,7 +307,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
301
307
 
302
308
  var sink = RelayRecordSource.create();
303
309
  var mutator = new RelayRecordSourceMutator(this._store.getSource(), sink);
304
- var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider);
310
+ var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider); // $FlowFixMe[unclear-type] see explanation above.
305
311
 
306
312
  var processUpdate = function processUpdate(optimisticUpdate) {
307
313
  if (optimisticUpdate.storeUpdater) {
@@ -18,6 +18,7 @@ import type RelayObservable from '../network/RelayObservable';
18
18
  import type {
19
19
  ExecuteMutationConfig,
20
20
  LogFunction,
21
+ MutationParameters,
21
22
  OperationAvailability,
22
23
  OperationDescriptor,
23
24
  OperationTracker,
@@ -112,7 +113,9 @@ class ActorSpecificEnvironment implements IActorEnvironment {
112
113
  return this._defaultRenderPolicy;
113
114
  }
114
115
 
115
- applyMutation(optimisticConfig: OptimisticResponseConfig): Disposable {
116
+ applyMutation<TMutation: MutationParameters>(
117
+ optimisticConfig: OptimisticResponseConfig<TMutation>,
118
+ ): Disposable {
116
119
  return this.multiActorEnvironment.applyMutation(this, optimisticConfig);
117
120
  }
118
121
 
@@ -190,15 +193,15 @@ class ActorSpecificEnvironment implements IActorEnvironment {
190
193
  return this.multiActorEnvironment.execute(this, config);
191
194
  }
192
195
 
193
- executeSubscription(config: {
196
+ executeSubscription<TMutation: MutationParameters>(config: {
194
197
  operation: OperationDescriptor,
195
- updater: ?SelectorStoreUpdater,
198
+ updater?: ?SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
196
199
  }): RelayObservable<GraphQLResponse> {
197
200
  return this.multiActorEnvironment.executeSubscription(this, config);
198
201
  }
199
202
 
200
- executeMutation(
201
- options: ExecuteMutationConfig,
203
+ executeMutation<TMutation: MutationParameters>(
204
+ options: ExecuteMutationConfig<TMutation>,
202
205
  ): RelayObservable<GraphQLResponse> {
203
206
  return this.multiActorEnvironment.executeMutation(this, options);
204
207
  }
@@ -21,6 +21,7 @@ import type {
21
21
  LogFunction,
22
22
  MissingFieldHandler,
23
23
  MutableRecordSource,
24
+ MutationParameters,
24
25
  OperationAvailability,
25
26
  OperationDescriptor,
26
27
  OperationLoader,
@@ -273,9 +274,9 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
273
274
  });
274
275
  }
275
276
 
276
- applyMutation(
277
+ applyMutation<TMutation: MutationParameters>(
277
278
  actorEnvironment: IActorEnvironment,
278
- optimisticConfig: OptimisticResponseConfig,
279
+ optimisticConfig: OptimisticResponseConfig<TMutation>,
279
280
  ): Disposable {
280
281
  const subscription = this._execute(actorEnvironment, {
281
282
  createSource: () => RelayObservable.create(_sink => {}),
@@ -347,14 +348,14 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
347
348
  });
348
349
  }
349
350
 
350
- executeSubscription(
351
+ executeSubscription<TMutation: MutationParameters>(
351
352
  actorEnvironment: IActorEnvironment,
352
353
  {
353
354
  operation,
354
355
  updater,
355
356
  }: {
356
357
  operation: OperationDescriptor,
357
- updater?: ?SelectorStoreUpdater,
358
+ updater?: ?SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
358
359
  },
359
360
  ): RelayObservable<GraphQLResponse> {
360
361
  return this._execute(actorEnvironment, {
@@ -374,7 +375,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
374
375
  });
375
376
  }
376
377
 
377
- executeMutation(
378
+ executeMutation<TMutation: MutationParameters>(
378
379
  actorEnvironment: IActorEnvironment,
379
380
  {
380
381
  operation,
@@ -382,7 +383,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
382
383
  optimisticUpdater,
383
384
  updater,
384
385
  uploadables,
385
- }: ExecuteMutationConfig,
386
+ }: ExecuteMutationConfig<TMutation>,
386
387
  ): RelayObservable<GraphQLResponse> {
387
388
  let optimisticConfig;
388
389
  if (optimisticResponse || optimisticUpdater) {
@@ -438,7 +439,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
438
439
  return this._isServer;
439
440
  }
440
441
 
441
- _execute(
442
+ _execute<TMutation: MutationParameters>(
442
443
  actorEnvironment: IActorEnvironment,
443
444
  {
444
445
  createSource,
@@ -450,8 +451,8 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
450
451
  createSource: () => RelayObservable<GraphQLResponse>,
451
452
  isClientPayload: boolean,
452
453
  operation: OperationDescriptor,
453
- optimisticConfig: ?OptimisticResponseConfig,
454
- updater: ?SelectorStoreUpdater,
454
+ optimisticConfig: ?OptimisticResponseConfig<TMutation>,
455
+ updater: ?SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
455
456
  |},
456
457
  ): RelayObservable<GraphQLResponse> {
457
458
  return RelayObservable.create(sink => {
@@ -17,6 +17,7 @@ import type RelayPublishQueue from '../store/RelayPublishQueue';
17
17
  import type {
18
18
  ExecuteMutationConfig,
19
19
  IEnvironment,
20
+ MutationParameters,
20
21
  OperationAvailability,
21
22
  OperationDescriptor,
22
23
  OptimisticResponseConfig,
@@ -138,9 +139,9 @@ export interface IMultiActorEnvironment {
138
139
  * Apply an optimistic mutation response and/or updater. The mutation can be
139
140
  * reverted by calling `dispose()` on the returned value.
140
141
  */
141
- applyMutation(
142
+ applyMutation<TMutation: MutationParameters>(
142
143
  actorEnvironment: IActorEnvironment,
143
- optimisticConfig: OptimisticResponseConfig,
144
+ optimisticConfig: OptimisticResponseConfig<TMutation>,
144
145
  ): Disposable;
145
146
 
146
147
  /**
@@ -201,11 +202,11 @@ export interface IMultiActorEnvironment {
201
202
  * Note: Observables are lazy, so calling this method will do nothing until
202
203
  * the result is subscribed to: environment.executeSubscription({...}).subscribe({...}).
203
204
  */
204
- executeSubscription(
205
+ executeSubscription<TMutation: MutationParameters>(
205
206
  actorEnvironment: IActorEnvironment,
206
207
  config: {
207
208
  operation: OperationDescriptor,
208
- updater?: ?SelectorStoreUpdater,
209
+ updater?: ?SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
209
210
  },
210
211
  ): RelayObservable<GraphQLResponse>;
211
212
 
@@ -219,9 +220,9 @@ export interface IMultiActorEnvironment {
219
220
  * the result is subscribed to:
220
221
  * environment.executeMutation({...}).subscribe({...}).
221
222
  */
222
- executeMutation(
223
+ executeMutation<TMutation: MutationParameters>(
223
224
  actorEnvironment: IActorEnvironment,
224
- config: ExecuteMutationConfig,
225
+ config: ExecuteMutationConfig<TMutation>,
225
226
  ): RelayObservable<GraphQLResponse>;
226
227
 
227
228
  /**
@@ -13,6 +13,7 @@
13
13
  'use strict';
14
14
 
15
15
  import type {
16
+ MutationParameters,
16
17
  RecordSourceSelectorProxy,
17
18
  SelectorData,
18
19
  SelectorStoreUpdater,
@@ -83,18 +84,24 @@ export type DeclarativeMutationConfig =
83
84
  | RangeDeleteConfig
84
85
  | NodeDeleteConfig;
85
86
 
86
- function convert(
87
+ function convert<TMutation: MutationParameters>(
87
88
  configs: Array<DeclarativeMutationConfig>,
88
89
  request: ConcreteRequest,
89
- optimisticUpdater?: ?SelectorStoreUpdater,
90
- updater?: ?SelectorStoreUpdater,
90
+ optimisticUpdater?: ?SelectorStoreUpdater<
91
+ $ElementType<TMutation, 'response'>,
92
+ >,
93
+ updater?: ?SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
91
94
  ): {
92
- optimisticUpdater: SelectorStoreUpdater,
93
- updater: SelectorStoreUpdater,
95
+ optimisticUpdater: SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
96
+ updater: SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
94
97
  ...
95
98
  } {
96
- const configOptimisticUpdates = optimisticUpdater ? [optimisticUpdater] : [];
97
- const configUpdates = updater ? [updater] : [];
99
+ const configOptimisticUpdates: Array<
100
+ SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
101
+ > = optimisticUpdater ? [optimisticUpdater] : [];
102
+ const configUpdates: Array<
103
+ SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
104
+ > = updater ? [updater] : [];
98
105
  configs.forEach(config => {
99
106
  switch (config.type) {
100
107
  case 'NODE_DELETE':
@@ -123,13 +130,16 @@ function convert(
123
130
  return {
124
131
  optimisticUpdater: (
125
132
  store: RecordSourceSelectorProxy,
126
- data: ?SelectorData,
133
+ data: ?$ElementType<TMutation, 'response'>,
127
134
  ) => {
128
135
  configOptimisticUpdates.forEach(eachOptimisticUpdater => {
129
136
  eachOptimisticUpdater(store, data);
130
137
  });
131
138
  },
132
- updater: (store: RecordSourceSelectorProxy, data: ?SelectorData) => {
139
+ updater: (
140
+ store: RecordSourceSelectorProxy,
141
+ data: ?$ElementType<TMutation, 'response'>,
142
+ ) => {
133
143
  configUpdates.forEach(eachUpdater => {
134
144
  eachUpdater(store, data);
135
145
  });
@@ -140,13 +150,13 @@ function convert(
140
150
  function nodeDelete(
141
151
  config: NodeDeleteConfig,
142
152
  request: ConcreteRequest,
143
- ): ?SelectorStoreUpdater {
153
+ ): ?SelectorStoreUpdater<mixed> {
144
154
  const {deletedIDFieldName} = config;
145
155
  const rootField = getRootField(request);
146
156
  if (!rootField) {
147
157
  return null;
148
158
  }
149
- return (store: RecordSourceSelectorProxy, data: ?SelectorData) => {
159
+ return (store: RecordSourceSelectorProxy, data: ?mixed) => {
150
160
  const payload = store.getRootField(rootField);
151
161
  if (!payload) {
152
162
  return;
@@ -164,7 +174,7 @@ function nodeDelete(
164
174
  function rangeAdd(
165
175
  config: RangeAddConfig,
166
176
  request: ConcreteRequest,
167
- ): ?SelectorStoreUpdater {
177
+ ): ?SelectorStoreUpdater<mixed> {
168
178
  const {parentID, connectionInfo, edgeName} = config;
169
179
  if (!parentID) {
170
180
  warning(
@@ -178,7 +188,7 @@ function rangeAdd(
178
188
  if (!connectionInfo || !rootField) {
179
189
  return null;
180
190
  }
181
- return (store: RecordSourceSelectorProxy, data: ?SelectorData) => {
191
+ return (store: RecordSourceSelectorProxy, data: ?mixed) => {
182
192
  const parent = store.get(parentID);
183
193
  if (!parent) {
184
194
  return;
@@ -232,7 +242,7 @@ function rangeAdd(
232
242
  function rangeDelete(
233
243
  config: RangeDeleteConfig,
234
244
  request: ConcreteRequest,
235
- ): ?SelectorStoreUpdater {
245
+ ): ?SelectorStoreUpdater<mixed> {
236
246
  const {
237
247
  parentID,
238
248
  connectionKeys,
@@ -251,12 +261,16 @@ function rangeDelete(
251
261
  if (!rootField) {
252
262
  return null;
253
263
  }
254
- return (store: RecordSourceSelectorProxy, data: ?SelectorData) => {
264
+ return (store: RecordSourceSelectorProxy, data: ?mixed) => {
255
265
  if (!data) {
256
266
  return;
257
267
  }
258
268
  const deleteIDs = [];
269
+ // the type of data should come from a type parameter associated with ConcreteRequest,
270
+ // but ConcreteRequest does not contain a type parameter. Hence, we use a FlowFixMe.
271
+ // $FlowFixMe[incompatible-use] see above
259
272
  let deletedIDField = data[rootField];
273
+
260
274
  if (deletedIDField && Array.isArray(deletedIDFieldName)) {
261
275
  for (const eachField of deletedIDFieldName) {
262
276
  if (deletedIDField && typeof deletedIDField === 'object') {
@@ -15,6 +15,7 @@
15
15
  import type {GraphQLTaggedNode} from '../query/GraphQLTag';
16
16
  import type {
17
17
  IEnvironment,
18
+ MutationParameters,
18
19
  SelectorStoreUpdater,
19
20
  } from '../store/RelayStoreTypes';
20
21
  import type {Disposable, Variables} from '../util/RelayRuntimeTypes';
@@ -28,11 +29,13 @@ const {
28
29
  const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
29
30
  const invariant = require('invariant');
30
31
 
31
- export type OptimisticMutationConfig = {|
32
+ export type OptimisticMutationConfig<TMutation: MutationParameters> = {|
32
33
  configs?: ?Array<DeclarativeMutationConfig>,
33
34
  mutation: GraphQLTaggedNode,
34
35
  variables: Variables,
35
- optimisticUpdater?: ?SelectorStoreUpdater,
36
+ optimisticUpdater?: ?SelectorStoreUpdater<
37
+ $ElementType<TMutation, 'response'>,
38
+ >,
36
39
  optimisticResponse?: Object,
37
40
  |};
38
41
 
@@ -40,9 +43,9 @@ export type OptimisticMutationConfig = {|
40
43
  * Higher-level helper function to execute a mutation against a specific
41
44
  * environment.
42
45
  */
43
- function applyOptimisticMutation(
46
+ function applyOptimisticMutation<TMutation: MutationParameters>(
44
47
  environment: IEnvironment,
45
- config: OptimisticMutationConfig,
48
+ config: OptimisticMutationConfig<TMutation>,
46
49
  ): Disposable {
47
50
  invariant(
48
51
  isRelayModernEnvironment(environment),
@@ -37,27 +37,30 @@ const validateMutation = require('./validateMutation');
37
37
  const invariant = require('invariant');
38
38
  const warning = require('warning');
39
39
 
40
- export type DEPRECATED_MutationConfig<T> = {|
40
+ export type DEPRECATED_MutationConfig<TMutationResponse> = {|
41
41
  configs?: Array<DeclarativeMutationConfig>,
42
42
  cacheConfig?: CacheConfig,
43
43
  mutation: GraphQLTaggedNode,
44
44
  variables: Variables,
45
45
  uploadables?: UploadableMap,
46
- onCompleted?: ?(response: T, errors: ?Array<PayloadError>) => void,
46
+ onCompleted?: ?(
47
+ response: TMutationResponse,
48
+ errors: ?Array<PayloadError>,
49
+ ) => void,
47
50
  onError?: ?(error: Error) => void,
48
51
  onUnsubscribe?: ?() => void,
49
- optimisticUpdater?: ?SelectorStoreUpdater,
52
+ optimisticUpdater?: ?SelectorStoreUpdater<TMutationResponse>,
50
53
  optimisticResponse?: Object,
51
- updater?: ?SelectorStoreUpdater,
54
+ updater?: ?SelectorStoreUpdater<TMutationResponse>,
52
55
  |};
53
56
 
54
- export type MutationConfig<T: MutationParameters> = {|
57
+ export type MutationConfig<TMutation: MutationParameters> = {|
55
58
  configs?: Array<DeclarativeMutationConfig>,
56
59
  cacheConfig?: CacheConfig,
57
60
  mutation: GraphQLTaggedNode,
58
61
  onError?: ?(error: Error) => void,
59
62
  onCompleted?: ?(
60
- response: $ElementType<T, 'response'>,
63
+ response: $ElementType<TMutation, 'response'>,
61
64
  errors: ?Array<PayloadError>,
62
65
  ) => void,
63
66
  onNext?: ?() => void,
@@ -65,24 +68,26 @@ export type MutationConfig<T: MutationParameters> = {|
65
68
  optimisticResponse?: $ElementType<
66
69
  {
67
70
  +rawResponse?: {...},
68
- ...T,
71
+ ...TMutation,
69
72
  ...
70
73
  },
71
74
  'rawResponse',
72
75
  >,
73
- optimisticUpdater?: ?SelectorStoreUpdater,
74
- updater?: ?SelectorStoreUpdater,
76
+ optimisticUpdater?: ?SelectorStoreUpdater<
77
+ $ElementType<TMutation, 'response'>,
78
+ >,
79
+ updater?: ?SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
75
80
  uploadables?: UploadableMap,
76
- variables: $ElementType<T, 'variables'>,
81
+ variables: $ElementType<TMutation, 'variables'>,
77
82
  |};
78
83
 
79
84
  /**
80
85
  * Higher-level helper function to execute a mutation against a specific
81
86
  * environment.
82
87
  */
83
- function commitMutation<T: MutationParameters>(
88
+ function commitMutation<TMutation: MutationParameters>(
84
89
  environment: IEnvironment,
85
- config: MutationConfig<T>,
90
+ config: MutationConfig<TMutation>,
86
91
  ): Disposable {
87
92
  invariant(
88
93
  isRelayModernEnvironment(environment),
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": "0.0.0-main-81de3a91",
4
+ "version": "0.0.0-main-e5f61d46",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"