relay-runtime 10.1.3 → 11.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.
Files changed (106) hide show
  1. package/handlers/connection/ConnectionHandler.js.flow +60 -0
  2. package/handlers/connection/MutationHandlers.js.flow +28 -0
  3. package/index.js +1 -1
  4. package/index.js.flow +9 -3
  5. package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
  6. package/lib/handlers/connection/ConnectionHandler.js +68 -6
  7. package/lib/handlers/connection/MutationHandlers.js +67 -8
  8. package/lib/index.js +3 -0
  9. package/lib/multi-actor-environment/ActorIdentifier.js +23 -0
  10. package/lib/multi-actor-environment/ActorSpecificEnvironment.js +108 -0
  11. package/lib/multi-actor-environment/MultiActorEnvironment.js +156 -0
  12. package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
  13. package/lib/multi-actor-environment/index.js +17 -0
  14. package/lib/mutations/RelayRecordProxy.js +1 -1
  15. package/lib/mutations/RelayRecordSourceMutator.js +1 -1
  16. package/lib/mutations/RelayRecordSourceProxy.js +1 -1
  17. package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -1
  18. package/lib/mutations/applyOptimisticMutation.js +1 -1
  19. package/lib/mutations/commitMutation.js +1 -1
  20. package/lib/mutations/validateMutation.js +36 -15
  21. package/lib/network/RelayNetwork.js +1 -1
  22. package/lib/network/RelayQueryResponseCache.js +3 -2
  23. package/lib/query/GraphQLTag.js +1 -1
  24. package/lib/query/fetchQuery.js +129 -13
  25. package/lib/query/fetchQueryInternal.js +3 -4
  26. package/lib/query/fetchQuery_DEPRECATED.js +39 -0
  27. package/lib/store/DataChecker.js +26 -14
  28. package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +117 -47
  29. package/lib/store/RelayConcreteVariables.js +8 -4
  30. package/lib/store/RelayModernEnvironment.js +105 -136
  31. package/lib/store/RelayModernFragmentSpecResolver.js +16 -9
  32. package/lib/store/RelayModernRecord.js +1 -1
  33. package/lib/store/RelayModernSelector.js +1 -1
  34. package/lib/store/RelayModernStore.js +19 -20
  35. package/lib/store/RelayOperationTracker.js +55 -49
  36. package/lib/store/RelayPublishQueue.js +9 -5
  37. package/lib/store/RelayReader.js +68 -14
  38. package/lib/store/RelayReferenceMarker.js +28 -14
  39. package/lib/store/RelayResponseNormalizer.js +109 -15
  40. package/lib/store/RelayStoreReactFlightUtils.js +6 -4
  41. package/lib/store/RelayStoreSubscriptions.js +18 -8
  42. package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +90 -30
  43. package/lib/store/RelayStoreUtils.js +3 -2
  44. package/lib/store/ResolverFragments.js +57 -0
  45. package/lib/store/cloneRelayHandleSourceField.js +1 -1
  46. package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
  47. package/lib/store/createFragmentSpecResolver.js +2 -2
  48. package/lib/store/createRelayContext.js +1 -1
  49. package/lib/store/defaultGetDataID.js +3 -1
  50. package/lib/store/hasOverlappingIDs.js +11 -3
  51. package/lib/store/readInlineData.js +1 -1
  52. package/lib/subscription/requestSubscription.js +33 -5
  53. package/lib/util/RelayConcreteNode.js +2 -0
  54. package/lib/util/RelayFeatureFlags.js +8 -3
  55. package/lib/util/RelayProfiler.js +17 -187
  56. package/lib/util/RelayReplaySubject.js +1 -1
  57. package/lib/util/deepFreeze.js +1 -0
  58. package/lib/util/getRelayHandleKey.js +1 -1
  59. package/lib/util/getRequestIdentifier.js +1 -1
  60. package/multi-actor-environment/ActorIdentifier.js.flow +27 -0
  61. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +189 -0
  62. package/multi-actor-environment/MultiActorEnvironment.js.flow +233 -0
  63. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +196 -0
  64. package/multi-actor-environment/index.js.flow +24 -0
  65. package/mutations/RelayRecordSourceProxy.js.flow +3 -2
  66. package/mutations/commitMutation.js.flow +1 -1
  67. package/mutations/validateMutation.js.flow +40 -15
  68. package/network/RelayNetworkTypes.js.flow +31 -11
  69. package/network/RelayQueryResponseCache.js.flow +2 -1
  70. package/package.json +3 -2
  71. package/query/fetchQuery.js.flow +147 -20
  72. package/query/fetchQueryInternal.js.flow +2 -3
  73. package/query/fetchQuery_DEPRECATED.js.flow +47 -0
  74. package/relay-runtime.js +2 -2
  75. package/relay-runtime.min.js +2 -2
  76. package/store/DataChecker.js.flow +23 -15
  77. package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +128 -40
  78. package/store/RelayConcreteVariables.js.flow +5 -0
  79. package/store/RelayModernEnvironment.js.flow +100 -130
  80. package/store/RelayModernFragmentSpecResolver.js.flow +30 -8
  81. package/store/RelayModernStore.js.flow +28 -24
  82. package/store/RelayOperationTracker.js.flow +69 -56
  83. package/store/RelayPublishQueue.js.flow +7 -4
  84. package/store/RelayReader.js.flow +63 -11
  85. package/store/RelayRecordSource.js.flow +3 -3
  86. package/store/RelayRecordSourceMapImpl.js.flow +6 -2
  87. package/store/RelayReferenceMarker.js.flow +28 -18
  88. package/store/RelayResponseNormalizer.js.flow +134 -23
  89. package/store/RelayStoreReactFlightUtils.js.flow +9 -4
  90. package/store/RelayStoreSubscriptions.js.flow +22 -7
  91. package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +36 -12
  92. package/store/RelayStoreTypes.js.flow +51 -22
  93. package/store/RelayStoreUtils.js.flow +2 -1
  94. package/store/ResolverFragments.js.flow +125 -0
  95. package/store/createFragmentSpecResolver.js.flow +2 -0
  96. package/store/defaultGetDataID.js.flow +3 -1
  97. package/store/hasOverlappingIDs.js.flow +11 -9
  98. package/subscription/requestSubscription.js.flow +25 -2
  99. package/util/NormalizationNode.js.flow +13 -0
  100. package/util/ReaderNode.js.flow +14 -1
  101. package/util/RelayConcreteNode.js.flow +2 -0
  102. package/util/RelayFeatureFlags.js.flow +12 -2
  103. package/util/RelayProfiler.js.flow +22 -194
  104. package/util/RelayRuntimeTypes.js.flow +4 -5
  105. package/util/deepFreeze.js.flow +2 -1
  106. package/util/isEmptyObject.js.flow +1 -1
@@ -12,25 +12,15 @@
12
12
 
13
13
  'use strict';
14
14
 
15
- type Handler = (name: string, callback: () => void) => void;
16
- type ProfileHandler = (name: string, state?: any) => (error?: Error) => void;
15
+ type EventName = 'fetchRelayQuery';
16
+ type ProfileHandler = (name: EventName, state?: any) => (error?: Error) => void;
17
17
 
18
- function emptyFunction() {}
18
+ const profileHandlersByName: {|
19
+ [name: EventName]: Array<ProfileHandler>,
20
+ |} = {};
19
21
 
20
- const aggregateHandlersByName: {[name: string]: Array<Handler>, ...} = {
21
- '*': [],
22
- };
23
- const profileHandlersByName: {[name: string]: Array<ProfileHandler>, ...} = {
24
- '*': [],
25
- };
26
-
27
- const NOT_INVOKED = {};
28
- const defaultProfiler = {stop: emptyFunction};
29
- const shouldInstrument = name => {
30
- if (__DEV__) {
31
- return true;
32
- }
33
- return name.charAt(0) !== '@';
22
+ const defaultProfiler = {
23
+ stop() {},
34
24
  };
35
25
 
36
26
  /**
@@ -60,154 +50,8 @@ const shouldInstrument = name => {
60
50
  * console.log(`Duration (${name})`, performance.now() - start);
61
51
  * }
62
52
  * });
63
- *
64
- * In order to reduce the impact on performance in production, instrumented
65
- * methods and profilers with names that begin with `@` will only be measured
66
- * if `__DEV__` is true. This should be used for very hot functions.
67
53
  */
68
54
  const RelayProfiler = {
69
- /**
70
- * Instruments methods on a class or object. This re-assigns the method in
71
- * order to preserve function names in stack traces (which are detected by
72
- * modern debuggers via heuristics). Example usage:
73
- *
74
- * const RelayStore = { primeCache: function() {...} };
75
- * RelayProfiler.instrumentMethods(RelayStore, {
76
- * primeCache: 'RelayStore.primeCache'
77
- * });
78
- *
79
- * RelayStore.primeCache.attachHandler(...);
80
- *
81
- * As a result, the methods will be replaced by wrappers that provide the
82
- * `attachHandler` and `detachHandler` methods.
83
- */
84
- instrumentMethods(
85
- object: Function | Object,
86
- names: {[key: string]: string, ...},
87
- ): void {
88
- for (const key in names) {
89
- if (names.hasOwnProperty(key)) {
90
- if (typeof object[key] === 'function') {
91
- object[key] = RelayProfiler.instrument(names[key], object[key]);
92
- }
93
- }
94
- }
95
- },
96
-
97
- /**
98
- * Wraps the supplied function with one that provides the `attachHandler` and
99
- * `detachHandler` methods. Example usage:
100
- *
101
- * const printRelayQuery =
102
- * RelayProfiler.instrument('printRelayQuery', printRelayQuery);
103
- *
104
- * printRelayQuery.attachHandler(...);
105
- *
106
- * NOTE: The instrumentation assumes that no handlers are attached or detached
107
- * in the course of executing another handler.
108
- */
109
- instrument<T: Function>(name: string, originalFunction: T): T {
110
- if (!shouldInstrument(name)) {
111
- originalFunction.attachHandler = emptyFunction;
112
- originalFunction.detachHandler = emptyFunction;
113
- return originalFunction;
114
- }
115
- if (!aggregateHandlersByName.hasOwnProperty(name)) {
116
- aggregateHandlersByName[name] = [];
117
- }
118
- const catchallHandlers = aggregateHandlersByName['*'];
119
- const aggregateHandlers = aggregateHandlersByName[name];
120
- const handlers: Array<Handler> = [];
121
- const contexts: Array<[number, number, number, any, any, any]> = [];
122
- const invokeHandlers = function() {
123
- const context = contexts[contexts.length - 1];
124
- if (context[0]) {
125
- context[0]--;
126
- catchallHandlers[context[0]](name, invokeHandlers);
127
- } else if (context[1]) {
128
- context[1]--;
129
- aggregateHandlers[context[1]](name, invokeHandlers);
130
- } else if (context[2]) {
131
- context[2]--;
132
- handlers[context[2]](name, invokeHandlers);
133
- } else {
134
- context[5] = originalFunction.apply(context[3], context[4]);
135
- }
136
- };
137
- const instrumentedCallback = function() {
138
- let returnValue;
139
- if (
140
- aggregateHandlers.length === 0 &&
141
- handlers.length === 0 &&
142
- catchallHandlers.length === 0
143
- ) {
144
- returnValue = originalFunction.apply(this, arguments);
145
- } else {
146
- contexts.push([
147
- catchallHandlers.length,
148
- aggregateHandlers.length,
149
- handlers.length,
150
- this,
151
- arguments,
152
- NOT_INVOKED,
153
- ]);
154
- invokeHandlers();
155
- const context = contexts.pop();
156
- returnValue = context[5];
157
- if (returnValue === NOT_INVOKED) {
158
- throw new Error(
159
- 'RelayProfiler: Handler did not invoke original function.',
160
- );
161
- }
162
- }
163
- return returnValue;
164
- };
165
- instrumentedCallback.attachHandler = function(handler: Handler): void {
166
- handlers.push(handler);
167
- };
168
- instrumentedCallback.detachHandler = function(handler: Handler): void {
169
- removeFromArray(handlers, handler);
170
- };
171
- instrumentedCallback.displayName = '(instrumented ' + name + ')';
172
- return (instrumentedCallback: any);
173
- },
174
-
175
- /**
176
- * Attaches a handler to all methods instrumented with the supplied name.
177
- *
178
- * function createRenderer() {
179
- * return RelayProfiler.instrument('render', function() {...});
180
- * }
181
- * const renderA = createRenderer();
182
- * const renderB = createRenderer();
183
- *
184
- * // Only profiles `renderA`.
185
- * renderA.attachHandler(...);
186
- *
187
- * // Profiles both `renderA` and `renderB`.
188
- * RelayProfiler.attachAggregateHandler('render', ...);
189
- *
190
- */
191
- attachAggregateHandler(name: string, handler: Handler): void {
192
- if (shouldInstrument(name)) {
193
- if (!aggregateHandlersByName.hasOwnProperty(name)) {
194
- aggregateHandlersByName[name] = [];
195
- }
196
- aggregateHandlersByName[name].push(handler);
197
- }
198
- },
199
-
200
- /**
201
- * Detaches a handler attached via `attachAggregateHandler`.
202
- */
203
- detachAggregateHandler(name: string, handler: Handler): void {
204
- if (shouldInstrument(name)) {
205
- if (aggregateHandlersByName.hasOwnProperty(name)) {
206
- removeFromArray(aggregateHandlersByName[name], handler);
207
- }
208
- }
209
- },
210
-
211
55
  /**
212
56
  * Instruments profiling for arbitrarily asynchronous code by a name.
213
57
  *
@@ -221,28 +65,17 @@ const RelayProfiler = {
221
65
  * Arbitrary state can also be passed into `profile` as a second argument. The
222
66
  * attached profile handlers will receive this as the second argument.
223
67
  */
224
- profile(name: string, state?: any): {stop: (error?: Error) => void, ...} {
225
- const hasCatchAllHandlers = profileHandlersByName['*'].length > 0;
226
- const hasNamedHandlers = profileHandlersByName.hasOwnProperty(name);
227
- if (hasNamedHandlers || hasCatchAllHandlers) {
228
- const profileHandlers =
229
- hasNamedHandlers && hasCatchAllHandlers
230
- ? profileHandlersByName[name].concat(profileHandlersByName['*'])
231
- : hasNamedHandlers
232
- ? profileHandlersByName[name]
233
- : profileHandlersByName['*'];
234
- let stopHandlers;
235
- for (let ii = profileHandlers.length - 1; ii >= 0; ii--) {
236
- const profileHandler = profileHandlers[ii];
237
- const stopHandler = profileHandler(name, state);
238
- stopHandlers = stopHandlers || [];
68
+ profile(name: EventName, state?: any): {stop: (error?: Error) => void, ...} {
69
+ const handlers = profileHandlersByName[name];
70
+ if (handlers && handlers.length > 0) {
71
+ const stopHandlers = [];
72
+ for (let ii = handlers.length - 1; ii >= 0; ii--) {
73
+ const stopHandler = handlers[ii](name, state);
239
74
  stopHandlers.unshift(stopHandler);
240
75
  }
241
76
  return {
242
77
  stop(error?: Error): void {
243
- if (stopHandlers) {
244
- stopHandlers.forEach(stopHandler => stopHandler(error));
245
- }
78
+ stopHandlers.forEach(stopHandler => stopHandler(error));
246
79
  },
247
80
  };
248
81
  }
@@ -250,26 +83,21 @@ const RelayProfiler = {
250
83
  },
251
84
 
252
85
  /**
253
- * Attaches a handler to profiles with the supplied name. You can also
254
- * attach to the special name '*' which is a catch all.
86
+ * Attaches a handler to profiles with the supplied name.
255
87
  */
256
- attachProfileHandler(name: string, handler: ProfileHandler): void {
257
- if (shouldInstrument(name)) {
258
- if (!profileHandlersByName.hasOwnProperty(name)) {
259
- profileHandlersByName[name] = [];
260
- }
261
- profileHandlersByName[name].push(handler);
88
+ attachProfileHandler(name: EventName, handler: ProfileHandler): void {
89
+ if (!profileHandlersByName.hasOwnProperty(name)) {
90
+ profileHandlersByName[name] = [];
262
91
  }
92
+ profileHandlersByName[name].push(handler);
263
93
  },
264
94
 
265
95
  /**
266
96
  * Detaches a handler attached via `attachProfileHandler`.
267
97
  */
268
- detachProfileHandler(name: string, handler: ProfileHandler): void {
269
- if (shouldInstrument(name)) {
270
- if (profileHandlersByName.hasOwnProperty(name)) {
271
- removeFromArray(profileHandlersByName[name], handler);
272
- }
98
+ detachProfileHandler(name: EventName, handler: ProfileHandler): void {
99
+ if (profileHandlersByName.hasOwnProperty(name)) {
100
+ removeFromArray(profileHandlersByName[name], handler);
273
101
  }
274
102
  },
275
103
  };
@@ -21,12 +21,12 @@
21
21
  * use-case is as a return value for subscriptions, where calling `dispose()`
22
22
  * would cancel the subscription.
23
23
  */
24
- export type Disposable = {dispose(): void, ...};
24
+ export type Disposable = interface {dispose(): void};
25
25
 
26
26
  export type DataID = string;
27
27
 
28
28
  // Variables
29
- export type Variables = {+[string]: $FlowFixMe, ...};
29
+ export type Variables = {+[string]: $FlowFixMe};
30
30
 
31
31
  /**
32
32
  * Generated operation flow types are subtypes of this.
@@ -49,6 +49,7 @@ export type VariablesOf<T: OperationType> = $ElementType<T, 'variables'>;
49
49
  * in milliseconds. (This value will be passed to setTimeout.)
50
50
  * - `liveConfigId`: causes a query to live update by calling GraphQLLiveQuery,
51
51
  * it represents a configuration of gateway when doing live query
52
+ * - `onSubscribe`: Not in use.
52
53
  * - `metadata`: user-supplied metadata.
53
54
  * - `transactionId`: a user-supplied value, intended for use as a unique id for
54
55
  * a given instance of executing an operation.
@@ -57,13 +58,11 @@ export type CacheConfig = {|
57
58
  force?: ?boolean,
58
59
  poll?: ?number,
59
60
  liveConfigId?: ?string,
61
+ onSubscribe?: () => void,
60
62
  metadata?: {[key: string]: mixed, ...},
61
63
  transactionId?: ?string,
62
64
  |};
63
65
 
64
- /**
65
- * Experimental
66
- */
67
66
  export type FetchQueryFetchPolicy = 'store-or-network' | 'network-only';
68
67
  export type FetchPolicy =
69
68
  | FetchQueryFetchPolicy
@@ -18,9 +18,10 @@
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: {...}>(object: T): T {
21
+ function deepFreeze<T: interface {}>(object: T): T {
22
22
  Object.freeze(object);
23
23
  Object.getOwnPropertyNames(object).forEach(name => {
24
+ // $FlowFixMe[prop-missing]
24
25
  const property = object[name];
25
26
  if (
26
27
  property &&
@@ -13,7 +13,7 @@
13
13
 
14
14
  const hasOwnProperty = Object.prototype.hasOwnProperty;
15
15
 
16
- function isEmptyObject(obj: {+[key: string]: mixed}): boolean {
16
+ function isEmptyObject(obj: interface {+[key: string]: mixed}): boolean {
17
17
  for (const key in obj) {
18
18
  if (hasOwnProperty.call(obj, key)) {
19
19
  return false;