relay-runtime 11.0.1 → 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.
- package/index.js +1 -1
- package/index.js.flow +4 -2
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +1 -1
- package/lib/handlers/connection/MutationHandlers.js +1 -1
- package/lib/multi-actor-environment/ActorIdentifier.js +23 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +108 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +156 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +17 -0
- 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/commitMutation.js +1 -1
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/network/RelayQueryResponseCache.js +1 -1
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/fetchQuery.js +1 -1
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/store/DataChecker.js +1 -1
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +81 -37
- package/lib/store/RelayConcreteVariables.js +1 -1
- package/lib/store/RelayModernEnvironment.js +99 -144
- package/lib/store/RelayModernFragmentSpecResolver.js +1 -1
- package/lib/store/RelayModernRecord.js +1 -1
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +1 -6
- package/lib/store/RelayOperationTracker.js +1 -1
- package/lib/store/RelayPublishQueue.js +9 -5
- package/lib/store/RelayReader.js +63 -10
- package/lib/store/RelayReferenceMarker.js +1 -1
- package/lib/store/RelayResponseNormalizer.js +47 -22
- package/lib/store/RelayStoreReactFlightUtils.js +1 -1
- package/lib/store/RelayStoreUtils.js +1 -1
- package/lib/store/ResolverFragments.js +57 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createRelayContext.js +1 -1
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +18 -7
- package/lib/util/RelayConcreteNode.js +1 -0
- package/lib/util/RelayFeatureFlags.js +3 -1
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +1 -1
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- package/multi-actor-environment/ActorIdentifier.js.flow +27 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +189 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +233 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +196 -0
- package/multi-actor-environment/index.js.flow +24 -0
- package/network/RelayNetworkTypes.js.flow +5 -4
- package/package.json +3 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +82 -35
- package/store/RelayModernEnvironment.js.flow +88 -131
- package/store/RelayModernStore.js.flow +0 -5
- package/store/RelayPublishQueue.js.flow +7 -4
- package/store/RelayReader.js.flow +57 -5
- package/store/RelayResponseNormalizer.js.flow +67 -26
- package/store/RelayStoreTypes.js.flow +15 -8
- package/store/ResolverFragments.js.flow +125 -0
- package/subscription/requestSubscription.js.flow +15 -7
- package/util/ReaderNode.js.flow +14 -1
- package/util/RelayConcreteNode.js.flow +1 -0
- package/util/RelayFeatureFlags.js.flow +4 -0
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayRuntimeTypes.js.flow +3 -1
|
@@ -12,25 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
type
|
|
16
|
-
type ProfileHandler = (name:
|
|
15
|
+
type EventName = 'fetchRelayQuery';
|
|
16
|
+
type ProfileHandler = (name: EventName, state?: any) => (error?: Error) => void;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const profileHandlersByName: {|
|
|
19
|
+
[name: EventName]: Array<ProfileHandler>,
|
|
20
|
+
|} = {};
|
|
19
21
|
|
|
20
|
-
const
|
|
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:
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
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.
|
|
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:
|
|
257
|
-
if (
|
|
258
|
-
|
|
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:
|
|
269
|
-
if (
|
|
270
|
-
|
|
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
|
};
|
|
@@ -26,7 +26,7 @@ export type Disposable = interface {dispose(): void};
|
|
|
26
26
|
export type DataID = string;
|
|
27
27
|
|
|
28
28
|
// Variables
|
|
29
|
-
export type Variables =
|
|
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,6 +58,7 @@ 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
|
|};
|