···
/* eslint-disable @typescript-eslint/no-use-before-define */
···
const makeResultSource = (operation: Operation) => {
(res: OperationResult) =>
res.operation.kind === operation.kind &&
res.operation.key === operation.key &&
(!res.operation.context._instance ||
res.operation.context._instance === operation.context._instance)
-
// Mask typename properties if the option for it is turned on
-
if (opts.maskTypename) {
-
map(res => ({ ...res, data: maskTypename(res.data, true) }))
-
if (operation.kind !== 'query') {
nextOperation(operation);
-
// A mutation is always limited to just a single result and is never shared
-
if (operation.kind === 'mutation') {
-
return pipe(result$, take(1));
-
if (operation.kind === 'subscription') {
-
takeWhile(result => !!result.hasNext)
-
// End the results stream when an active teardown event is sent
-
filter(op => op.kind === 'teardown' && op.key === operation.key)
-
if (operation.kind !== 'query' || result.stale) {
-
return fromValue(result);
-
// Mark a result as stale when a new operation is sent for it
-
op.key === operation.key &&
-
op.context.requestPolicy !== 'cache-only'
-
map(() => ({ ...result, stale: true }))
-
dispatched.delete(operation.key);
-
replays.set(operation.key, result);
-
// Delete the active operation handle
-
dispatched.delete(operation.key);
-
replays.delete(operation.key);
-
active.delete(operation.key);
-
// Delete all queued up operations of the same key on end
-
for (let i = queue.length - 1; i >= 0; i--)
-
if (queue[i].key === operation.key) queue.splice(i, 1);
-
// Dispatch a teardown signal for the stopped operation
-
nextOperation(makeOperation('teardown', operation, operation.context));
···
-
make<OperationResult>(observer => {
let source = active.get(operation.key);
active.set(operation.key, (source = makeResultSource(operation)));
-
const prevReplay = replays.get(operation.key);
-
const isNetworkOperation =
-
operation.context.requestPolicy === 'cache-and-network' ||
-
operation.context.requestPolicy === 'network-only';
-
if (operation.kind !== 'query') {
-
} else if (isNetworkOperation) {
-
dispatchOperation(operation);
-
if (prevReplay && !prevReplay.hasNext) prevReplay.stale = true;
-
prevReplay === replays.get(operation.key)
-
observer.next(prevReplay);
-
} else if (!isNetworkOperation) {
dispatchOperation(operation);
-
isOperationBatchActive = false;
-
subscribe(observer.next)
···
/* eslint-disable @typescript-eslint/no-use-before-define */
···
const makeResultSource = (operation: Operation) => {
+
// Filter by matching key (or _instance if it’s set)
(res: OperationResult) =>
res.operation.kind === operation.kind &&
res.operation.key === operation.key &&
(!res.operation.context._instance ||
res.operation.context._instance === operation.context._instance)
+
// End the results stream when an active teardown event is sent
+
filter(op => op.kind === 'teardown' && op.key === operation.key)
+
if (operation.kind !== 'query') {
+
// Interrupt subscriptions and mutations when they have no more results
+
takeWhile(result => !!result.hasNext, true)
+
// Add `stale: true` flag when a new operation is sent for queries
+
const value$ = fromValue(result);
+
op.key === operation.key &&
+
op.context.requestPolicy !== 'cache-only'
+
map(() => ({ ...result, stale: true }))
+
if (operation.kind !== 'mutation') {
+
dispatched.delete(operation.key);
+
replays.set(operation.key, result);
+
// Cleanup active states on end of source
+
// Delete the active operation handle
+
dispatched.delete(operation.key);
+
replays.delete(operation.key);
+
active.delete(operation.key);
+
// Interrupt active queue
+
isOperationBatchActive = false;
+
// Delete all queued up operations of the same key on end
+
for (let i = queue.length - 1; i >= 0; i--)
+
if (queue[i].key === operation.key) queue.splice(i, 1);
+
// Dispatch a teardown signal for the stopped operation
+
makeOperation('teardown', operation, operation.context)
+
// Send mutation operation on start
nextOperation(operation);
+
// Mask typename properties if the option for it is turned on
+
if (opts.maskTypename) {
+
map(res => ({ ...res, data: maskTypename(res.data, true) }))
···
+
lazy<OperationResult>(() => {
let source = active.get(operation.key);
active.set(operation.key, (source = makeResultSource(operation)));
+
const isNetworkOperation =
+
operation.context.requestPolicy === 'cache-and-network' ||
+
operation.context.requestPolicy === 'network-only';
+
const replay = replays.get(operation.key);
+
if (operation.kind !== 'query' || !replay || isNetworkOperation) {
dispatchOperation(operation);
+
if (operation.kind === 'query' && replay) {
+
if (replay === replays.get(operation.key)) {
+
if (isNetworkOperation && !replay.hasNext)
+
if (!isNetworkOperation) dispatchOperation(operation);